Class: Workarea::Content
- Inherits:
-
Object
- Object
- Workarea::Content
- Includes:
- ApplicationDocument, Commentable, Releasable
- Defined in:
- app/models/workarea/content.rb,
app/models/workarea/content/block.rb,
app/models/workarea/content/email.rb,
app/models/workarea/content/field.rb,
app/models/workarea/content/preset.rb,
app/models/workarea/content/fieldset.rb,
app/models/workarea/content/block_name.rb,
app/models/workarea/content/block_type.rb,
app/models/workarea/content/fields/url.rb,
app/models/workarea/content/block_draft.rb,
app/models/workarea/content/fields/text.rb,
app/models/workarea/content/asset_lookup.rb,
app/models/workarea/content/fields/asset.rb,
app/models/workarea/content/fields/color.rb,
app/models/workarea/content/fields/range.rb,
app/models/workarea/content/fields/string.rb,
app/models/workarea/content/fields/boolean.rb,
app/models/workarea/content/fields/integer.rb,
app/models/workarea/content/fields/options.rb,
app/models/workarea/content/fields/category.rb,
app/models/workarea/content/fields/products.rb,
app/models/workarea/content/fields/taxonomy.rb,
app/models/workarea/content/fields/breakpoints.rb,
app/models/workarea/content/block_type_definition.rb
Defined Under Namespace
Modules: AssetLookup, Fields Classes: Asset, Block, BlockDraft, BlockName, BlockType, BlockTypeDefinition, Email, Field, Fieldset, Page, Preset
Class Method Summary collapse
- .define_block_types(&block) ⇒ Object
-
.for(object) ⇒ Content
Find Content for a given object.
- .from_block(block_id) ⇒ Content
Instance Method Summary collapse
-
#all_text ⇒ Array<String>
Get an array of all text strings associated as part of this content.
-
#blocks_for(area) ⇒ Array<Block>
Find an array of active blocks for a given area.
-
#home_page? ⇒ Boolean
Whether this is home page content, which is a special case.
-
#layout? ⇒ Boolean
Whether this is layout content, which is a special case.
-
#name ⇒ String
The name for this content, returns the name of the contentable if that is present.
-
#slug ⇒ String
Slug for the type of object this content is attached to.
-
#system? ⇒ Boolean
Whether this content belongs to a system page as opposed to a contentable model.
Methods included from Commentable
#add_subscription, #remove_subscription
Methods included from Releasable
#changesets_with_children, #destroy, #in_release, #release_changes, #release_originals, #save_changeset, #skip_changeset, #without_release
Methods included from Segmentable
#active?, #active_segment_ids_with_children, #segmented?, #segments
Methods included from Release::Activation
#activate_with?, #create_activation_changeset, #save_activate_with, #was_active?
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Methods included from Mongoid::Document
Class Method Details
.define_block_types(&block) ⇒ Object
63 64 65 66 67 |
# File 'app/models/workarea/content.rb', line 63 def define_block_types(&block) require_dependency 'workarea/content/block_type_definition' definition = BlockTypeDefinition.new definition.instance_eval(&block) end |
.for(object) ⇒ Content
Find Workarea::Content for a given object. Object can be string or model (polymorphic).
41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/workarea/content.rb', line 41 def self.for(object) if object.is_a?(String) find_or_create_by(name: object.titleize) else find_or_create_by( contentable_id: object.try(:id), contentable_type: object.try(:class) ) end end |
.from_block(block_id) ⇒ Content
Find the Workarea::Content from a Block id
56 57 58 59 |
# File 'app/models/workarea/content.rb', line 56 def self.from_block(block_id) block_id = BSON::ObjectId.from_string(block_id.to_s) find_by('blocks._id' => block_id) rescue nil end |
Instance Method Details
#all_text ⇒ Array<String>
Get an array of all text strings associated as part of this content. Used in indexing content for search.
143 144 145 |
# File 'app/models/workarea/content.rb', line 143 def all_text blocks.map { |b| b.data.values }.flatten end |
#blocks_for(area) ⇒ Array<Block>
Find an array of active blocks for a given area.
134 135 136 |
# File 'app/models/workarea/content.rb', line 134 def blocks_for(area) blocks.where(area: area).all end |
#home_page? ⇒ Boolean
Whether this is home page content, which is a special case. Used when linking to contentable.
115 116 117 |
# File 'app/models/workarea/content.rb', line 115 def home_page? name =~ /home/i end |
#layout? ⇒ Boolean
Whether this is layout content, which is a special case. Used when linking to contentable.
125 126 127 |
# File 'app/models/workarea/content.rb', line 125 def layout? name =~ /layout/i end |
#name ⇒ String
The name for this content, returns the name of the contentable if that is present.
79 80 81 82 83 84 85 |
# File 'app/models/workarea/content.rb', line 79 def name if !system? && contentable.present? contentable.name else read_attribute(:name) end end |
#slug ⇒ String
Slug for the type of object this content is attached to.
101 102 103 104 105 106 107 |
# File 'app/models/workarea/content.rb', line 101 def slug if system? name.slugify else contentable_type.to_s.demodulize.underscore end end |
#system? ⇒ Boolean
Whether this content belongs to a system page as opposed to a contentable model.
92 93 94 |
# File 'app/models/workarea/content.rb', line 92 def system? contentable_type.blank? end |