Class: ActiveScaffold::Config::Core
- Defined in:
- lib/active_scaffold/config/core.rb,
lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb,
lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb
Overview
to fix the ckeditor bridge problem inherit from full class name
Constant Summary collapse
- @@plugin_directory =
- @@frontend =
:default
- @@theme =
:default
- @@cache_action_link_urls =
true
- @@cache_association_options =
true
- @@conditional_get_support =
false
- @@store_user_settings =
true
- @@dhtml_history =
true
- @@action_links =
ActiveScaffold::DataStructures::ActionLinks.new
- @@ignore_columns =
ActiveScaffold::DataStructures::Set.new
- @@sti_create_links =
true
- @@timestamped_messages =
false
- @@highlight_messages =
nil
Instance Attribute Summary collapse
-
#action_links ⇒ Object
readonly
action links are used by actions to tie together.
-
#actions ⇒ Object
provides read/write access to the local Actions DataStructure.
-
#cache_action_link_urls ⇒ Object
enable caching of action link urls.
-
#cache_association_options ⇒ Object
enable caching of association options.
-
#columns ⇒ Object
provides read/write access to the local Columns DataStructure.
-
#conditional_get_support ⇒ Object
enable setting ETag and LastModified on responses and using fresh_when/stale? to respond with 304 and avoid rendering views.
-
#file_column_fields ⇒ Object
Returns the value of attribute file_column_fields.
-
#frontend ⇒ Object
lets you override the global ActiveScaffold frontend for a specific controller.
-
#highlight_messages ⇒ Object
a hash of string (or array of strings) and highlighter string to highlight words in messages.
- #label(options = {}) ⇒ Object
-
#model_id ⇒ Object
readonly
some utility methods ——————–.
-
#sti_children ⇒ Object
STI children models, use an array of model names.
-
#sti_create_links ⇒ Object
lets you specify whether add a create link for each sti child for a specific controller.
-
#store_user_settings ⇒ Object
enable saving user settings in session (per_page, limit, page, sort, search params).
-
#theme ⇒ Object
lets you override the global ActiveScaffold theme for a specific controller.
-
#timestamped_messages ⇒ Object
prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used.
Attributes inherited from Base
#action_group, #core, #formats, #user
Class Method Summary collapse
- .actions=(val) ⇒ Object
-
.asset_path(filename, frontend = self.frontend) ⇒ Object
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.
- .available_frontends ⇒ Object
-
.dhtml_history=(val) ⇒ Object
lets you disable the DHTML history.
- .dhtml_history? ⇒ Boolean
-
.ignore_columns ⇒ Object
columns that should be ignored for every model.
- .ignore_columns=(val) ⇒ Object
-
.javascripts(frontend = self.frontend) ⇒ Object
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.
- .method_missing(name, *args) ⇒ Object
-
.security ⇒ Object
access to the permissions configuration.
Instance Method Summary collapse
-
#_configure_sti ⇒ Object
To be called after your finished configuration.
-
#_load_action_columns ⇒ Object
To be called after your finished configuration.
- #add_sti_create_links? ⇒ Boolean
- #configure_file_column_field(field) ⇒ Object
-
#inherited_view_paths ⇒ Object
warning - this won’t work as a per-request dynamic attribute in rails 2.0.
-
#initialize(model_id) ⇒ Core
constructor
internal usage only below this point ————————————.
- #initialize_with_calendar_date_select(model_id) ⇒ Object
- #initialize_with_file_column(model_id) ⇒ Object
-
#method_missing(name, *args) ⇒ Object
configuration routing.
- #model ⇒ Object
Methods inherited from Base
Methods included from ActiveScaffold::Configurable
Constructor Details
#initialize(model_id) ⇒ Core
internal usage only below this point
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/active_scaffold/config/core.rb', line 148 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 = model.columns.collect { |c| c.name.to_sym }.sort_by(&:to_s) association_column_names = model.reflect_on_all_associations.collect { |a| a.name.to_sym }.sort_by(&:to_s) @columns = ActiveScaffold::DataStructures::Columns.new(model, attribute_names + association_column_names) # and then, let's remove some columns from the inheritable set. content_columns = Set.new(model.content_columns.map(&:name)) @columns.exclude(*self.class.ignore_columns) @columns.exclude(*@columns.find_all { |c| c.column && content_columns.exclude?(c.column.name) }.collect(&:name)) @columns.exclude(*model.reflect_on_all_associations.collect { |a| a.foreign_type.to_sym if a.[:polymorphic] }.compact) # inherit the global frontend @frontend = self.class.frontend @theme = self.class.theme @cache_action_link_urls = self.class.cache_action_link_urls @cache_association_options = self.class. @conditional_get_support = self.class.conditional_get_support @store_user_settings = self.class.store_user_settings @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. @highlight_messages = self.class. end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
configuration routing. we want to route calls named like an activated action to that action’s global or local Config class.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/active_scaffold/config/core.rb', line 207 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 |
Instance Attribute Details
#action_links ⇒ Object (readonly)
action links are used by actions to tie together. they appear as links for each record, or general links for the ActiveScaffold.
127 128 129 |
# File 'lib/active_scaffold/config/core.rb', line 127 def action_links @action_links end |
#actions ⇒ Object
provides read/write access to the local Actions DataStructure
89 90 91 |
# File 'lib/active_scaffold/config/core.rb', line 89 def actions @actions end |
#cache_action_link_urls ⇒ Object
enable caching of action link urls
109 110 111 |
# File 'lib/active_scaffold/config/core.rb', line 109 def cache_action_link_urls @cache_action_link_urls end |
#cache_association_options ⇒ Object
enable caching of association options
112 113 114 |
# File 'lib/active_scaffold/config/core.rb', line 112 def @cache_association_options end |
#columns ⇒ Object
provides read/write access to the local Columns DataStructure
95 96 97 |
# File 'lib/active_scaffold/config/core.rb', line 95 def columns @columns end |
#conditional_get_support ⇒ Object
enable setting ETag and LastModified on responses and using fresh_when/stale? to respond with 304 and avoid rendering views
115 116 117 |
# File 'lib/active_scaffold/config/core.rb', line 115 def conditional_get_support @conditional_get_support end |
#file_column_fields ⇒ Object
Returns the value of attribute file_column_fields.
7 8 9 |
# File 'lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb', line 7 def file_column_fields @file_column_fields end |
#frontend ⇒ Object
lets you override the global ActiveScaffold frontend for a specific controller
103 104 105 |
# File 'lib/active_scaffold/config/core.rb', line 103 def frontend @frontend end |
#highlight_messages ⇒ Object
a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper
142 143 144 |
# File 'lib/active_scaffold/config/core.rb', line 142 def @highlight_messages end |
#label(options = {}) ⇒ Object
131 132 133 |
# File 'lib/active_scaffold/config/core.rb', line 131 def label( = {}) as_(@label, ) || model.model_name.human(.merge([:count].to_i == 1 ? {} : {:default => model.name.pluralize})) end |
#model_id ⇒ Object (readonly)
some utility methods
230 231 232 |
# File 'lib/active_scaffold/config/core.rb', line 230 def model_id @model_id end |
#sti_children ⇒ Object
STI children models, use an array of model names
136 137 138 |
# File 'lib/active_scaffold/config/core.rb', line 136 def sti_children @sti_children end |
#sti_create_links ⇒ Object
lets you specify whether add a create link for each sti child for a specific controller
121 122 123 |
# File 'lib/active_scaffold/config/core.rb', line 121 def sti_create_links @sti_create_links end |
#store_user_settings ⇒ Object
enable saving user settings in session (per_page, limit, page, sort, search params)
118 119 120 |
# File 'lib/active_scaffold/config/core.rb', line 118 def store_user_settings @store_user_settings end |
#theme ⇒ Object
lets you override the global ActiveScaffold theme for a specific controller
106 107 108 |
# File 'lib/active_scaffold/config/core.rb', line 106 def theme @theme end |
#timestamped_messages ⇒ Object
prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used
139 140 141 |
# File 'lib/active_scaffold/config/core.rb', line 139 def @timestamped_messages end |
Class Method Details
.actions=(val) ⇒ Object
9 10 11 |
# File 'lib/active_scaffold/config/core.rb', line 9 def self.actions=(val) @@actions = ActiveScaffold::DataStructures::Actions.new(*val) end |
.asset_path(filename, frontend = self.frontend) ⇒ Object
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.
243 244 245 |
# File 'lib/active_scaffold/config/core.rb', line 243 def self.asset_path(filename, frontend = self.frontend) "active_scaffold/#{frontend}/#{filename}" end |
.available_frontends ⇒ Object
254 255 256 257 |
# File 'lib/active_scaffold/config/core.rb', line 254 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(/^\./) } # Get rid of files that start with . end |
.dhtml_history=(val) ⇒ Object
lets you disable the DHTML history
43 44 45 |
# File 'lib/active_scaffold/config/core.rb', line 43 def self.dhtml_history=(val) @@dhtml_history = val end |
.dhtml_history? ⇒ Boolean
46 47 48 |
# File 'lib/active_scaffold/config/core.rb', line 46 def self.dhtml_history? @@dhtml_history ? true : false end |
.ignore_columns ⇒ Object
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.
65 66 67 |
# File 'lib/active_scaffold/config/core.rb', line 65 def self.ignore_columns @@ignore_columns end |
.ignore_columns=(val) ⇒ Object
68 69 70 |
# File 'lib/active_scaffold/config/core.rb', line 68 def self.ignore_columns=(val) @@ignore_columns = ActiveScaffold::DataStructures::Set.new(*val) end |
.javascripts(frontend = self.frontend) ⇒ Object
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.
249 250 251 252 |
# File 'lib/active_scaffold/config/core.rb', line 249 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(/\.js$/) || (!self.dhtml_history? && e.match('dhtml_history')) } end |
.method_missing(name, *args) ⇒ Object
222 223 224 225 226 |
# File 'lib/active_scaffold/config/core.rb', line 222 def self.method_missing(name, *args) klass = "ActiveScaffold::Config::#{name.to_s.camelcase}".constantize rescue nil return klass if @@actions.include?(name.to_s.underscore) && klass super end |
.security ⇒ Object
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
59 60 61 |
# File 'lib/active_scaffold/config/core.rb', line 59 def self.security ActiveScaffold::ActiveRecordPermissions end |
Instance Method Details
#_configure_sti ⇒ Object
To be called after your finished configuration
191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/active_scaffold/config/core.rb', line 191 def _configure_sti column = model.inheritance_column if sti_create_links columns[column].form_ui ||= :hidden else columns[column].form_ui ||= :select columns[column]. ||= {} columns[column].[:options] = 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 ⇒ Object
To be called after your finished configuration
182 183 184 185 186 187 188 |
# File 'lib/active_scaffold/config/core.rb', line 182 def _load_action_columns # then, register the column objects actions.each do |action_name| action = send(action_name) action.columns.set_columns(columns) if action.respond_to?(:columns) end end |
#add_sti_create_links? ⇒ Boolean
122 123 124 |
# File 'lib/active_scaffold/config/core.rb', line 122 def add_sti_create_links? sti_create_links && !sti_children.nil? end |
#configure_file_column_field(field) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb', line 27 def configure_file_column_field(field) # set list_ui first because it gets its default value from form_ui columns[field].list_ui ||= model.field_has_image_version?(field, 'thumb') ? :thumbnail : :download_link_with_filename 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. 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. model.columns_hash[field.to_s].instance_variable_set('@null', false) rescue false end |
#inherited_view_paths ⇒ Object
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
237 238 239 |
# File 'lib/active_scaffold/config/core.rb', line 237 def inherited_view_paths @inherited_view_paths ||= [] end |
#initialize_with_calendar_date_select(model_id) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb', line 3 def initialize_with_calendar_date_select(model_id) initialize_without_calendar_date_select(model_id) calendar_date_select_fields = 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| columns[field].form_ui = :calendar_date_select } end |
#initialize_with_file_column(model_id) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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?(model) model.send :extend, ActiveScaffold::Bridges::FileColumn::FileColumnHelpers # include the "delete" helpers for use with active scaffold, unless they are already included model.generate_delete_helpers # switch on multipart update.multipart = true create.multipart = true model.file_column_fields.each { |field| configure_file_column_field(field) } end |
#model ⇒ Object
232 233 234 |
# File 'lib/active_scaffold/config/core.rb', line 232 def model @model ||= @model_id.to_s.camelize.constantize end |