Class: Effective::Snippets::Snippet

Inherits:
Object
  • Object
show all
Defined in:
app/models/effective/snippets/snippet.rb

Direct Known Subclasses

CurrentUserInfo

Instance Method Summary collapse

Constructor Details

#initialize(atts = {}) ⇒ Snippet

Returns a new instance of Snippet.



19
20
21
# File 'app/models/effective/snippets/snippet.rb', line 19

def initialize(atts = {})
  (atts || {}).each { |k, v| self.send("#{k}=", v) if respond_to?("#{k}=") }
end

Instance Method Details

#class_nameObject



35
36
37
# File 'app/models/effective/snippets/snippet.rb', line 35

def class_name
  @class_name ||= self.class.name.demodulize.underscore.to_sym
end

#dataObject



27
28
29
# File 'app/models/effective/snippets/snippet.rb', line 27

def data
  self.attributes.reject { |k, v| [:region, :id].include?(k) }
end

#idObject



23
24
25
# File 'app/models/effective/snippets/snippet.rb', line 23

def id
  super.presence || "snippet_#{object_id}"
end

#snippet_descriptionObject



44
45
46
# File 'app/models/effective/snippets/snippet.rb', line 44

def snippet_description
  "Insert #{snippet_label}"
end

#snippet_dialog_urlObject



48
49
50
# File 'app/models/effective/snippets/snippet.rb', line 48

def snippet_dialog_url
  "/assets/effective/snippets/#{class_name}.js"
end

#snippet_editablesObject



63
64
65
# File 'app/models/effective/snippets/snippet.rb', line 63

def snippet_editables
  false
end

#snippet_inlineObject



59
60
61
# File 'app/models/effective/snippets/snippet.rb', line 59

def snippet_inline
  [:span].include?(snippet_tag)
end

#snippet_labelObject

The following methods are used for the CKEditor widget creation.



40
41
42
# File 'app/models/effective/snippets/snippet.rb', line 40

def snippet_label
  class_name.to_s.humanize
end

#snippet_tagObject

This is the tag that the ckeditor snippet will be created as It supports divs and spans, but that’s it No ULs, or LIs



55
56
57
# File 'app/models/effective/snippets/snippet.rb', line 55

def snippet_tag
  :div
end

#to_partial_pathObject



31
32
33
# File 'app/models/effective/snippets/snippet.rb', line 31

def to_partial_path
  "effective/snippets/#{class_name}"
end