class ActiveScaffold::Config::Core

to fix the ckeditor bridge problem

Attributes

actions[R]

provides read/write access to the local Actions DataStructure

columns[R]

provides read/write access to the local Columns DataStructure

file_column_fields[RW]
frontend[RW]

lets you override the global ActiveScaffold frontend for a specific controller

highlight_messages[RW]

a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper

label[W]

a generally-applicable name for this ActiveScaffold … will be used for generating page/section headers

sti_children[RW]

STI children models, use an array of model names

theme[RW]

lets you override the global ActiveScaffold theme for a specific controller

timestamped_messages[RW]

prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used

Public Instance Methods

_configure_sti() click to toggle source

To be called after your finished configuration

# File lib/active_scaffold/config/core.rb, line 163
def _configure_sti
  column = self.model.inheritance_column
  if sti_create_links
    self.columns[column].form_ui ||= :hidden
  else
    self.columns[column].form_ui ||= :select
    self.columns[column].options ||= {}
    self.columns[column].options[:options] = self.sti_children.collect do |model_name|
      [model_name.to_s.camelize.constantize.model_name.human, model_name.to_s.camelize]
    end
  end
end
_load_action_columns() click to toggle source

To be called after your finished configuration

# File lib/active_scaffold/config/core.rb, line 151
def _load_action_columns
  #ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration}

  # then, register the column objects
  self.actions.each do |action_name|
    action = self.send(action_name)
    next unless action.respond_to? :columns
    action.columns.set_columns(self.columns)
  end
end
actions=(args) click to toggle source
# File lib/active_scaffold/config/core.rb, line 76
def actions=(args)
  @actions = ActiveScaffold::DataStructures::Actions.new(*args)
end
columns=(val) click to toggle source
# File lib/active_scaffold/config/core.rb, line 82
def columns=(val)
  @columns._inheritable = val.collect {|c| c.to_sym}
  # Add virtual columns
  @columns << val.collect {|c| c.to_sym unless @columns[c.to_sym]}.compact
end
configure_file_column_field(field) click to toggle source
# File lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb, line 29
def configure_file_column_field(field)
  # set list_ui first because it gets its default value from form_ui
  self.columns[field].list_ui ||= self.model.field_has_image_version?(field, "thumb") ? :thumbnail : :download_link_with_filename
  self.columns[field].form_ui ||= :file_column
  
  # these 2 parameters are necessary helper attributes for the file column that must be allowed to be set to the model by active scaffold.
  self.columns[field].params.add "#{field}_temp", "delete_#{field}"
  
  # set null to false so active_scaffold wont set it to null
  # delete_file_column will take care of deleting a file or not.
  self.model.columns_hash[field.to_s].instance_variable_set("@null", false)
  
rescue
  false
end
inherited_view_paths() click to toggle source

warning - this won’t work as a per-request dynamic attribute in rails 2.0. You’ll need to interact with Controller#generic_view_paths

# File lib/active_scaffold/config/core.rb, line 213
def inherited_view_paths
  @inherited_view_paths||=[]
end
initialize_with_calendar_date_select(model_id) click to toggle source
# File lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb, line 4
def initialize_with_calendar_date_select(model_id)
  initialize_without_calendar_date_select(model_id)
  
  calendar_date_select_fields = self.model.columns.collect{|c| c.name.to_sym if [:date, :datetime].include?(c.type) }.compact
  # check to see if file column was used on the model
  return if calendar_date_select_fields.empty?
  
  # automatically set the forum_ui to a file column
  calendar_date_select_fields.each{|field|
    self.columns[field].form_ui = :calendar_date_select
  }
end
initialize_with_file_column(model_id) click to toggle source
# File lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb, line 8
def initialize_with_file_column(model_id)
  initialize_without_file_column(model_id)
  
  return unless ActiveScaffold::Bridges::FileColumn::FileColumnHelpers.klass_has_file_column_fields?(self.model)
  
  self.model.send :extend, ActiveScaffold::Bridges::FileColumn::FileColumnHelpers
  
  # include the "delete" helpers for use with active scaffold, unless they are already included
  self.model.generate_delete_helpers
  
  # switch on multipart
  self.update.multipart = true
  self.create.multipart = true
  
  self.model.file_column_fields.each{ |field|
    configure_file_column_field(field)
  }
end
label(options={}) click to toggle source
# File lib/active_scaffold/config/core.rb, line 105
def label(options={})
  as_(@label, options) || model.model_name.human(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize}))
end
method_missing(name, *args) click to toggle source

configuration routing. we want to route calls named like an activated action to that action’s global or local Config class.


# File lib/active_scaffold/config/core.rb, line 179
def method_missing(name, *args)
  @action_configs ||= {}
  titled_name = name.to_s.camelcase
  underscored_name = name.to_s.underscore.to_sym
  klass = "ActiveScaffold::Config::#{titled_name}".constantize rescue nil
  if klass
    if @actions.include? underscored_name
      return @action_configs[underscored_name] ||= klass.new(self)
    else
      raise "#{titled_name} is not enabled. Please enable it or remove any references in your configuration (e.g. config.#{underscored_name}.columns = [...])."
    end
  end
  super
end
model() click to toggle source
# File lib/active_scaffold/config/core.rb, line 208
def model
  @model ||= @model_id.to_s.camelize.constantize
end
model_id() click to toggle source

some utility methods


# File lib/active_scaffold/config/core.rb, line 204
def model_id
  @model_id
end

Public Class Methods

actions=(val) click to toggle source
# File lib/active_scaffold/config/core.rb, line 11
def self.actions=(val)
  @@actions = ActiveScaffold::DataStructures::Actions.new(*val)
end
asset_path(filename, frontend = self.frontend) click to toggle source

must be a class method so the layout doesn’t depend on a controller that uses active_scaffold note that this is unaffected by per-controller frontend configuration.

# File lib/active_scaffold/config/core.rb, line 219
def self.asset_path(filename, frontend = self.frontend)
  "active_scaffold/#{frontend}/#{filename}"
end
available_frontends() click to toggle source
# File lib/active_scaffold/config/core.rb, line 230
def self.available_frontends
  frontends_dir = File.join(Rails.root, "vendor", "plugins", ActiveScaffold::Config::Core.plugin_directory, "frontends")
  Dir.entries(frontends_dir).reject { |e| e.match(%r^\./) } # Get rid of files that start with .
end
dhtml_history=(val) click to toggle source

lets you disable the DHTML history

# File lib/active_scaffold/config/core.rb, line 29
def self.dhtml_history=(val)
  @@dhtml_history = val
end
dhtml_history?() click to toggle source
# File lib/active_scaffold/config/core.rb, line 32
def self.dhtml_history?
  @@dhtml_history ? true : false
end
ignore_columns() click to toggle source

columns that should be ignored for every model. these should be metadata columns like change dates, versions, etc. values in this array may be symbols or strings.

# File lib/active_scaffold/config/core.rb, line 51
def self.ignore_columns
  @@ignore_columns
end
ignore_columns=(val) click to toggle source
# File lib/active_scaffold/config/core.rb, line 54
def self.ignore_columns=(val)
  @@ignore_columns = ActiveScaffold::DataStructures::Set.new(*val)
end
javascripts(frontend = self.frontend) click to toggle source

must be a class method so the layout doesn’t depend on a controller that uses active_scaffold note that this is unaffected by per-controller frontend configuration.

# File lib/active_scaffold/config/core.rb, line 225
def self.javascripts(frontend = self.frontend)
  javascript_dir = File.join(Rails.public_path, "javascripts", asset_path('', frontend))
  Dir.entries(javascript_dir).reject { |e| !e.match(%r\.js$/) or (!self.dhtml_history? and e.match('dhtml_history')) }
end
method_missing(name, *args) click to toggle source
# File lib/active_scaffold/config/core.rb, line 194
def self.method_missing(name, *args)
  klass = "ActiveScaffold::Config::#{name.to_s.camelcase}".constantize rescue nil
  if @@actions.include? name.to_s.underscore and klass
    return eval("ActiveScaffold::Config::#{name.to_s.camelcase}")
  end
  super
end
new(model_id) click to toggle source

internal usage only below this point


# File lib/active_scaffold/config/core.rb, line 122
def initialize(model_id)
  # model_id is the only absolutely required configuration value. it is also not publicly accessible.
  @model_id = model_id

  # inherit the actions list directly from the global level
  @actions = self.class.actions.clone

  # create a new default columns datastructure, since it doesn't make sense before now
  attribute_names = self.model.columns.collect{ |c| c.name.to_sym }.sort_by { |c| c.to_s }
  association_column_names = self.model.reflect_on_all_associations.collect{ |a| a.name.to_sym }.sort_by { |c| c.to_s }
  @columns = ActiveScaffold::DataStructures::Columns.new(self.model, attribute_names + association_column_names)

  # and then, let's remove some columns from the inheritable set.
  @columns.exclude(*self.class.ignore_columns)
  @columns.exclude(*@columns.find_all { |c| c.column and (c.column.primary or c.column.name =~ %r(_id|_count)$/) }.collect {|c| c.name})
  @columns.exclude(*self.model.reflect_on_all_associations.collect{|a| :"#{a.name}_type" if a.options[:polymorphic]}.compact)

  # inherit the global frontend
  @frontend = self.class.frontend
  @theme = self.class.theme
  @sti_create_links = self.class.sti_create_links

  # inherit from the global set of action links
  @action_links = self.class.action_links.clone
  @timestamped_messages = self.class.timestamped_messages
  @highlight_messages = self.class.highlight_messages
end
security() click to toggle source

access to the permissions configuration. configuration options include:

* current_user_method - what method on the controller returns the current user. default: :current_user
* default_permission - what the default permission is. default: true
# File lib/active_scaffold/config/core.rb, line 45
def self.security
  ActiveRecordPermissions
end