Class: ActiveScaffold::Config::Core
- Defined in:
- lib/active_scaffold/config/core.rb
Overview
to fix the ckeditor bridge problem
Constant Summary collapse
- @@plugin_directory =
- @@frontend =
:default
- @@theme =
:default
- @@dhtml_history =
true
- @@action_links =
ActiveScaffold::DataStructures::ActionLinks.new
- @@ignore_columns =
ActiveScaffold::DataStructures::Set.new
- @@sti_create_links =
true
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.
-
#columns ⇒ Object
provides read/write access to the local Columns DataStructure.
-
#frontend ⇒ Object
lets you override the global ActiveScaffold frontend for a specific controller.
- #label(options = {}) ⇒ Object
-
#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.
-
#theme ⇒ Object
lets you override the global ActiveScaffold theme for a specific controller.
Attributes inherited from Base
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
-
#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 ————————————.
-
#method_missing(name, *args) ⇒ Object
configuration routing.
- #model ⇒ Object
-
#model_id ⇒ Object
some utility methods ——————–.
Methods inherited from Base
#crud_type, #formats, #formats=, inherited
Methods included from ActiveScaffold::Configurable
Constructor Details
#initialize(model_id) ⇒ Core
internal usage only below this point
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/active_scaffold/config/core.rb', line 107 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.sort_by {|c| c.to_s} association_column_names = self.model.associations.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_key] or c.name.to_s =~ /(_id|_count)$/) }.collect {|c| c.name}) # 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 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.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/active_scaffold/config/core.rb', line 161 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.
92 93 94 |
# File 'lib/active_scaffold/config/core.rb', line 92 def action_links @action_links end |
#actions ⇒ Object
provides read/write access to the local Actions DataStructure
66 67 68 |
# File 'lib/active_scaffold/config/core.rb', line 66 def actions @actions end |
#columns ⇒ Object
provides read/write access to the local Columns DataStructure
72 73 74 |
# File 'lib/active_scaffold/config/core.rb', line 72 def columns @columns end |
#frontend ⇒ Object
lets you override the global ActiveScaffold frontend for a specific controller
80 81 82 |
# File 'lib/active_scaffold/config/core.rb', line 80 def frontend @frontend end |
#label(options = {}) ⇒ Object
96 97 98 |
# File 'lib/active_scaffold/config/core.rb', line 96 def label(={}) as_(@label, ) || model.model_name.human(.merge([:count].to_i == 1 ? {} : {:default => model.name.pluralize})) end |
#sti_children ⇒ Object
STI children models, use an array of model names
101 102 103 |
# File 'lib/active_scaffold/config/core.rb', line 101 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
86 87 88 |
# File 'lib/active_scaffold/config/core.rb', line 86 def sti_create_links @sti_create_links end |
#theme ⇒ Object
lets you override the global ActiveScaffold theme for a specific controller
83 84 85 |
# File 'lib/active_scaffold/config/core.rb', line 83 def theme @theme end |
Class Method Details
.actions=(val) ⇒ Object
11 12 13 |
# 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) ⇒ 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.
201 202 203 |
# File 'lib/active_scaffold/config/core.rb', line 201 def self.asset_path(filename, frontend = self.frontend) "active_scaffold/#{frontend}/#{filename}" end |
.available_frontends ⇒ Object
212 213 214 215 |
# File 'lib/active_scaffold/config/core.rb', line 212 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
29 30 31 |
# File 'lib/active_scaffold/config/core.rb', line 29 def self.dhtml_history=(val) @@dhtml_history = val end |
.dhtml_history? ⇒ Boolean
32 33 34 |
# File 'lib/active_scaffold/config/core.rb', line 32 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.
50 51 52 |
# File 'lib/active_scaffold/config/core.rb', line 50 def self.ignore_columns @@ignore_columns end |
.ignore_columns=(val) ⇒ Object
53 54 55 |
# File 'lib/active_scaffold/config/core.rb', line 53 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.
207 208 209 210 |
# File 'lib/active_scaffold/config/core.rb', line 207 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$/) or (!self.dhtml_history? and e.match('dhtml_history')) } end |
.method_missing(name, *args) ⇒ Object
176 177 178 179 180 181 182 |
# File 'lib/active_scaffold/config/core.rb', line 176 def self.method_missing(name, *args) klass = "ActiveScaffold::Config::#{name.to_s.titleize}".constantize rescue nil if @@actions.include? name.to_s.underscore and klass return eval("ActiveScaffold::Config::#{name.to_s.titleize}") end super end |
.security ⇒ Object
access to the permissions configuration. configuration options include:
* default_permission - what the default permission is. default: true
44 45 46 |
# File 'lib/active_scaffold/config/core.rb', line 44 def self.security ModelPermissions end |
Instance Method Details
#_configure_sti ⇒ Object
To be called after your finished configuration
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/active_scaffold/config/core.rb', line 145 def _configure_sti column = self.model.respond_to?(:sti_key) ? self.model.sti_key : :type if sti_create_links self.columns[column].form_ui ||= :hidden else self.columns[column].form_ui ||= :select self.columns[column]. ||= {} self.columns[column].[: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 ⇒ Object
To be called after your finished configuration
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/active_scaffold/config/core.rb', line 133 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 |
#add_sti_create_links? ⇒ Boolean
87 88 89 |
# File 'lib/active_scaffold/config/core.rb', line 87 def add_sti_create_links? self.sti_create_links and not self.sti_children.nil? 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
195 196 197 |
# File 'lib/active_scaffold/config/core.rb', line 195 def inherited_view_paths @inherited_view_paths||=[] end |
#model ⇒ Object
190 191 192 |
# File 'lib/active_scaffold/config/core.rb', line 190 def model @model ||= @model_id.to_s.camelize.constantize end |
#model_id ⇒ Object
some utility methods
186 187 188 |
# File 'lib/active_scaffold/config/core.rb', line 186 def model_id @model_id end |