komponent 1.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/komponent.gemspec +26 -0
- data/lib/generators/component/USAGE +12 -0
- data/lib/generators/component/component_generator.rb +37 -0
- data/lib/generators/component/templates/css.erb +1 -0
- data/lib/generators/component/templates/js.erb +1 -0
- data/lib/generators/component/templates/rb.erb +3 -0
- data/lib/generators/component/templates/view.html.slim.erb +1 -0
- data/lib/komponent.rb +5 -0
- data/lib/komponent/core/component_helper.rb +11 -0
- data/lib/komponent/komponent_helper.rb +44 -0
- data/lib/komponent/railtie.rb +18 -0
- data/lib/komponent/version.rb +3 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 49bd1e590f8faf9b5eb6a2ca87b556144bf0333d
|
4
|
+
data.tar.gz: aff68306564d0e94d963e1de3fb28f13d33f714e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e37992a8d7e267a8d056db03e77dd3a23f8e8e6b7e2a3b96a32d950e2370e646e889ba5e982f736938b7ed481fba4d34aa299eb262b507033f2f8792b9b7ec52
|
7
|
+
data.tar.gz: 753ce8aba84b0410f406ac691a7294b7f0e4badad58b67907ac31811ab40329ffd3212506546cc84a4fb16c760e1ad944e6f141c7a457d023fb95e0205b8071f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ouvrages
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Komponent
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
gem 'komponent'
|
7
|
+
```
|
8
|
+
|
9
|
+
Modify your webpacker config to:
|
10
|
+
|
11
|
+
```
|
12
|
+
# config/webpacker.yml
|
13
|
+
source_path: frontend
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Generate new component with `component` generator:
|
19
|
+
|
20
|
+
`rails generate component button`
|
21
|
+
|
22
|
+
And use it in your views with helper. You can pass `locals`, or `block` to component helper.
|
23
|
+
|
24
|
+
`= component('button')`
|
25
|
+
|
26
|
+
Locals passed in to component are accessible as instance variables.
|
27
|
+
|
28
|
+
```
|
29
|
+
= component('button', color: :red)
|
30
|
+
|
31
|
+
.button
|
32
|
+
= @color
|
33
|
+
```
|
34
|
+
|
35
|
+
You can define custom helpers in `ButtonComponent`:
|
36
|
+
|
37
|
+
```
|
38
|
+
class ButtonComponent
|
39
|
+
def bar
|
40
|
+
"foo"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
.button
|
45
|
+
= bar
|
46
|
+
```
|
47
|
+
|
48
|
+
You can set properties in `ButtonComponent` too:
|
49
|
+
|
50
|
+
```
|
51
|
+
class ButtonComponent
|
52
|
+
property :foo, default: "bar", required: true
|
53
|
+
end
|
54
|
+
|
55
|
+
.button
|
56
|
+
= @foo
|
57
|
+
```
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ouvrages/komponent.
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "komponent"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/komponent.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "komponent/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "komponent"
|
8
|
+
spec.version = Komponent::VERSION
|
9
|
+
spec.authors = ["Ouvrages"]
|
10
|
+
spec.email = ["contact@ouvrages-web.fr"]
|
11
|
+
|
12
|
+
spec.summary = ""
|
13
|
+
spec.description = ""
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Description:
|
2
|
+
Generates all files needed for a component
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate component button
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
frontend/components/button
|
9
|
+
frontend/components/button/_button.html.slim
|
10
|
+
frontend/components/button/button.js
|
11
|
+
frontend/components/button/button.css
|
12
|
+
frontend/components/button/button_component.rb
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class ComponentGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
argument :component, required: true, desc: "Component name, e.g: button"
|
5
|
+
|
6
|
+
def create_view_file
|
7
|
+
template "view.html.slim.erb", component_path + "_#{component}.html.slim"
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_css_file
|
11
|
+
template "css.erb", component_path + "#{component}.css"
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_js_file
|
15
|
+
template "js.erb", component_path + "#{component}.js"
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_rb_file
|
19
|
+
template "rb.erb", component_path + "#{component}_component.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
def append_frontend_packs
|
23
|
+
append_to_file "frontend/components/index.js" do
|
24
|
+
"import \"components/#{component}/#{component}\";"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def component_path
|
31
|
+
"frontend/components/#{component}/"
|
32
|
+
end
|
33
|
+
|
34
|
+
def module_name
|
35
|
+
"#{component}_component".camelize
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
.<%= component %> {}
|
@@ -0,0 +1 @@
|
|
1
|
+
import "./<%= component %>.css";
|
@@ -0,0 +1 @@
|
|
1
|
+
.<%= component %> <%= component %>
|
data/lib/komponent.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module KomponentHelper
|
2
|
+
def component(component, locals = {}, &block)
|
3
|
+
components_path = Rails.root.join("frontend", "components")
|
4
|
+
|
5
|
+
parts = component.split("/")
|
6
|
+
component_path = components_path.join(*parts)
|
7
|
+
component_name = parts.join("_")
|
8
|
+
component_path = component_path.join("#{component_name}_component")
|
9
|
+
require_dependency(component_path)
|
10
|
+
|
11
|
+
component_module = "#{component_name}_component".camelize.constantize
|
12
|
+
context = controller.view_context.dup
|
13
|
+
context.class_eval { prepend component_module }
|
14
|
+
capture_block = proc { capture(&block) } if block
|
15
|
+
|
16
|
+
context.instance_eval do
|
17
|
+
if component_module.respond_to?(:properties)
|
18
|
+
locals = locals.dup
|
19
|
+
component_module.properties.each do |name, options|
|
20
|
+
unless locals.has_key?(name)
|
21
|
+
if options.has_key?(:default)
|
22
|
+
locals[name] = options[:default]
|
23
|
+
elsif options[:required]
|
24
|
+
raise "Missing required component parameter: #{name}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
locals.each do |name, value|
|
31
|
+
instance_variable_set(:"@#{name}", locals[name] || options[:default])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
custom_method = :"render_#{component_name}"
|
36
|
+
if context.respond_to?(custom_method)
|
37
|
+
context.public_send(custom_method, locals, &capture_block)
|
38
|
+
else
|
39
|
+
context.render("components/#{component}/#{parts.last}", &capture_block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
alias :c :component
|
44
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'komponent/komponent_helper'
|
2
|
+
require 'komponent/core/component_helper'
|
3
|
+
|
4
|
+
module Komponent
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer "komponent.helper" do |app|
|
7
|
+
ActionView::Base.send :include, KomponentHelper
|
8
|
+
end
|
9
|
+
|
10
|
+
initializer "komponent.controller" do |app|
|
11
|
+
ActionController::Base.prepend_view_path "#{app.config.root}/frontend"
|
12
|
+
end
|
13
|
+
|
14
|
+
initializer 'komponent.autoload', before: :set_autoload_paths do |app|
|
15
|
+
app.config.autoload_paths << "#{app.config.root}/frontend"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: komponent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ouvrages
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- contact@ouvrages-web.fr
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- komponent.gemspec
|
56
|
+
- lib/generators/component/USAGE
|
57
|
+
- lib/generators/component/component_generator.rb
|
58
|
+
- lib/generators/component/templates/css.erb
|
59
|
+
- lib/generators/component/templates/js.erb
|
60
|
+
- lib/generators/component/templates/rb.erb
|
61
|
+
- lib/generators/component/templates/view.html.slim.erb
|
62
|
+
- lib/komponent.rb
|
63
|
+
- lib/komponent/core/component_helper.rb
|
64
|
+
- lib/komponent/komponent_helper.rb
|
65
|
+
- lib/komponent/railtie.rb
|
66
|
+
- lib/komponent/version.rb
|
67
|
+
homepage: ''
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.3.1
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.6.13
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: ''
|
91
|
+
test_files: []
|