Module: Gluttonberg::ContentHelpers
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/gluttonberg/content_helpers.rb
Instance Method Summary collapse
-
#content_editor(content_class) ⇒ Object
Looks for a matching partial in the templates directory.
-
#enable_jwysiwyg_on_class(html_class) ⇒ Object
generate javascript code to enable tinymce on it.
-
#enable_slug_management_on(html_class) ⇒ Object
generate javascript code to enable tinymce on it.
-
#gb_content_for(section_name, opts = nil) ⇒ Object
Returns the content record for the specified section.
- #gb_image_alt_text(section_name, opts = {}) ⇒ Object
-
#gb_image_url(section_name, opts = {}) ⇒ Object
Renders an image url, allows the designer to specify who they want to handle the image.
-
#render_content_for(section_name, opts = {}) ⇒ Object
Finds the matching content block and determines the helper it needs to execute to actually write the contents to page.
-
#render_html_content(content, opts = nil) ⇒ Object
Render html content.
-
#render_image_content(content, opts = {}) ⇒ Object
Renders an image tag with the src set to the associated asset.
-
#render_plain_text_content(content, opts = nil) ⇒ Object
Simple as it gets, it just pulles the text property from the content record.
Instance Method Details
#content_editor(content_class) ⇒ Object
Looks for a matching partial in the templates directory. Failing that, it falls back to Gluttonberg’s view dir — views/content/editors
78 79 80 81 82 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 78 def content_editor(content_class) locals = {:content => content_class} type = content_class.content_type render :partial => Gluttonberg::Templates.editor_template_path(type) , :locals => locals end |
#enable_jwysiwyg_on_class(html_class) ⇒ Object
generate javascript code to enable tinymce on it. textArea need to have class = jwysiwyg
85 86 87 88 89 90 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 85 def enable_jwysiwyg_on_class(html_class) if Gluttonberg::Setting.get_setting("enable_WYSIWYG") == "Yes" content = "enable_jwysiwyg_on('.#{html_class}'); \n" javascript_tag(content) end end |
#enable_slug_management_on(html_class) ⇒ Object
generate javascript code to enable tinymce on it. textArea need to have class = jwysiwyg
93 94 95 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 93 def enable_slug_management_on(html_class) javascript_tag("enable_slug_management_on('#{html_class}')" ) end |
#gb_content_for(section_name, opts = nil) ⇒ Object
Returns the content record for the specified section. It will include the relevant localized version based the current locale/dialect
23 24 25 26 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 23 def gb_content_for(section_name, opts = nil) section_name = section_name.to_sym @page.localized_contents.pluck {|c| c.section[:name] == section_name} end |
#gb_image_alt_text(section_name, opts = {}) ⇒ Object
63 64 65 66 67 68 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 63 def gb_image_alt_text(section_name, opts = {}) content = gb_content_for(section_name) if content.asset content.asset.name end end |
#gb_image_url(section_name, opts = {}) ⇒ Object
Renders an image url, allows the designer to specify who they want to handle the image.
52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 52 def gb_image_url(section_name, opts = {}) content = gb_content_for(section_name) if content.asset if opts[:url_for].blank? content.asset.url else content.asset.url_for(opts[:url_for].to_sym) end end end |
#render_content_for(section_name, opts = {}) ⇒ Object
Finds the matching content block and determines the helper it needs to execute to actually write the contents to page. TODO: if there is no way to to render the content, freak out and raise an error
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 7 def render_content_for(section_name, opts = {}) # At present this generates a bunch of queries. Eventually we should # look at caching section names to save some DB hits. content = gb_content_for(section_name) render_method = :"render_#{content.content_type}" if respond_to? render_method send(:"render_#{content.content_type}", content, opts) elsif content.respond_to? :text content.text else # raise Gluttonberg::ContentRenderError, "Don't know how to render this content" end end |
#render_html_content(content, opts = nil) ⇒ Object
Render html content. Actually just looks for the text property on the content model.
30 31 32 33 34 35 36 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 30 def render_html_content(content, opts = nil) if content.current_localization.text content.current_localization.text.html_safe else "" end end |
#render_image_content(content, opts = {}) ⇒ Object
Renders an image tag with the src set to the associated asset. If the asset is missing it returns nil.
41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 41 def render_image_content(content, opts = {}) if content.asset if opts[:url_for].blank? image_tag(content.asset.url, opts.merge!(:alt => content.asset.name)) else image_tag(content.asset.url_for(opts[:url_for].to_sym), opts.merge!(:alt => content.asset.name)) end end end |
#render_plain_text_content(content, opts = nil) ⇒ Object
Simple as it gets, it just pulles the text property from the content record
72 73 74 |
# File 'app/helpers/gluttonberg/content_helpers.rb', line 72 def render_plain_text_content(content, opts = nil) content.current_localization.text end |