styleus 0.0.10 → 0.0.11
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.
- data/app/helpers/external_helper.rb +14 -15
- data/app/helpers/styleus_helper.rb +22 -21
- data/app/helpers/styleus_representer_helper.rb +2 -2
- data/app/models/styleus/component.rb +44 -1
- data/app/models/styleus/view_component.rb +10 -4
- data/app/views/components/index.html.erb +2 -2
- data/app/views/styleus/_option_bar.html.erb +1 -1
- data/app/views/styleus/_styleus_partials.html.erb +1 -1
- data/config/initializers/zz_preload_models.rb +15 -0
- data/config/routes.rb +3 -2
- data/lib/styleus.rb +0 -1
- data/lib/styleus/engine.rb +0 -1
- data/lib/styleus/version.rb +1 -1
- metadata +4 -5
- data/config/initializers/02_init_container_routes.rb +0 -1
- data/lib/styleus/spacable.rb +0 -14
@@ -6,38 +6,37 @@ module ExternalHelper
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def documentation(&block)
|
9
|
-
|
9
|
+
content_for :documentation, _styleus_documentation_wrap(&block)
|
10
10
|
end
|
11
11
|
|
12
12
|
def display(&block)
|
13
|
-
|
13
|
+
content_for :representation, capture(&block)
|
14
14
|
end
|
15
15
|
|
16
16
|
def html(&block)
|
17
|
-
|
17
|
+
content_for :html, _html_representation(&block)
|
18
18
|
end
|
19
19
|
|
20
20
|
def helper(&block)
|
21
|
-
|
21
|
+
content_for :helper, _helper_representation(&block)
|
22
22
|
end
|
23
23
|
|
24
|
-
def styleus_page(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def styleus_page(&block)
|
25
|
+
index = styleus_index
|
26
|
+
components = styleus_components
|
27
|
+
documentation = ''
|
28
|
+
documentation = index_documentation(&block) if block_given?
|
29
|
+
index.concat(documentation).concat(components)
|
29
30
|
end
|
30
31
|
|
31
|
-
def styleus_components
|
32
|
-
_build_view_components
|
33
|
-
|
32
|
+
def styleus_components
|
33
|
+
_build_view_components
|
34
34
|
@component_list = @components.map { |component| _wrap_component component }
|
35
|
-
|
36
35
|
@component_list.join.html_safe
|
37
36
|
end
|
38
37
|
|
39
|
-
def styleus_index
|
40
|
-
_build_view_components
|
38
|
+
def styleus_index
|
39
|
+
_build_view_components
|
41
40
|
_component_index(components_category, @components)
|
42
41
|
end
|
43
42
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'styleus_representer_helper'
|
2
2
|
|
3
3
|
module StyleusHelper
|
4
|
+
def _section
|
5
|
+
params[:components]
|
6
|
+
end
|
7
|
+
|
4
8
|
def _application_context(&block)
|
5
9
|
captured_block = capture(&block)
|
6
10
|
|
@@ -21,7 +25,7 @@ module StyleusHelper
|
|
21
25
|
|
22
26
|
partial_name = 'component_context'
|
23
27
|
partial_path = File.join view_path, 'component_context'
|
24
|
-
file_path
|
28
|
+
file_path = File.join view_path, "_#{partial_name}.html.erb"
|
25
29
|
|
26
30
|
if _partial_exists?(file_path)
|
27
31
|
render(layout: partial_path) { captured_block }
|
@@ -50,36 +54,33 @@ module StyleusHelper
|
|
50
54
|
# and enables the configured content_for blocks for the target
|
51
55
|
# partial called styleus_partials.
|
52
56
|
def _styleus_partials(component, options = { })
|
57
|
+
_clear_content_for_registrations(:documentation, :representation, :html, :helper)
|
53
58
|
# execute application partial without responding it directly,
|
54
59
|
# so only the given content_for methods will help.
|
55
60
|
render partial: "#{component.partial_path}", locals: { component: component }
|
56
61
|
|
57
62
|
# returning concatenating responder partial, which consists of content_for blocks only.
|
58
|
-
render(layout: 'styleus/styleus_partials', locals: { component: component }) { }
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
# blocks each time, we have to clean up them before registering
|
64
|
-
# the next blocks.
|
65
|
-
#
|
66
|
-
# So this function wraps the content_for function with
|
67
|
-
# a prepended clearing for the specific content_for attribute,
|
68
|
-
# so that earlier defined content_for areas are not
|
69
|
-
# rendered again.
|
70
|
-
def _cleared_content_for(content_name, content)
|
71
|
-
# clear content_for calls for this name
|
72
|
-
@view_flow.set(content_name, '')
|
63
|
+
result = render(layout: 'styleus/styleus_partials', locals: { component: component }) { }
|
64
|
+
flush_output_buffer
|
65
|
+
_clear_content_for_registrations(:documentation, :representation, :html, :helper)
|
66
|
+
result
|
67
|
+
end
|
73
68
|
|
74
|
-
|
75
|
-
|
69
|
+
# clean up content_for blocks, so same content_for names can be used several times
|
70
|
+
def _clear_content_for_registrations(*content_names)
|
71
|
+
# clear content_for calls for this name
|
72
|
+
content_names.each { |content_name| @view_flow.set(content_name, '') }
|
76
73
|
end
|
77
74
|
|
78
75
|
|
79
76
|
# converts the list of component hashes configured in the
|
80
77
|
# app to a list of ViewComponent instances.
|
81
|
-
def _build_view_components
|
82
|
-
@components ||= Styleus::ViewComponent.
|
78
|
+
def _build_view_components
|
79
|
+
@components ||= Styleus::ViewComponent.from_names(_section, _section_class.components)
|
80
|
+
end
|
81
|
+
|
82
|
+
def _section_class
|
83
|
+
_section.camelcase.singularize.constantize
|
83
84
|
end
|
84
85
|
|
85
86
|
# wraps a component in an article and combines it with
|
@@ -87,7 +88,7 @@ module StyleusHelper
|
|
87
88
|
# and hide the different partials.
|
88
89
|
def _wrap_component(component)
|
89
90
|
_styleus_article_wrap(component) do
|
90
|
-
_styleus_partials(component
|
91
|
+
_styleus_partials(component)
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module StyleusRepresenterHelper
|
2
|
-
def _option_bar(component)
|
3
|
-
_render_styleus('option_bar', locals: { component: component })
|
2
|
+
def _option_bar(component, helper)
|
3
|
+
_render_styleus('option_bar', locals: { component: component, helper: helper })
|
4
4
|
end
|
5
5
|
|
6
6
|
def _component_index(headline, components)
|
@@ -1,5 +1,48 @@
|
|
1
1
|
module Styleus
|
2
2
|
class Component
|
3
|
-
|
3
|
+
class_attribute :_sections, :components, :_section_name
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def components(*new_components)
|
7
|
+
return registered_components if new_components.empty?
|
8
|
+
|
9
|
+
registered_components.push(*new_components).uniq!
|
10
|
+
registered_components
|
11
|
+
end
|
12
|
+
|
13
|
+
def registered_components
|
14
|
+
styleus_sections[section_key] ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def styleus_sections
|
18
|
+
::Styleus::Component.sections
|
19
|
+
end
|
20
|
+
|
21
|
+
def sections
|
22
|
+
self._sections ||= { }
|
23
|
+
end
|
24
|
+
|
25
|
+
def section_key
|
26
|
+
section_name.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def section_name
|
30
|
+
self._section_name ||= to_underscore
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_underscore
|
34
|
+
underscored_module_name
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def underscored_module_name
|
40
|
+
underscored_name.gsub('/', '_')
|
41
|
+
end
|
42
|
+
|
43
|
+
def underscored_name
|
44
|
+
name.underscore
|
45
|
+
end
|
46
|
+
end
|
4
47
|
end
|
5
48
|
end
|
@@ -9,10 +9,6 @@ module Styleus
|
|
9
9
|
headline.underscore.gsub(/ /, '_')
|
10
10
|
end
|
11
11
|
|
12
|
-
def helper?
|
13
|
-
!!helper
|
14
|
-
end
|
15
|
-
|
16
12
|
class << self
|
17
13
|
def components
|
18
14
|
@components ||= []
|
@@ -23,6 +19,16 @@ module Styleus
|
|
23
19
|
hashes.each { |comp_hash| components << new(comp_hash) }
|
24
20
|
components
|
25
21
|
end
|
22
|
+
|
23
|
+
def from_names(section, names)
|
24
|
+
components.clear
|
25
|
+
names.each do |name|
|
26
|
+
components << new(
|
27
|
+
headline: name.to_s.humanize,
|
28
|
+
partial_path: File.join('components', section, "#{name}"))
|
29
|
+
end
|
30
|
+
components
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
<nav class="__component_index">
|
3
3
|
<h3>Components</h3>
|
4
4
|
<ul>
|
5
|
-
<% Styleus::Component.
|
6
|
-
<li><%= link_to
|
5
|
+
<% Styleus::Component.sections.each do |section, components| %>
|
6
|
+
<li><%= link_to section.to_s.camelcase, send(:"#{section.to_s.pluralize}_path") %></li>
|
7
7
|
<% end %>
|
8
8
|
</ul>
|
9
9
|
</nav>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<li><%= link_to t('icons.html'), component_path(component),
|
4
4
|
title: t('links.titles.html'), class: 'icon', data: { toggle: "##{component.id} [data-subject=html-representation]" } %></li>
|
5
5
|
|
6
|
-
<% if
|
6
|
+
<% if helper %>
|
7
7
|
<li><%= link_to t('icons.helper'), component_path(component),
|
8
8
|
title: t('links.titles.helper'), class: 'icon', data: { toggle: "##{component.id} [data-subject=ruby-representation]" } %></li>
|
9
9
|
<% end %>
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<% end %>
|
6
6
|
|
7
7
|
<section class="__code_partials">
|
8
|
-
<%= _option_bar(component) %>
|
8
|
+
<%= _option_bar(component, content_for?(:helper)) %>
|
9
9
|
<%= _styleus_component_wrap(partial_path: component.partial_path) { content_for(:representation).html_safe } %>
|
10
10
|
<%= content_for(:html).html_safe %>
|
11
11
|
<%= content_for(:helper).html_safe %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# We preload the models here, to let their component registration take effect
|
2
|
+
# on the routes builded by their categories later.
|
3
|
+
|
4
|
+
# TODO: to be discussed, how to handle this better.
|
5
|
+
# this active code can break applications, if their libraries depend on later initializers.
|
6
|
+
# after_initialization before routing would be the best.
|
7
|
+
|
8
|
+
Rails.configuration.after_initialize do
|
9
|
+
model_path = Rails.root.join 'app/models'
|
10
|
+
|
11
|
+
Dir.open(model_path).each do |file_handler|
|
12
|
+
file_path = model_path.join(file_handler)
|
13
|
+
require file_path if File.file?(file_path) && file_handler =~ /.*\.rb/
|
14
|
+
end
|
15
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
resources :components, only: [:index, :show] do
|
3
3
|
collection do
|
4
|
-
Styleus::
|
5
|
-
|
4
|
+
Styleus::Component.sections.each do |section, _|
|
5
|
+
section_route = section.to_s.pluralize
|
6
|
+
resources section_route, only: [:index, :show], controller: :components, components: section_route
|
6
7
|
end
|
7
8
|
end
|
8
9
|
end
|
data/lib/styleus.rb
CHANGED
data/lib/styleus/engine.rb
CHANGED
data/lib/styleus/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.11
|
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-12-
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -120,11 +120,10 @@ files:
|
|
120
120
|
- app/views/styleus/_screen_size_viewer.html.erb
|
121
121
|
- app/views/styleus/_styleus_partials.html.erb
|
122
122
|
- config/initializers/01_styleus_config.rb
|
123
|
-
- config/initializers/
|
123
|
+
- config/initializers/zz_preload_models.rb
|
124
124
|
- config/locales/en.yml
|
125
125
|
- config/routes.rb
|
126
126
|
- lib/styleus/engine.rb
|
127
|
-
- lib/styleus/spacable.rb
|
128
127
|
- lib/styleus/version.rb
|
129
128
|
- lib/styleus.rb
|
130
129
|
- MIT-LICENSE
|
@@ -150,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
149
|
version: '0'
|
151
150
|
requirements: []
|
152
151
|
rubyforge_project:
|
153
|
-
rubygems_version: 1.8.
|
152
|
+
rubygems_version: 1.8.23
|
154
153
|
signing_key:
|
155
154
|
specification_version: 3
|
156
155
|
summary: Styleguide Support Tool
|
@@ -1 +0,0 @@
|
|
1
|
-
Styleus::COMPONENT_SPACES = Styleus::Component.spaces || []
|
data/lib/styleus/spacable.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Styleus
|
2
|
-
module Spacable
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
module ClassMethods
|
6
|
-
def spaces(*collection)
|
7
|
-
@spaces ||= []
|
8
|
-
return @spaces if collection.empty?
|
9
|
-
@spaces.concat(collection).uniq! if collection.respond_to? :to_ary
|
10
|
-
@spaces
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|