Module: CMS::Helper
- Included in:
- ViewTags
- Defined in:
- lib/cms/helper.rb
Instance Method Summary collapse
- #cms_content_parse(content) ⇒ Object
- #cms_file(name, size = false) ⇒ Object
- #cms_image(name, size = false, width = '', height = '') ⇒ Object
- #cms_page_area(name, options = {}, &block) ⇒ Object
- #cms_page_area_edit_link ⇒ Object
- #markdown(text) ⇒ Object
- #render_cms_page_area_content(page_area, options = {}, &block) ⇒ Object
Instance Method Details
#cms_content_parse(content) ⇒ Object
84 85 86 87 |
# File 'lib/cms/helper.rb', line 84 def cms_content_parse content content = content.gsub(' ', ' ') CMS::ViewTags.instance.parse content, context: self end |
#cms_file(name, size = false) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/cms/helper.rb', line 8 def cms_file name, size = false if file = CMS::FileUpload.find_by_name(name) then return file end opts = {name: name} opts[:description] = (size.sub('x', ' by ') << ' pixels') if size CMS::FileUpload.create(opts, without_protection: true) end |
#cms_image(name, size = false, width = '', height = '') ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cms/helper.rb', line 15 def cms_image name, size = false, width = '', height = '' width, height = size.split('x') if size image = cms_file(name, size) style = if size then "width: #{width}px ; height: #{height}px" else '' end if image.file? image_tag image.file.url, class: 'cms-image', style: style else if current_user && current_user.role.admin? link_to(name, edit_cms_file_upload_path(image), class: 'cms-image missing-cms-image', style: style) else content_tag :div, name, class: 'cms-image missing-cms-image', style: style end end end |
#cms_page_area(name, options = {}, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cms/helper.rb', line 31 def cms_page_area name, = {}, &block page_area = if area = CMS::PageArea.find_by_name(name) then area else CMS::PageArea.new({name: name}, without_protection: true) end [:editable] = true unless .key?(:editable) if admin? && [:editable] content_tag :div, role: 'html-editor' do out = content_tag(:div, class: 'cms-page-area', role: 'display') do display = ''.html_safe display << cms_page_area_edit_link if admin? display << render_cms_page_area_content(page_area, , &block) end out << content_tag(:div, role: 'editor') do form_for([:cms, page_area], format: 'json', remote: true) do |f| form = f.hidden_field(:name) form << f.hidden_field(:content, class: 'content') form << f.actions(save: 'done') end end end else content_tag :div, class: 'cms-page-area' do render_cms_page_area_content(page_area, , &block) end end rescue Exception => e if Rails.env.production? then '' else raise e end end |
#cms_page_area_edit_link ⇒ Object
78 79 80 81 82 |
# File 'lib/cms/helper.rb', line 78 def cms_page_area_edit_link content_tag :div, class: 'cms-edit-link' do link_to('Edit', '#edit') end end |
#markdown(text) ⇒ Object
4 5 6 |
# File 'lib/cms/helper.rb', line 4 def markdown text Markdown.render(text).html_safe end |
#render_cms_page_area_content(page_area, options = {}, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cms/helper.rb', line 60 def render_cms_page_area_content page_area, = {}, &block if page_area.content.present? && !page_area.default content = page_area.content elsif block_given? content = capture(&block) page_area.content = ''.concat(content) page_area.save! end if [:format].try(:to_s) == 'markdown' content = markdown(content) end content_tag(:div, class: 'content') do cms_content_parse(content) if content.present? end end |