Module: StyleusHelper
- Defined in:
- app/helpers/styleus_helper.rb
Instance Method Summary collapse
- #_coderay_highlight_wrap(note = nil, &block) ⇒ Object
- #_joined_component_list ⇒ Object
- #_styleus_article_wrap(options = { }, &block) ⇒ Object
- #_styleus_representation_wrap(options = { }, &block) ⇒ Object
- #component_menu ⇒ Object
- #styleus(comp_list = []) ⇒ Object
- #styleus_partials(partial_path) ⇒ Object
- #wrap_component(component) ⇒ Object
Instance Method Details
#_coderay_highlight_wrap(note = nil, &block) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/styleus_helper.rb', line 65 def _coderay_highlight_wrap(note = nil, &block) captured_block = capture(&block) code_block = CodeRay.scan(captured_block.to_s, :html) note_tag = note ? content_tag('p', note, class: '__code_note') : '' highlighted_code = "#{note_tag}#{code_block.div(:css => :class)}" highlighted_code.html_safe end |
#_joined_component_list ⇒ Object
75 76 77 |
# File 'app/helpers/styleus_helper.rb', line 75 def _joined_component_list @component_list.join.html_safe end |
#_styleus_article_wrap(options = { }, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/styleus_helper.rb', line 42 def _styleus_article_wrap( = { }, &block) captured_block = capture(&block) content_tag('article', class: '__sg_article', id: [:anchor_id]) do content = '' headline = [:headline] content.concat(content_tag('h3', headline)) if headline content.concat(captured_block) content.html_safe end end |
#_styleus_representation_wrap(options = { }, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/styleus_helper.rb', line 54 def _styleus_representation_wrap( = { }, &block) captured_block = capture(&block) classes = '__sg_component'.concat(" #{[:class].to_s}") content_tag('section', class: classes) do render layout: 'layouts/styleus_context' do captured_block.to_s.html_safe end end end |
#component_menu ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/styleus_helper.rb', line 31 def return if @components.empty? content_tag 'nav' do content_tag 'ul' do content_tag_for(:li, @components) do |component| link_to component.headline, anchor: component.id end end end end |
#styleus(comp_list = []) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'app/helpers/styleus_helper.rb', line 2 def styleus(comp_list = []) @components = Styleus::ViewComponent.from_hashes(comp_list) @component_list = @components.map do |component| wrap_component component end .concat(_joined_component_list) end |
#styleus_partials(partial_path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/styleus_helper.rb', line 19 def styleus_partials(partial_path) sample_template = _styleus_representation_wrap(class: '__boxed') do render partial: "#{partial_path}_sample" end plain_template = _coderay_highlight_wrap("#{partial_path}.html.erb") do render partial: "#{partial_path}" end sample_template.concat(plain_template) end |
#wrap_component(component) ⇒ Object
13 14 15 16 17 |
# File 'app/helpers/styleus_helper.rb', line 13 def wrap_component(component) _styleus_article_wrap(headline: component.headline, anchor_id: component.id) do styleus_partials(component.partial_path) end end |