Module: Enjoy::Pages::Models::Block

Extended by:
ActiveSupport::Concern
Includes:
Enableable, Model, ManualSlug
Included in:
Block
Defined in:
lib/enjoy/pages/models/block.rb

Instance Method Summary collapse

Instance Method Details

#file_fullpath(with_ext = false, ext = ".html.slim") ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/enjoy/pages/models/block.rb', line 65

def file_fullpath(with_ext = false, ext = ".html.slim")
  ret = nil
  unless self.file_path.blank?
    res_filename = self.file_pathname_for_fs.to_s
    res_filename += ext if with_ext
    ret = Rails.root.join("views", res_filename)
  end
  return ret
end

#file_pathname_as_partialObject



26
27
28
# File 'lib/enjoy/pages/models/block.rb', line 26

def file_pathname_as_partial
  self.file_pathname.dirname.join("_#{self.file_pathname.basename}")
end

#file_pathname_for_fsObject



30
31
32
# File 'lib/enjoy/pages/models/block.rb', line 30

def file_pathname_for_fs
  self.partial ? self.file_path_as_partial : self.file_pathname
end


75
76
77
# File 'lib/enjoy/pages/models/block.rb', line 75

def nav_options
  nav_options_default.deep_merge(nav_options_additions)
end


91
92
93
# File 'lib/enjoy/pages/models/block.rb', line 91

def nav_options_additions
  {}
end


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/enjoy/pages/models/block.rb', line 79

def nav_options_default
  {
    highlights_on: false,
    link_html: {
      data: {
        pageblock_selector: self.pageblock_selector,
        history_name: self.name
      }
    }
  }
end

#render_or_content(view, opts = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/enjoy/pages/models/block.rb', line 53

def render_or_content(view, opts = {})
  ret = ""
  unless self.file_path.blank?
    opts.merge!(partial: self.file_path)
    ret = view.render(opts) rescue self.content
  else
    ret = self.content
  end
  ret = yield ret if block_given?
  return ret
end

#render_or_content_html(view, opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/enjoy/pages/models/block.rb', line 34

def render_or_content_html(view, opts = {})
  ret = ""
  unless self.file_path.blank?
    opts.merge!(partial: self.file_path)
    ret = view.render(opts) rescue self.content_html.html_safe
  else
    ret = self.content_html.html_safe
  end
  if use_wrapper
    _attrs = {
      class: wrapper_class,
      id: wrapper_id
    }.merge(wrapper_attributes)
    ret = view. wrapper_tag, ret, _attrs
  end
  ret = yield ret if block_given?
  return ret
end

#wrapper_attributes=(val) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/enjoy/pages/models/block.rb', line 95

def wrapper_attributes=(val)
  if val.is_a? (String)
    begin
      begin
        self[:wrapper_attributes] = JSON.parse(val)
      rescue
        self[:wrapper_attributes] = YAML.load(val)
      end
    rescue
    end
  elsif val.is_a?(Hash)
    self[:wrapper_attributes] = val
  else
    self[:wrapper_attributes] = wrapper_attributes
  end
end