app/helpers/styleus_helper.rb in styleus-0.0.4 vs app/helpers/styleus_helper.rb in styleus-0.0.5
- old
+ new
@@ -4,52 +4,64 @@
@component_list = @components.map do |component|
wrap_component component
end
- component_menu.concat(_joined_component_list)
+ component_index(components_category).concat(_joined_component_list)
end
-
def wrap_component(component)
- _styleus_article_wrap(headline: component.headline, anchor_id: component.id) do
- styleus_partials(component.partial_path)
+ article = _styleus_article_wrap(headline: component.headline, id: component.id) do
+ styleus_partials(component.partial_path, helper: component.helper?)
end
+ option_bar(component).concat article
end
- def styleus_partials(partial_path)
- sample_template = _styleus_representation_wrap(class: '__boxed') do
- render partial: "#{partial_path}_sample"
- end
+ def styleus_partials(partial_path, options = { })
+ sample_template = _styleus_representation_wrap(class: '__boxed') { render partial: "#{partial_path}_sample" }
- plain_template = _coderay_highlight_wrap("#{partial_path}.html.erb") do
- render partial: "#{partial_path}"
- end
+ plain_template = _html_representation("#{partial_path}.html.erb") { render partial: "#{partial_path}" }
- sample_template.concat(plain_template)
+ helper_template = _helper_representation { render partial: "#{partial_path}_helper" } if options[:helper]
+
+ sample_template.concat(plain_template).concat(helper_template || safe_empty)
end
- def component_menu
- return if @components.empty?
- content_tag 'nav' do
+ def option_bar(component)
+ content_tag 'nav', class: '__option_bar' do
content_tag 'ul' do
+ html_area = content_tag('li') { link_to t('icons.html'), component_path(component), title: t('links.titles.html'), class: 'icon', data: { toggle: "##{component.id} [data-subject=html-representation]" } }
+ helper_area = content_tag('li') { link_to t('icons.helper'), component_path(component), title: t('links.titles.helper'), class: 'icon', data: { toggle: "##{component.id} [data-subject=ruby-representation]" } } if component.helper?
+ presentation_area = content_tag('li') { link_to t('icons.expand_all'), component_path(component), title: t('links.titles.expand_all'), class: 'icon', data: { toggle: "##{component.id} [data-subject*=representation]" } }
+
+ html_area.concat(helper_area || safe_empty).concat(presentation_area)
+ end
+ end
+ end
+
+ def component_index(headline)
+ return if @components.empty?
+ content_tag 'nav', class: "__component_index" do
+ menu_entries = content_tag 'ul' do
content_tag_for(:li, @components) do |component|
link_to component.headline, anchor: component.id
end
end
+ content_tag('h3', headline).concat menu_entries
end
+
end
def _styleus_article_wrap(options = { }, &block)
captured_block = capture(&block)
- content_tag('article', class: '__sg_article', id: options[:anchor_id]) do
- content = ''
+ content_tag('article', class: '__sg_article', id: options[:id]) do
+ content = safe_empty
headline = options[:headline]
content.concat(content_tag('h3', headline)) if headline
content.concat(captured_block)
- content.html_safe
+ content
end
end
def _styleus_representation_wrap(options = { }, &block)
captured_block = capture(&block)
@@ -60,19 +72,34 @@
captured_block.to_s.html_safe
end
end
end
- 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') : ''
+ def _html_representation(note = nil, &block)
+ _coderay_highlight_wrap(note, type: :html, &block)
+ end
- highlighted_code = "#{note_tag}#{code_block.div(:css => :class)}"
- highlighted_code.html_safe
+ def _helper_representation(&block)
+ _coderay_highlight_wrap('Rails Helper', type: :ruby, &block)
end
+ def _coderay_highlight_wrap(note = nil, options = { type: :html }, &block)
+ captured_block = capture(&block)
+ code_block = CodeRay.scan(captured_block.to_s, options[:type])
+
+ note_tag = note ? content_tag('p', note, class: '__code_note') : safe_empty
+
+ highlighted_code = "#{note_tag}#{code_block.div(:css => :class, line_numbers: :table)}"
+ content_tag('div', data: { subject: "#{options[:type]}-representation" }) do
+ highlighted_code.html_safe
+ end
+ end
+
def _joined_component_list
@component_list.join.html_safe
+ end
+
+ def safe_empty
+ ''.html_safe
end
end
\ No newline at end of file