Module: Mokio::FrontendHelpers::StaticModulesHelper
- Defined in:
- lib/mokio/frontend_helpers/static_modules_helper.rb
Overview
Frontend helper methods used with Mokio::StaticModules objects
Instance Method Summary collapse
-
#build_content(obj, position, with_intro = true) ⇒ Object
check visibility and generate static modules tree from activerecord object.
-
#build_from_content(content, with_intro = true) ⇒ Object
builds html for a single position without tpl template.
-
#build_from_view_file(content, tpl) ⇒ Object
builds html for a single position with tpl template and render.
-
#build_static_modules(position_name, always_displayed = false, with_intro = true) ⇒ Object
returns all contents by position_name.
Instance Method Details
#build_content(obj, position, with_intro = true) ⇒ Object
check visibility and generate static modules tree from activerecord object
Attributes
-
obj
- static modules object from activerecord -
position
- module position object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mokio/frontend_helpers/static_modules_helper.rb', line 83 def build_content(obj,position, with_intro = true) html = "" obj.each do |pos| content = pos if(content.displayed?) if(position.tpl.blank?) html << build_from_content(content, with_intro) else html << build_from_view_file(content,position.tpl) end end end html.html_safe end |
#build_from_content(content, with_intro = true) ⇒ Object
builds html for a single position without tpl template
Attributes
-
content
- single static module from result
Variables
-
content.intro
- static_module_intro from mokio_static_modules -
content.content
- static_module_content from mokio_static_modules
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mokio/frontend_helpers/static_modules_helper.rb', line 49 def build_from_content(content, with_intro = true) html = "" if with_intro html = "<div class='static-module'>" html << "<div>#{content.intro}</div>" html << "<div>#{content.content}</div>" html << "</div>" else html << content.content end html.html_safe end |
#build_from_view_file(content, tpl) ⇒ Object
builds html for a single position with tpl template and render
Attributes
-
content
- single static module from result -
tpl
- tpl path
70 71 72 73 |
# File 'lib/mokio/frontend_helpers/static_modules_helper.rb', line 70 def build_from_view_file(content,tpl) @html = render :file => tpl.strip, :locals => { :content => content } @html.html_safe end |
#build_static_modules(position_name, always_displayed = false, with_intro = true) ⇒ Object
returns all contents by position_name
Attributes
-
position_name
- name of the module position -
always_displayed
- display all modules for positions or only always displayed
Variables
-
content
- single static module from result -
position
- module position active record result
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mokio/frontend_helpers/static_modules_helper.rb', line 19 def build_static_modules(position_name,always_displayed = false, with_intro = true) lang = Mokio::Lang.default_frontend position = Mokio::ModulePosition.find_by_name(position_name) html = " " if !position.nil? if always_displayed mod = Mokio::AvailableModule.static_module_active_for_lang(position.id,lang.id).only_always_displayed else mod = Mokio::AvailableModule.static_module_active_for_lang(position.id,lang.id) end html << build_content(mod,position, with_intro) else html << "Position not found" end html.html_safe end |