komponent 1.0.0.pre.2 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/README.md +42 -2
- data/komponent.gemspec +4 -0
- data/lib/generators/component/component_generator.rb +46 -9
- data/lib/generators/component/templates/css.erb +1 -1
- data/lib/generators/component/templates/view.html.erb.erb +1 -1
- data/lib/generators/component/templates/view.html.haml.erb +1 -1
- data/lib/generators/component/templates/view.html.slim.erb +1 -1
- data/lib/komponent/komponent_helper.rb +24 -0
- data/lib/komponent/version.rb +1 -1
- data/logo.svg +1 -0
- metadata +48 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a99b2271c7cb864588a945d95ffe2bb96b1c29f8
|
4
|
+
data.tar.gz: 523d53f622f49450b839515dd34441087123d32c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c4501a2a63283281a76cf550c40e4544c6fe5d834c539bf3b6e88b1999a17917f6b13033cc86ee0c861e13204f296a6c22ea89ef724da4b67861728f721254e
|
7
|
+
data.tar.gz: 117abc530d8d1bdff4e68d63ebc43eae8eaf80babd0bc4778b91673c8edbf62c03f752410d37b545e9c49127c8741bd0d1d7c96969330a0d481d87090f98951e
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# Komponent
|
1
|
+
# <img alt="Komponent" src="https://raw.github.com/ouvrages/komponent/master/logo.svg?sanitize=true" width="200" height="40" />
|
2
|
+
[](https://travis-ci.org/komposable/komponent)
|
3
|
+
=======
|
2
4
|
|
3
5
|
**Komponent** implements an opinionated way of organizing front-end code in Ruby on Rails, based on _components_.
|
4
6
|
|
@@ -47,6 +49,8 @@ Then, render it in your views with the `component` helper (or its alias `c`).
|
|
47
49
|
= c "button"
|
48
50
|
```
|
49
51
|
|
52
|
+
### Passing variables
|
53
|
+
|
50
54
|
You can pass `locals` to the helper. They are accessible within the component partial, as instance variables.
|
51
55
|
|
52
56
|
```slim
|
@@ -62,6 +66,8 @@ You can pass `locals` to the helper. They are accessible within the component pa
|
|
62
66
|
= @text
|
63
67
|
```
|
64
68
|
|
69
|
+
### Passing a block
|
70
|
+
|
65
71
|
The component also accepts a `block`. To render the block, just use the standard `yield`.
|
66
72
|
|
67
73
|
```slim
|
@@ -78,6 +84,8 @@ The component also accepts a `block`. To render the block, just use the standard
|
|
78
84
|
= yield
|
79
85
|
```
|
80
86
|
|
87
|
+
### Properties
|
88
|
+
|
81
89
|
Each component comes with a Ruby `module`. You can use it to set properties:
|
82
90
|
|
83
91
|
```ruby
|
@@ -96,7 +104,9 @@ a.button(href=@href)
|
|
96
104
|
= @text
|
97
105
|
```
|
98
106
|
|
99
|
-
|
107
|
+
### Helpers
|
108
|
+
|
109
|
+
If your partial becomes too complex and you want to extract logic from it, you may want to define custom helpers in the `ButtonComponent` module:
|
100
110
|
|
101
111
|
```ruby
|
102
112
|
# frontend/components/button/button_component.rb
|
@@ -125,6 +135,36 @@ a.button(href=@href)
|
|
125
135
|
= component "button", text: "My button", href: "http://github.com"
|
126
136
|
```
|
127
137
|
|
138
|
+
### Component partials
|
139
|
+
|
140
|
+
You can also choose to split your component into partials. In this case, use the `render_partial` helper to render a partial, stored inside the component directory. It's a simple shorthand of the default `render` helper from Rails.
|
141
|
+
|
142
|
+
```slim
|
143
|
+
/ frontend/components/button/_button.html.slim
|
144
|
+
|
145
|
+
= a.button(href=@href)
|
146
|
+
= @text
|
147
|
+
/ The line below is similar to: render("components/button/suffix", text: "external link") if external_link?
|
148
|
+
= render_partial("suffix", text: "external link") if external_link?
|
149
|
+
```
|
150
|
+
|
151
|
+
```slim
|
152
|
+
/ frontend/components/button/_external_link.html.slim
|
153
|
+
|
154
|
+
= " (#{text})"
|
155
|
+
```
|
156
|
+
|
157
|
+
### Namespacing components
|
158
|
+
|
159
|
+
To organize different types of components, you can group them in namespaces when you use the generator:
|
160
|
+
|
161
|
+
```sh
|
162
|
+
rails generate component admin/header
|
163
|
+
```
|
164
|
+
|
165
|
+
This will create the component in an `admin` folder, and name its Ruby module `AdminHeaderComponent`.
|
166
|
+
|
167
|
+
|
128
168
|
## Contributing
|
129
169
|
|
130
170
|
Bug reports and pull requests are welcome on GitHub at https://github.com/ouvrages/komponent.
|
data/komponent.gemspec
CHANGED
@@ -23,4 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.15"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
|
27
|
+
spec.add_development_dependency "cucumber"
|
28
|
+
spec.add_development_dependency "aruba"
|
29
|
+
spec.add_development_dependency "rails", ">= 5.0"
|
26
30
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
class ComponentGenerator < Rails::Generators::
|
1
|
+
class ComponentGenerator < Rails::Generators::NamedBase
|
2
2
|
source_root File.expand_path('../templates', __FILE__)
|
3
3
|
|
4
|
-
argument :component, required: true, desc: "Component name, e.g: button"
|
5
4
|
class_option :locale, type: :boolean, default: false
|
6
5
|
|
7
6
|
def create_view_file
|
@@ -17,7 +16,7 @@ class ComponentGenerator < Rails::Generators::Base
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def create_rb_file
|
20
|
-
template "rb.erb", component_path + "#{
|
19
|
+
template "rb.erb", component_path + "#{module_name.underscore}.rb"
|
21
20
|
end
|
22
21
|
|
23
22
|
def create_locale_files
|
@@ -29,24 +28,62 @@ class ComponentGenerator < Rails::Generators::Base
|
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
31
|
+
def import_to_packs
|
32
|
+
root_path = Pathname.new("frontend")
|
33
|
+
base_path = root_path + "components"
|
34
|
+
|
35
|
+
imports = []
|
36
|
+
|
37
|
+
split_name[0..-2].each do |split|
|
38
|
+
base_path += split
|
39
|
+
file_path = base_path + "index.js"
|
40
|
+
create_file(file_path) unless File.exists?(file_path)
|
41
|
+
imports << base_path.relative_path_from(root_path)
|
35
42
|
end
|
43
|
+
|
44
|
+
root_path_dup = root_path.dup
|
45
|
+
|
46
|
+
[Pathname.new("components"), *split_name[0..-2]].each do |split|
|
47
|
+
root_path_dup += split
|
48
|
+
import = imports.shift
|
49
|
+
if import
|
50
|
+
append_to_file(root_path_dup + "index.js") do
|
51
|
+
"import \"#{import}\";\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
append_to_file(base_path + "index.js") do
|
57
|
+
"import \"#{base_path.relative_path_from(root_path)}/#{component_name}/#{component_name}\";\n"
|
58
|
+
end
|
36
59
|
end
|
37
60
|
|
38
61
|
protected
|
39
62
|
|
63
|
+
def split_name
|
64
|
+
name.split(/[:,::,\/]/).reject(&:blank?).map(&:underscore)
|
65
|
+
end
|
66
|
+
|
67
|
+
def name_with_namespace
|
68
|
+
split_name.join("_")
|
69
|
+
end
|
70
|
+
|
40
71
|
def component_path
|
41
|
-
"frontend
|
72
|
+
path_parts = ["frontend", "components", *split_name]
|
73
|
+
|
74
|
+
Pathname.new(path_parts.join("/"))
|
42
75
|
end
|
43
76
|
|
44
77
|
def module_name
|
45
|
-
"#{
|
78
|
+
"#{name_with_namespace}_component".camelize
|
79
|
+
end
|
80
|
+
|
81
|
+
def component_class_name
|
82
|
+
name_with_namespace.dasherize
|
46
83
|
end
|
47
84
|
|
48
85
|
def component_name
|
49
|
-
|
86
|
+
split_name.last.underscore
|
50
87
|
end
|
51
88
|
|
52
89
|
def template_engine
|
@@ -1 +1 @@
|
|
1
|
-
.<%=
|
1
|
+
.<%= component_class_name %> {}
|
@@ -1 +1 @@
|
|
1
|
-
.<%=
|
1
|
+
.<%= component_class_name %> <%= component_name %>
|
@@ -1 +1 @@
|
|
1
|
-
.<%=
|
1
|
+
.<%= component_class_name %> <%= component_name %>
|
@@ -41,4 +41,28 @@ module KomponentHelper
|
|
41
41
|
end
|
42
42
|
|
43
43
|
alias :c :component
|
44
|
+
|
45
|
+
def render_partial(partial_name, locals = {}, &block)
|
46
|
+
benchmark("Rendered partial #{partial_name}") do
|
47
|
+
context = controller.view_context
|
48
|
+
view_paths = context.lookup_context.view_paths.dup
|
49
|
+
components_path = Rails.root.join "frontend/components"
|
50
|
+
|
51
|
+
capture_block = proc { capture(&block) } if block
|
52
|
+
|
53
|
+
current_dir = Pathname.new(@virtual_path).dirname
|
54
|
+
|
55
|
+
context.lookup_context.prefixes.prepend current_dir
|
56
|
+
context.lookup_context.view_paths.unshift components_path
|
57
|
+
|
58
|
+
rendered_partial = capture do
|
59
|
+
context.render partial_name, locals, &capture_block
|
60
|
+
end
|
61
|
+
|
62
|
+
context.lookup_context.prefixes.delete current_dir
|
63
|
+
context.lookup_context.view_paths = view_paths
|
64
|
+
|
65
|
+
rendered_partial
|
66
|
+
end
|
67
|
+
end
|
44
68
|
end
|
data/lib/komponent/version.rb
CHANGED
data/logo.svg
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 198.64 37"><title>Komponent</title><g style="fill:#0038ea;"><path d="M48.58,9.89h3.88v8.33l7.35-8.33h4.74l-7.09,7.88,7.59,10.28H60.32l-5.58-7.51L52.46,23v5.07H48.58Z"/><path d="M66.05,21.21a7.47,7.47,0,0,1,14.92,0,7.47,7.47,0,0,1-14.92,0Zm11.24,0a3.77,3.77,0,1,0-3.75,3.91A3.86,3.86,0,0,0,77.29,21.21Z"/><path d="M104.9,19.35v8.73h-3.7V20a2.54,2.54,0,1,0-5.08-.22v8.28h-3.7V20a2.53,2.53,0,1,0-5-.22v8.25H83.51V14.38h3.86v1.8a4,4,0,0,1,3.7-2.11,4.87,4.87,0,0,1,4.34,2.48,4.74,4.74,0,0,1,4.44-2.48A5,5,0,0,1,104.9,19.35Z"/><path d="M122.88,21.21c0,4.2-2.64,7.16-6.29,7.16A5.58,5.58,0,0,1,112,26.12V32.6h-3.86V14.38H112v1.91a5.64,5.64,0,0,1,4.58-2.22C120.24,14.07,122.88,17,122.88,21.21Zm-3.75,0a3.62,3.62,0,0,0-3.65-3.89A3.49,3.49,0,0,0,112,20.68v1.05a3.5,3.5,0,0,0,3.47,3.39A3.63,3.63,0,0,0,119.13,21.21Z"/><path d="M124.84,21.21a7.46,7.46,0,0,1,14.91,0,7.46,7.46,0,0,1-14.91,0Zm11.24,0a3.77,3.77,0,1,0-3.76,3.91A3.87,3.87,0,0,0,136.08,21.21Z"/><path d="M155.35,19.35v8.7h-3.73V20.17A2.6,2.6,0,0,0,149,17.32,2.71,2.71,0,0,0,146.18,20l0-.08v8.17h-3.86V14.38h3.86V16.1a4.87,4.87,0,0,1,4.13-2A5,5,0,0,1,155.35,19.35Z"/><path d="M168.2,23.74l2.46,2.52a8.33,8.33,0,0,1-5.58,2.11,7,7,0,0,1-7.24-7.19,6.88,6.88,0,0,1,7-7.11c4.29,0,6.8,3.25,6.8,8.41H161.8A3.32,3.32,0,0,0,165.06,25,4.91,4.91,0,0,0,168.2,23.74Zm-6.34-4H168A2.86,2.86,0,0,0,165,17.48,3.29,3.29,0,0,0,161.86,19.7Z"/><path d="M187.27,19.35v8.7h-3.73V20.17A2.6,2.6,0,0,0,181,17.32,2.72,2.72,0,0,0,178.09,20l0-.08v8.17h-3.86V14.38h3.86V16.1a4.87,4.87,0,0,1,4.12-2A5,5,0,0,1,187.27,19.35Z"/><path d="M198.64,27.18a5,5,0,0,1-3.15,1.19,4,4,0,0,1-4.09-4.18V17.5h-1.88V14.38h1.88V10.63h3.7v3.75h3V17.5h-3v6.09a1.4,1.4,0,0,0,1.29,1.53,2,2,0,0,0,1.32-.45Z"/><rect y="12" width="20" height="12"/></g><g style="fill:#aaa;"><rect width="10" height="12"/><rect y="24" width="10" height="13"/><rect x="20" width="10" height="12"/><rect x="20" y="24" width="10" height="13"/></g></svg>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: komponent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ouvrages
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cucumber
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aruba
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
41
83
|
description: An opinionated way of organizing front-end code in Ruby on Rails, based
|
42
84
|
on components
|
43
85
|
email:
|
@@ -47,6 +89,7 @@ extensions: []
|
|
47
89
|
extra_rdoc_files: []
|
48
90
|
files:
|
49
91
|
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
50
93
|
- Gemfile
|
51
94
|
- LICENSE.txt
|
52
95
|
- README.md
|
@@ -69,6 +112,7 @@ files:
|
|
69
112
|
- lib/komponent/komponent_helper.rb
|
70
113
|
- lib/komponent/railtie.rb
|
71
114
|
- lib/komponent/version.rb
|
115
|
+
- logo.svg
|
72
116
|
homepage: http://komponent.io
|
73
117
|
licenses:
|
74
118
|
- MIT
|
@@ -84,9 +128,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
128
|
version: '0'
|
85
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
130
|
requirements:
|
87
|
-
- - "
|
131
|
+
- - ">="
|
88
132
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
133
|
+
version: '0'
|
90
134
|
requirements: []
|
91
135
|
rubyforge_project:
|
92
136
|
rubygems_version: 2.6.13
|