Module: StyleusHelper
- Defined in:
- app/helpers/styleus_helper.rb
Instance Method Summary collapse
- #_coderay_highlight_wrap(note = nil, &block) ⇒ Object
- #_styleus_article_wrap(options = { }, &block) ⇒ Object
- #_styleus_representation_wrap(options = { }, &block) ⇒ Object
- #styleus(components = []) ⇒ Object
- #styleus_component(headline, partial_path, menu = nil) ⇒ Object
- #styleus_list(menu_entries) ⇒ Object
- #styleus_partials(partial_path) ⇒ Object
Instance Method Details
#_coderay_highlight_wrap(note = nil, &block) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/helpers/styleus_helper.rb', line 69 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 |
#_styleus_article_wrap(options = { }, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/styleus_helper.rb', line 49 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
61 62 63 64 65 66 67 |
# File 'app/helpers/styleus_helper.rb', line 61 def _styleus_representation_wrap( = { }, &block) captured_block = capture(&block) classes = '__sg_component'.concat(" #{options[:class].to_s}") content_tag('section', class: classes) do captured_block.to_s.html_safe end end |
#styleus(components = []) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'app/helpers/styleus_helper.rb', line 2 def styleus(components = []) = [] component_listing = components.map do || styleus_component([:headline], [:partial_path], ) end styleus_list().concat(component_listing.join.html_safe) end |
#styleus_component(headline, partial_path, menu = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/styleus_helper.rb', line 11 def styleus_component(headline, partial_path, = nil) # create a "unique" id for anchor tags #TODO make it really unique ^^ component_id = "#{headline}#{rand(999)}".underscore # add component to linked list menu .push({ id: component_id, headline: headline }) if _styleus_article_wrap(headline: headline, anchor_id: component_id) do styleus_partials(partial_path) end end |
#styleus_list(menu_entries) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/styleus_helper.rb', line 36 def styleus_list() content_tag 'nav' do content_tag 'ul' do link_list = .map do |entry| content_tag 'li' do link_to entry[:headline], anchor: entry[:id] end end link_list.join.html_safe end end end |
#styleus_partials(partial_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/styleus_helper.rb', line 24 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}_plain" end sample_template.concat(plain_template) end |