Module: Card::Set
- Includes:
- Event, Trait
- Included in:
- Abstract::Attachment, Abstract::Permission, All::Account, All::Actions, All::ActiveCard, All::AllCss, All::AllCsv, All::AllJs, All::Base, All::Bootstrap::Form, All::Bootstrap::Helper, All::Bootstrap::Wrapper, All::Collection, All::Comment, All::Content, All::ContentHistory, All::EmailHtml, All::EmailText, All::Erb, All::Error, All::EventViz, All::Fetch, All::File, All::Follow, All::Haml, All::History, All::Initialize, All::Json, All::Links, All::Name, All::Notify, All::Observer, All::Pattern, All::Permissions, All::Phases, All::References, All::RichBootstrap, All::RichHtml::Content, All::RichHtml::Editing, All::RichHtml::Form, All::RichHtml::Header, All::RichHtml::Menu, All::RichHtml::Modal, All::RichHtml::Toolbar, All::RichHtml::Wrapper, All::Rss, All::Rules, All::States, All::Templating, All::Text, All::TrackedAttributes, All::Trash, All::Type, All::Utils, All::ViewCache, Right::Account, Right::AddHelp, Right::Bcc, Right::Cc, Right::Comment, Right::Create, Right::Default, Right::Delete, Right::Discussion, Right::Email, Right::Follow, Right::FollowFields, Right::Followers, Right::Following, Right::From, Right::Help, Right::HtmlMessage, Right::MachineInput, Right::MachineOutput, Right::Password, Right::Read, Right::Salt, Right::Script, Right::Stats, Right::Status, Right::Structure, Right::Style, Right::To, Right::Token, Right::Update, Right::WhenCreated, Right::WhenLastEdited, Rstar::Rules, Self::AccountLinks, Self::Accountable, Self::AddHelp, Self::Alerts, Self::All, Self::Always, Self::Autoname, Self::BootstrapCards, Self::BootstrapJs, Self::BootswatchShared, Self::Captcha, Self::Create, Self::Created, Self::Default, Self::Delete, Self::Edited, Self::Follow, Self::FollowDefaults, Self::Foot, Self::Head, Self::Help, Self::Input, Self::Layout, Self::Navbox, Self::Never, Self::Now, Self::OnCreate, Self::OnDelete, Self::OnUpdate, Self::Options, Self::OptionsLabel, Self::PerformanceLog, Self::Read, Self::Recent, Self::RecentSettings, Self::Script, Self::ScriptAce, Self::ScriptCardMenu, Self::ScriptHtml5shivPrintshiv, Self::ScriptJquery, Self::ScriptJqueryHelper, Self::ScriptSlot, Self::ScriptTinymce, Self::Search, Self::Signin, Self::SmartmenuCss, Self::SmartmenuJs, Self::Stats, Self::Structure, Self::Style, Self::StyleBootstrapCompatible, Self::StyleCards, Self::StyleJqueryUiSmoothness, Self::TableOfContents, Self::Thanks, Self::Update, Self::Version, Type::Basic, Type::Cardtype, Type::CoffeeScript, Type::Css, Type::Date, Type::EmailTemplate, Type::File, Type::Html, Type::Image, Type::JavaScript, Type::LayoutType, Type::Number, Type::Phrase, Type::PlainText, Type::Pointer, Type::Scss, Type::SearchType, Type::Session, Type::Set, Type::Setting, Type::Signup, Type::Skin, Type::Toggle, Type::Uri, Type::User, TypePlusRight::User::Follow
- Defined in:
- lib/card/set.rb,
lib/card/set/event.rb,
lib/card/set/trait.rb,
tmpsets/set/mod001-01_core/all/erb.rb,
tmpsets/set/mod001-01_core/all/haml.rb,
tmpsets/set/mod001-01_core/all/name.rb,
tmpsets/set/mod001-01_core/all/type.rb,
tmpsets/set/mod001-01_core/all/fetch.rb,
tmpsets/set/mod001-01_core/all/rules.rb,
tmpsets/set/mod001-01_core/all/trash.rb,
tmpsets/set/mod001-01_core/all/utils.rb,
tmpsets/set/mod006-05_email/right/cc.rb,
tmpsets/set/mod006-05_email/right/to.rb,
tmpsets/set/mod001-01_core/all/phases.rb,
tmpsets/set/mod001-01_core/all/states.rb,
tmpsets/set/mod006-05_email/right/bcc.rb,
tmpsets/set/mod001-01_core/all/content.rb,
tmpsets/set/mod001-01_core/all/pattern.rb,
tmpsets/set/mod006-05_email/all/follow.rb,
tmpsets/set/mod006-05_email/all/notify.rb,
tmpsets/set/mod006-05_email/right/from.rb,
tmpsets/set/mod006-05_email/self/never.rb,
tmpsets/set/mod004-03_machines/type/css.rb,
tmpsets/set/mod006-05_email/self/always.rb,
tmpsets/set/mod006-05_email/self/edited.rb,
tmpsets/set/mod006-05_email/self/follow.rb,
tmpsets/set/mod007-05_standard/self/all.rb,
tmpsets/set/mod007-05_standard/self/now.rb,
tmpsets/set/mod007-05_standard/type/set.rb,
tmpsets/set/mod007-05_standard/type/uri.rb,
tmpsets/set/mod004-03_machines/type/scss.rb,
tmpsets/set/mod004-03_machines/type/skin.rb,
tmpsets/set/mod005-04_settings/self/help.rb,
tmpsets/set/mod005-04_settings/self/read.rb,
tmpsets/set/mod006-05_email/all/observer.rb,
tmpsets/set/mod006-05_email/right/follow.rb,
tmpsets/set/mod006-05_email/self/created.rb,
tmpsets/set/mod007-05_standard/all/error.rb,
tmpsets/set/mod007-05_standard/all/links.rb,
tmpsets/set/mod007-05_standard/self/foot.rb,
tmpsets/set/mod007-05_standard/self/head.rb,
tmpsets/set/mod007-05_standard/type/date.rb,
tmpsets/set/mod007-05_standard/type/file.rb,
tmpsets/set/mod007-05_standard/type/user.rb,
tmpsets/set/mod001-01_core/all/collection.rb,
tmpsets/set/mod001-01_core/all/initialize.rb,
tmpsets/set/mod001-01_core/all/references.rb,
tmpsets/set/mod001-01_core/all/templating.rb,
tmpsets/set/mod001-01_core/all/view_cache.rb,
tmpsets/set/mod002-01_history/all/actions.rb,
tmpsets/set/mod002-01_history/all/history.rb,
tmpsets/set/mod003-02_basic_types/all/rss.rb,
tmpsets/set/mod005-04_settings/right/help.rb,
tmpsets/set/mod005-04_settings/right/read.rb,
tmpsets/set/mod005-04_settings/self/input.rb,
tmpsets/set/mod005-04_settings/self/style.rb,
tmpsets/set/mod007-05_standard/right/salt.rb,
tmpsets/set/mod007-05_standard/self/stats.rb,
tmpsets/set/mod007-05_standard/type/basic.rb,
tmpsets/set/mod007-05_standard/type/image.rb,
tmpsets/set/mod001-01_core/all/active_card.rb,
tmpsets/set/mod001-01_core/all/permissions.rb,
tmpsets/set/mod003-02_basic_types/all/base.rb,
tmpsets/set/mod003-02_basic_types/all/file.rb,
tmpsets/set/mod003-02_basic_types/all/json.rb,
tmpsets/set/mod003-02_basic_types/all/text.rb,
tmpsets/set/mod005-04_settings/right/style.rb,
tmpsets/set/mod005-04_settings/self/create.rb,
tmpsets/set/mod005-04_settings/self/delete.rb,
tmpsets/set/mod005-04_settings/self/layout.rb,
tmpsets/set/mod005-04_settings/self/script.rb,
tmpsets/set/mod005-04_settings/self/thanks.rb,
tmpsets/set/mod005-04_settings/self/update.rb,
tmpsets/set/mod006-05_email/all/email_html.rb,
tmpsets/set/mod006-05_email/all/email_text.rb,
tmpsets/set/mod007-05_standard/all/account.rb,
tmpsets/set/mod007-05_standard/all/comment.rb,
tmpsets/set/mod007-05_standard/right/email.rb,
tmpsets/set/mod007-05_standard/right/stats.rb,
tmpsets/set/mod007-05_standard/right/token.rb,
tmpsets/set/mod007-05_standard/rstar/rules.rb,
tmpsets/set/mod007-05_standard/self/alerts.rb,
tmpsets/set/mod007-05_standard/self/navbox.rb,
tmpsets/set/mod007-05_standard/self/recent.rb,
tmpsets/set/mod007-05_standard/self/search.rb,
tmpsets/set/mod007-05_standard/self/signin.rb,
tmpsets/set/mod007-05_standard/type/number.rb,
tmpsets/set/mod007-05_standard/type/phrase.rb,
tmpsets/set/mod007-05_standard/type/signup.rb,
tmpsets/set/mod007-05_standard/type/toggle.rb,
tmpsets/set/mod003-02_basic_types/type/html.rb,
tmpsets/set/mod005-04_settings/right/create.rb,
tmpsets/set/mod005-04_settings/right/delete.rb,
tmpsets/set/mod005-04_settings/right/script.rb,
tmpsets/set/mod005-04_settings/right/update.rb,
tmpsets/set/mod005-04_settings/self/captcha.rb,
tmpsets/set/mod005-04_settings/self/default.rb,
tmpsets/set/mod005-04_settings/self/options.rb,
tmpsets/set/mod005-04_settings/type/setting.rb,
tmpsets/set/mod006-05_email/right/followers.rb,
tmpsets/set/mod006-05_email/right/following.rb,
tmpsets/set/mod007-05_standard/right/status.rb,
tmpsets/set/mod007-05_standard/self/version.rb,
tmpsets/set/mod007-05_standard/type/session.rb,
tmpsets/set/mod003-02_basic_types/all/all_js.rb,
tmpsets/set/mod005-04_settings/right/comment.rb,
tmpsets/set/mod005-04_settings/right/default.rb,
tmpsets/set/mod005-04_settings/self/add_help.rb,
tmpsets/set/mod005-04_settings/self/autoname.rb,
tmpsets/set/mod007-05_standard/all/event_viz.rb,
tmpsets/set/mod007-05_standard/right/account.rb,
tmpsets/set/mod007-05_standard/type/cardtype.rb,
tmpsets/set/mod003-02_basic_types/all/all_css.rb,
tmpsets/set/mod003-02_basic_types/all/all_csv.rb,
tmpsets/set/mod005-04_settings/right/add_help.rb,
tmpsets/set/mod005-04_settings/self/on_create.rb,
tmpsets/set/mod005-04_settings/self/on_delete.rb,
tmpsets/set/mod005-04_settings/self/on_update.rb,
tmpsets/set/mod005-04_settings/self/structure.rb,
tmpsets/set/mod007-05_standard/right/password.rb,
tmpsets/set/mod003-02_basic_types/type/pointer.rb,
tmpsets/set/mod004-03_machines/self/script_ace.rb,
tmpsets/set/mod005-04_settings/right/structure.rb,
tmpsets/set/mod006-05_email/right/html_message.rb,
tmpsets/set/mod004-03_machines/self/script_slot.rb,
tmpsets/set/mod004-03_machines/self/style_cards.rb,
tmpsets/set/mod004-03_machines/type/java_script.rb,
tmpsets/set/mod005-04_settings/self/accountable.rb,
tmpsets/set/mod006-05_email/right/follow_fields.rb,
tmpsets/set/mod006-05_email/type/email_template.rb,
tmpsets/set/mod007-05_standard/right/discussion.rb,
tmpsets/set/mod007-05_standard/type/layout_type.rb,
tmpsets/set/mod007-05_standard/type/search_type.rb,
tmpsets/set/mod006-05_email/self/follow_defaults.rb,
tmpsets/set/mod001-01_core/all/tracked_attributes.rb,
tmpsets/set/mod002-01_history/all/content_history.rb,
tmpsets/set/mod003-02_basic_types/type/plain_text.rb,
tmpsets/set/mod004-03_machines/self/script_jquery.rb,
tmpsets/set/mod004-03_machines/type/coffee_script.rb,
tmpsets/set/mod005-04_settings/self/options_label.rb,
tmpsets/set/mod007-05_standard/all/rich_html/form.rb,
tmpsets/set/mod007-05_standard/all/rich_html/menu.rb,
tmpsets/set/mod007-05_standard/right/when_created.rb,
tmpsets/set/mod007-05_standard/self/account_links.rb,
tmpsets/set/mod008-06_bootstrap/self/bootstrap_js.rb,
tmpsets/set/mod008-06_bootstrap/self/smartmenu_js.rb,
tmpsets/set/mod004-03_machines/right/machine_input.rb,
tmpsets/set/mod004-03_machines/self/script_tinymce.rb,
tmpsets/set/mod005-04_settings/abstract/permission.rb,
tmpsets/set/mod007-05_standard/abstract/attachment.rb,
tmpsets/set/mod007-05_standard/all/rich_html/modal.rb,
tmpsets/set/mod008-06_bootstrap/all/bootstrap/form.rb,
tmpsets/set/mod008-06_bootstrap/all/rich_bootstrap.rb,
tmpsets/set/mod008-06_bootstrap/self/smartmenu_css.rb,
tmpsets/set/mod004-03_machines/right/machine_output.rb,
tmpsets/set/mod005-04_settings/self/recent_settings.rb,
tmpsets/set/mod007-05_standard/all/rich_html/header.rb,
tmpsets/set/mod007-05_standard/self/performance_log.rb,
tmpsets/set/mod004-03_machines/self/script_card_menu.rb,
tmpsets/set/mod007-05_standard/all/rich_html/content.rb,
tmpsets/set/mod007-05_standard/all/rich_html/editing.rb,
tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb,
tmpsets/set/mod007-05_standard/all/rich_html/wrapper.rb,
tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb,
tmpsets/set/mod008-06_bootstrap/self/bootstrap_cards.rb,
tmpsets/set/mod005-04_settings/self/table_of_contents.rb,
tmpsets/set/mod007-05_standard/right/when_last_edited.rb,
tmpsets/set/mod008-06_bootstrap/all/bootstrap/wrapper.rb,
tmpsets/set/mod008-06_bootstrap/self/bootswatch_shared.rb,
tmpsets/set/mod006-05_email/type_plus_right/user/follow.rb,
tmpsets/set/mod004-03_machines/self/script_jquery_helper.rb,
tmpsets/set/mod004-03_machines/self/script_html5shiv_printshiv.rb,
tmpsets/set/mod004-03_machines/self/style_bootstrap_compatible.rb,
tmpsets/set/mod004-03_machines/self/style_jquery_ui_smoothness.rb
Defined Under Namespace
Modules: Abstract, All, Event, Format, Right, Rstar, Self, Trait, Type, TypePlusRight
Constant Summary
collapse
- @@modules =
{ base: [], base_format: {}, nonbase: {}, nonbase_format: {},
abstract: {}, abstract_format: {} }
Class Method Summary
collapse
Instance Method Summary
collapse
-
#abstract_set? ⇒ Boolean
-
#all_set? ⇒ Boolean
-
#define_on_format(format_name = :base, &block) ⇒ Object
-
#each_format(set) ⇒ Object
-
#ensure_set(&block) ⇒ Object
-
#format(*format_names, &block) ⇒ Object
-
#include_set(set, opts = {}) ⇒ Object
include a set module and all its format modules include_set Type::Basic, except: :css.
-
#include_set_formats(set, opts = {}) ⇒ Object
include a format modules of a set include_set Type::Basic, except: :css.
-
#register_set_format(format_class, mod) ⇒ Object
-
#shortname ⇒ Object
-
#stage_method(method, opts = {}, &block) ⇒ Object
-
#view(*args, &block) ⇒ Object
Methods included from Trait
#card_accessor, #card_reader, #card_writer
Methods included from Event
#define_event, #event
Class Method Details
.clean_empty_module_from_hash(hash) ⇒ Object
313
314
315
316
317
318
|
# File 'lib/card/set.rb', line 313
def clean_empty_module_from_hash hash
hash.each do |mod_name, modlist|
modlist.delete_if { |x| x.instance_methods.empty? }
hash.delete mod_name if modlist.empty?
end
end
|
.clean_empty_modules ⇒ Object
306
307
308
309
310
311
|
# File 'lib/card/set.rb', line 306
def clean_empty_modules
clean_empty_module_from_hash modules[:nonbase]
modules[:nonbase_format].values.each do |hash|
clean_empty_module_from_hash hash
end
end
|
.extended(mod) ⇒ Object
each set file calls ‘extend Card::Set` when loaded
247
248
249
|
# File 'lib/card/set.rb', line 247
def extended mod
register_set mod
end
|
.process_base_module_list(list, klass) ⇒ Object
297
298
299
300
301
302
303
304
|
# File 'lib/card/set.rb', line 297
def process_base_module_list list, klass
list.each do |mod|
klass.send :include, mod if mod.instance_methods.any?
if (class_methods = mod.const_get_if_defined(:ClassMethods))
klass.send :extend, class_methods
end
end
end
|
.process_base_modules ⇒ Object
‘base modules’ are modules that are permanently included on the Card or Format class ‘nonbase modules’ are included dynamically on singleton_classes
288
289
290
291
292
293
294
295
|
# File 'lib/card/set.rb', line 288
def process_base_modules
process_base_module_list modules[:base], Card
modules[:base_format].each do |format_class, modules_list|
process_base_module_list modules_list, format_class
end
modules.delete :base
modules.delete :base_format
end
|
.register_set(set_module) ⇒ Object
make the set available for use
252
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/card/set.rb', line 252
def register_set set_module
if set_module.all_set?
modules[:base] << set_module
else
set_type = set_module.abstract_set? ? :abstract : :nonbase
modules[set_type][set_module.shortname] ||= []
modules[set_type][set_module.shortname] << set_module
end
end
|
.write_tmp_file(from_file, to_file, rel_path) ⇒ Object
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/card/set.rb', line 264
def write_tmp_file from_file, to_file, rel_path
name_parts = rel_path.gsub(/\.rb/, '').split(File::SEPARATOR)
submodules = name_parts.map { |a| "module #{a.camelize};" } * ' '
file_content = <<EOF
# -*- encoding : utf-8 -*-
class Card; module Set; #{submodules} extend Card::Set
# ~~~~~~~~~~~ above autogenerated; below pulled from #{from_file} ~~~~~~~~~~~
#{File.read from_file}
# ~~~~~~~~~~~ below autogenerated; above pulled from #{from_file} ~~~~~~~~~~~
end;end;#{'end;' * name_parts.size}
EOF
FileUtils.mkdir_p File.dirname(to_file)
File.write to_file, file_content
to_file
end
|
Instance Method Details
#abstract_set? ⇒ Boolean
348
349
350
|
# File 'lib/card/set.rb', line 348
def abstract_set?
name =~ /^Card::Set::Abstract::/
end
|
#all_set? ⇒ Boolean
352
353
354
|
# File 'lib/card/set.rb', line 352
def all_set?
name =~ /^Card::Set::All::/
end
|
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/card/set.rb', line 131
def define_on_format format_name=:base, &block
klass = Card::Format.format_class_name format_name
mod = const_get_or_set klass do
m = Module.new
register_set_format Card.const_get(klass), m
m.extend Card::Set::Format
m
end
mod.class_eval &block
end
|
190
191
192
193
194
195
196
197
|
# File 'lib/card/set.rb', line 190
def each_format set
set_type = set.abstract_set? ? :abstract : :nonbase
format_type = "#{set_type}_format".to_sym
@@modules[format_type].each_pair do |format, set_format_mod_hash|
next unless (format_mods = set_format_mod_hash[set.shortname])
yield format, format_mods
end
end
|
#ensure_set(&block) ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/card/set.rb', line 220
def ensure_set &block
set_module = yield
rescue NameError => e
if e.message =~ /uninitialized constant (?:Card::Set::)?(.+)$/
Regexp.last_match(1).split('::').inject(Card::Set) do |set_mod, module_name|
set_mod.const_get_or_set module_name do
Module.new
end
end
end
ensure_set &block
else
set_module.extend Card::Set
end
|
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/card/set.rb', line 119
def format *format_names, &block
if format_names.empty?
format_names = [:base]
elsif format_names.first == :all
format_names =
Card::Format.registered.reject { |f| Card::Format.aliases[f] }
end
format_names.each do |f|
define_on_format f, &block
end
end
|
#include_set(set, opts = {}) ⇒ Object
include a set module and all its format modules include_set Type::Basic, except: :css
182
183
184
185
186
187
188
|
# File 'lib/card/set.rb', line 182
def include_set set, opts={}
set_type = set.abstract_set? ? :abstract : :nonbase
@@modules[set_type][set.shortname].each do |set_mod|
include set_mod
end
include_set_formats set, opts
end
|
include a format modules of a set include_set Type::Basic, except: :css
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/card/set.rb', line 206
def include_set_formats set, opts={}
each_format set do |format, format_mods|
match = format.to_s.match(/::(?<format>[^:]+)Format/)
format_sym = match ? match[:format] : :base
next if opts[:except] && Array(opts[:except]).include?(format_sym)
next if opts[:only] && !Array(opts[:only]).include?(format_sym)
format_mods.each do |format_mod|
define_on_format format_sym do
include format_mod
end
end
end
end
|
321
322
323
324
325
326
327
328
329
330
331
332
333
|
# File 'lib/card/set.rb', line 321
def register_set_format format_class, mod
if all_set?
modules[:base_format][format_class] ||= []
modules[:base_format][format_class] << mod
else
format_type = abstract_set? ? :abstract_format : :nonbase_format
format_hash = modules[format_type][format_class] ||= {}
format_hash[shortname] ||= []
format_hash[shortname] << mod
end
end
|
#shortname ⇒ Object
335
336
337
338
339
340
341
342
343
344
345
346
|
# File 'lib/card/set.rb', line 335
def shortname
parts = name.split '::'
first = 2 pattern_name = parts[first].underscore
last = if pattern_name == 'abstract'
first + 1
else
set_class = Card::SetPattern.find pattern_name
first + set_class.anchor_parts_count
end
parts[first..last].join '::'
end
|
#stage_method(method, opts = {}, &block) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/card/set.rb', line 152
def stage_method method, opts={}, &block
class_eval do
define_method "_#{method}", &block
define_method method do |*args|
error =
if !director.stage_ok? opts
if !stage
"phase method #{method} called outside of event phases"
else
"#{opts.inspect} method #{method} called in phase #{stage}"
end
elsif !on_condition_applies?(opts[:on])
"on: #{opts[:on]} method #{method} called on #{@action}"
end
if error
raise Card::Error, error
else
send "_#{method}", *args
end
end
end
end
|
#view(*args, &block) ⇒ Object
146
147
148
149
150
|
# File 'lib/card/set.rb', line 146
def view *args, &block
format do
view *args, &block
end
end
|