styleus 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,51 +1,46 @@
1
1
  module StyleusHelper
2
- def styleus(components = [])
3
- menu_entries = []
4
- component_listing = components.map do |options|
5
- styleus_component(options[:headline], options[:partial_path], menu_entries)
2
+ def styleus(comp_list = [])
3
+ component_list = ComponentList.from_hashes(comp_list)
4
+
5
+ component_listing = component_list.components.map do |component|
6
+ wrap_component component
6
7
  end
7
8
 
8
- styleus_list(menu_entries).concat(component_listing.join.html_safe)
9
+ component_menu(component_list).concat(component_listing.join.html_safe)
9
10
  end
10
11
 
11
- def styleus_component(headline, partial_path, menu = nil)
12
- # create a "unique" id for anchor tags
13
- #TODO make it really unique ^^
14
- component_id = "#{headline}#{rand(999)}".underscore
15
-
12
+ def wrap_component(component)
16
13
  # add component to linked list menu
17
- menu.push({ id: component_id, headline: headline }) if menu
18
-
19
- _styleus_article_wrap(headline: headline, anchor_id: component_id) do
20
- styleus_partials(partial_path)
14
+ #menu.push({ id: component.id, headline: component.headline }) if menu
15
+ _styleus_article_wrap(headline: component.headline, anchor_id: component.id) do
16
+ styleus_partials(component.partial_path)
21
17
  end
22
18
  end
23
19
 
24
20
  def styleus_partials(partial_path)
25
21
  sample_template = _styleus_representation_wrap(class: '__boxed') do
26
- render partial: "#{partial_path}_sample"
27
- end
22
+ render partial: "#{partial_path}_sample"
23
+ end
28
24
 
29
- plain_template = _coderay_highlight_wrap("#{partial_path}.html.erb") do
30
- render partial: "#{partial_path}_plain"
31
- end
25
+ plain_template = _coderay_highlight_wrap("#{partial_path}.html.erb") do
26
+ render partial: "#{partial_path}_plain"
27
+ end
32
28
 
33
- sample_template.concat(plain_template)
29
+ sample_template.concat(plain_template)
34
30
  end
35
31
 
36
- def styleus_list(menu_entries)
32
+ def component_menu(component_list)
37
33
  content_tag 'nav' do
38
34
  content_tag 'ul' do
39
- link_list = menu_entries.map do |entry|
40
- content_tag 'li' do
41
- link_to entry[:headline], anchor: entry[:id]
42
- end
35
+ content_tag_for(:li, component_list.components) do |component|
36
+ link_to component.headline, anchor: component.id
43
37
  end
44
- link_list.join.html_safe
45
38
  end
46
39
  end
47
40
  end
48
41
 
42
+
43
+
49
44
  def _styleus_article_wrap(options = { }, &block)
50
45
  captured_block = capture(&block)
51
46
 
@@ -0,0 +1,31 @@
1
+ class Base
2
+ extend ActiveModel::Naming
3
+ include ActiveModel::AttributeMethods
4
+ include ActiveModel::Serialization
5
+
6
+ def initialize(attributes)
7
+ @attributes = attributes
8
+ end
9
+
10
+ def id
11
+ @id ||= rand(99999999)
12
+ end
13
+
14
+ # as implemented as in ActiveRecord
15
+ def to_key
16
+ key = self.id
17
+ [key] if key
18
+ end
19
+
20
+ private
21
+
22
+ def attribute(attr)
23
+ @attributes[attr.to_sym]
24
+ end
25
+
26
+ class << self
27
+ def with_attributes(*attribute_names)
28
+ define_attribute_methods attribute_names.map(&:to_s)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ class Component < Base
2
+ with_attributes :headline, :partial_path
3
+ end
@@ -0,0 +1,15 @@
1
+ class ComponentList
2
+
3
+ def components
4
+ @components ||= []
5
+ end
6
+
7
+ class << self
8
+ def from_hashes(hashes)
9
+ @component_list = ComponentList.new
10
+ hashes.each { |comp_hash| @component_list.components << Component.new(comp_hash)}
11
+ @component_list
12
+ end
13
+ end
14
+
15
+ end
@@ -8,7 +8,7 @@
8
8
  </head>
9
9
  <body>
10
10
  <div class="__sg_wrapper">
11
- <%= yield %>
11
+ <%= yield :components %>
12
12
  </div>
13
13
  </body>
14
14
  </html>
@@ -1,3 +1,3 @@
1
1
  module Styleus
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: styleus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-19 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -75,7 +75,10 @@ files:
75
75
  - app/assets/stylesheets/styleus/settings/_colors.css.scss
76
76
  - app/assets/stylesheets/styleus.css
77
77
  - app/helpers/styleus_helper.rb
78
- - app/views/layouts/application.html.erb
78
+ - app/models/base.rb
79
+ - app/models/component.rb
80
+ - app/models/component_list.rb
81
+ - app/views/layouts/_styleus.html.erb
79
82
  - app/views/styleus/_screen_size_viewer.html.erb
80
83
  - config/routes.rb
81
84
  - lib/styleus/engine.rb