actioncomponent 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate +23 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +21 -0
- data/.rubocop_todo.yml +0 -0
- data/.travis.yml +26 -0
- data/.yardopts +3 -0
- data/Gemfile +6 -0
- data/README.md +262 -0
- data/actioncomponent.gemspec +33 -0
- data/lib/actioncomponent/component/renderer.rb +24 -0
- data/lib/actioncomponent/component/view_model.rb +22 -0
- data/lib/actioncomponent/component.rb +81 -0
- data/lib/actioncomponent/importer_helper.rb +25 -0
- data/lib/actioncomponent/railtie.rb +11 -0
- data/lib/actioncomponent.rb +30 -0
- metadata +213 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 76be070b5053ecc8da9c380f2e13946d9955b2dd3eeaa76f08d3dfe48031ea80
|
4
|
+
data.tar.gz: 48545e6160b1667d4af0fa0686bb60bb11130ee67d67a46686d1988ef25c7242
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d04b7b700b5cb1a6fae38baa9a7bcaa5e4a7f1b65690de597ab599c8b3e514122f83830f0bc41bd985c7fea459e59f010e6b2a571bdcf4e935d155c03fb7ca29
|
7
|
+
data.tar.gz: 4b7a9dbc8c5f30951c1c1d2bd110cb277d291f591dc46dad8704f35c36b7f09f8d067e10b7fcd9ace15b441d45a42958ed4b3683c81d4781f2384fd8f4b12680
|
data/.codeclimate
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
engines:
|
2
|
+
rubocop:
|
3
|
+
enabled: true
|
4
|
+
#checks:
|
5
|
+
# Rubocop/Metrics/ClassLength:
|
6
|
+
# enabled: false
|
7
|
+
brakeman:
|
8
|
+
enabled: false
|
9
|
+
eslint:
|
10
|
+
enabled: false
|
11
|
+
csslint:
|
12
|
+
enabled: false
|
13
|
+
duplication:
|
14
|
+
enabled: true
|
15
|
+
config:
|
16
|
+
languages:
|
17
|
+
- ruby:
|
18
|
+
- javascript:
|
19
|
+
ratings:
|
20
|
+
paths:
|
21
|
+
- lib/**
|
22
|
+
exclude_paths:
|
23
|
+
- spec/**/*
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Documentation:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
Style/ClassAndModuleChildren:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/FrozenStringLiteralComment:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Metrics/LineLength:
|
13
|
+
Max: 150
|
14
|
+
IgnoredPatterns: ['\A#']
|
15
|
+
|
16
|
+
AllCops:
|
17
|
+
Exclude:
|
18
|
+
- actioncomponent.gemspec
|
19
|
+
- 'exe/**/*'
|
20
|
+
- 'bin/**/*'
|
21
|
+
- 'spec/**/*'
|
data/.rubocop_todo.yml
ADDED
File without changes
|
data/.travis.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=3155042648b3cc74c8af8a1713df60818092046d8b395fdf29b4b1c00db7c792
|
4
|
+
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
|
5
|
+
|
6
|
+
language: ruby
|
7
|
+
|
8
|
+
cache:
|
9
|
+
bundler: true
|
10
|
+
|
11
|
+
rvm:
|
12
|
+
- "2.4.1"
|
13
|
+
|
14
|
+
bundler_args: "--binstubs --standalone --without documentation --path ../bundle"
|
15
|
+
|
16
|
+
before_script:
|
17
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
18
|
+
- chmod +x ./cc-test-reporter
|
19
|
+
|
20
|
+
script:
|
21
|
+
- bundle exec rubocop -c .rubocop.yml
|
22
|
+
- bundle exec rspec
|
23
|
+
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
|
24
|
+
|
25
|
+
notifications:
|
26
|
+
email: false
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
# Welcome to actioncomponent gem
|
2
|
+
|
3
|
+
[![Travis](https://travis-ci.org/viniciusoyama/action_component.svg?branch=master)](https://travis-ci.org/viniciusoyama/action_component)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/viniciusoyama/action_component/badges/gpa.svg)](https://codeclimate.com/github/viniciusoyama/action_component)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/viniciusoyama/action_component/badges/coverage.svg)](https://codeclimate.com/github/viniciusoyama/action_component)
|
6
|
+
|
7
|
+
Frontend components for Ruby on Rails: group your view logic, html, css and javascript files in components to be used in views or directly rendered from controllers.
|
8
|
+
|
9
|
+
# How to use?
|
10
|
+
|
11
|
+
**Gemfile**
|
12
|
+
```ruby
|
13
|
+
gem 'actioncomponent'
|
14
|
+
```
|
15
|
+
|
16
|
+
# What do you get?
|
17
|
+
|
18
|
+
## Organize your frontend code
|
19
|
+
Your can group your frontend stuff by domain and organize the UI of your Rails app like this:
|
20
|
+
|
21
|
+
```
|
22
|
+
app
|
23
|
+
├── components
|
24
|
+
│ └── user
|
25
|
+
│ └── filter
|
26
|
+
│ └── template.html.erb
|
27
|
+
│ └── list
|
28
|
+
│ └── template.html.erb
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
And, in your views, or in your components, your can render it!
|
33
|
+
|
34
|
+
**app/view/users/index.html.erb**
|
35
|
+
|
36
|
+
```html
|
37
|
+
<%
|
38
|
+
import_action_component 'Filter', path: 'user/filter'
|
39
|
+
import_action_component 'List', path: 'user/list'
|
40
|
+
%>
|
41
|
+
|
42
|
+
<%= Filter() %>
|
43
|
+
|
44
|
+
<%= List(users: @users) %>
|
45
|
+
```
|
46
|
+
|
47
|
+
Or, you can completely drop your view and tell your controller to render a User Index Compoment
|
48
|
+
|
49
|
+
```
|
50
|
+
app
|
51
|
+
├── components
|
52
|
+
│ └── user
|
53
|
+
│ └── filter
|
54
|
+
│ └── template.html.erb
|
55
|
+
│ └── list
|
56
|
+
│ └── template.html.erb
|
57
|
+
│ └── index
|
58
|
+
│ └── template.html.erb
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
**app/components/user/index/template.html.erb**
|
63
|
+
|
64
|
+
```html
|
65
|
+
<%
|
66
|
+
import_action_component 'Filter', path: 'user/filter'
|
67
|
+
import_action_component 'List', path: 'user/list'
|
68
|
+
%>
|
69
|
+
|
70
|
+
<%= Filter() %>
|
71
|
+
|
72
|
+
<%= List(users: @users) %>
|
73
|
+
```
|
74
|
+
|
75
|
+
**app/controllers/users_controller.rb**
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
|
79
|
+
# ...
|
80
|
+
# TODO
|
81
|
+
# ...
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
## Pass data to your components
|
86
|
+
|
87
|
+
When rendering your can pass data in a hash/named parameters format. The data will be exposed in your template through a view model.
|
88
|
+
|
89
|
+
Supose that you have a header component
|
90
|
+
|
91
|
+
```
|
92
|
+
app
|
93
|
+
├── components
|
94
|
+
│ └── header
|
95
|
+
│ └── template.html.erb
|
96
|
+
```
|
97
|
+
|
98
|
+
And you want to render this component in your layout file.
|
99
|
+
|
100
|
+
**app/views/layouts/application.html.erb**
|
101
|
+
|
102
|
+
```html
|
103
|
+
|
104
|
+
<%
|
105
|
+
import_action_component 'Header', path: 'header'
|
106
|
+
%>
|
107
|
+
|
108
|
+
<%= Header(my_user: current_user) %>
|
109
|
+
```
|
110
|
+
|
111
|
+
You can access the user attribute in your template like this:
|
112
|
+
|
113
|
+
**app/components/header/template.html.erb**
|
114
|
+
|
115
|
+
```html
|
116
|
+
<header>
|
117
|
+
Hi, <%= my_user.name %>
|
118
|
+
</header>
|
119
|
+
```
|
120
|
+
|
121
|
+
## View Models
|
122
|
+
|
123
|
+
The methods available inside the template will be those defined in your view model. If no view model is defined for your component then our ActionComponent::Component::ViewModel will be used. The view model is instantiated with the arguments that you provide when calling your component.
|
124
|
+
|
125
|
+
### ActionComponent::Component::ViewModel
|
126
|
+
|
127
|
+
It takes all the constructor arguments (it must be a hash/named args) and creates a getter for each one of them. Example:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
vm = ActionComponent::Component::ViewModel.new(name: 'John', age: 12)
|
131
|
+
vm.name # John
|
132
|
+
vm.age # 12
|
133
|
+
```
|
134
|
+
|
135
|
+
### Create your own ViewModel: handle complex view logic
|
136
|
+
|
137
|
+
We only use our own view model if there is no view_model.rb file inside your component's folder. This file should declare a class following all the Rails naming conventions.
|
138
|
+
|
139
|
+
So, imagine that we want our vm to have a random_greeting method. We can can create a view model like this:
|
140
|
+
|
141
|
+
|
142
|
+
## Use helpers inside your components
|
143
|
+
|
144
|
+
When initializing the view model we also provide two additionals parameters (:h and :helper) so you can have access to rails helpers.
|
145
|
+
|
146
|
+
As all view model methods are available to your template your will have access to a `h` or `helper` like this:
|
147
|
+
|
148
|
+
**Example of a component's templatefile**
|
149
|
+
|
150
|
+
```
|
151
|
+
<div class="child">
|
152
|
+
<div class="date">
|
153
|
+
<%= helper.l(Date.new(2019, 01, 03)) %>
|
154
|
+
</div>
|
155
|
+
|
156
|
+
<div class="routes">
|
157
|
+
<%= h.users_path %>
|
158
|
+
</div>
|
159
|
+
|
160
|
+
<div class="translation">
|
161
|
+
<%= h.t('hello')%>
|
162
|
+
</div>
|
163
|
+
</div>
|
164
|
+
```
|
165
|
+
|
166
|
+
Your can create custom view models that inherits from ours
|
167
|
+
|
168
|
+
**app/components/header/view_model.rb**
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
class Header::ViewModel < ActionComponent::Component::ViewModel
|
172
|
+
def random_greeting
|
173
|
+
hi_text = ['Hi', 'Yo'].sample
|
174
|
+
"#{hi_text}, #{user.name}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
```
|
178
|
+
|
179
|
+
Now the template can access the method like this:
|
180
|
+
|
181
|
+
**app/components/header/template.html.erb**
|
182
|
+
```html
|
183
|
+
<header>
|
184
|
+
<%= random_greeting %>
|
185
|
+
</header>
|
186
|
+
```
|
187
|
+
|
188
|
+
### Use helpers inside a ViewModel
|
189
|
+
|
190
|
+
A `helper` and `h` attribute are passed when instantiating a ViewModel.
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
class Header::ViewModel < ActionComponent::Component::ViewModel
|
194
|
+
def random_greeting
|
195
|
+
hi_text = ['Hi', 'Yo'].sample
|
196
|
+
"#{hi_text}, #{user.name}."
|
197
|
+
end
|
198
|
+
|
199
|
+
def formated_date
|
200
|
+
h.l(Date.today)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
```
|
204
|
+
|
205
|
+
**app/components/header/template.html.erb**
|
206
|
+
```html
|
207
|
+
<header>
|
208
|
+
<%= random_greeting %> Today is <%= formated_date %>
|
209
|
+
</header>
|
210
|
+
```
|
211
|
+
|
212
|
+
|
213
|
+
## Access your controller in your VM or Template
|
214
|
+
|
215
|
+
When rendering a component, a `c` or `controller` parameter is passed through so you can have access to all your request data inside your VM or template.
|
216
|
+
|
217
|
+
**view_model**
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
class ControllerData::ViewModel < ActionComponent::Component::ViewModel
|
221
|
+
|
222
|
+
def formated_page
|
223
|
+
"Current page: #{c.params[:page]}"
|
224
|
+
end
|
225
|
+
|
226
|
+
def formated_search
|
227
|
+
"Searching for: #{controller.params[:search]}"
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
```
|
232
|
+
|
233
|
+
**template.erb**
|
234
|
+
|
235
|
+
```html
|
236
|
+
<%= formated_search %>
|
237
|
+
|
238
|
+
<%= formated_page %>
|
239
|
+
```
|
240
|
+
|
241
|
+
|
242
|
+
# Configuration
|
243
|
+
|
244
|
+
You can change some parameters by creating a initializer on your app
|
245
|
+
|
246
|
+
**config/initializers/action_component.rb**
|
247
|
+
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
|
251
|
+
ActionComponent.configure do |config|
|
252
|
+
# Folder path to look for components
|
253
|
+
config.components_path = 'app/components'
|
254
|
+
|
255
|
+
# Default name for the html/erb/slim/etc template file inside the component folder
|
256
|
+
config.template_file_name = 'template'
|
257
|
+
|
258
|
+
# Default name for the view model file inside the component folder
|
259
|
+
config.view_model_file_name = 'view_model'
|
260
|
+
end
|
261
|
+
|
262
|
+
```
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'actioncomponent'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.date = '2019-03-21'
|
5
|
+
s.summary = 'Stop using views: frontend components architecture for Ruby on Rails'
|
6
|
+
s.description = 'Stop using views: frontend components architecture for Ruby on Rails'
|
7
|
+
s.authors = ['Vinícius Oyama']
|
8
|
+
s.email = 'contact@viniciusoyama.com'
|
9
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
10
|
+
s.homepage =
|
11
|
+
'http://rubygems.org/gems/actioncomponent'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
14
|
+
|
15
|
+
s.add_dependency 'rails', '>= 4.0.0'
|
16
|
+
|
17
|
+
# Quality Control
|
18
|
+
s.add_development_dependency 'rspec'
|
19
|
+
s.add_development_dependency 'rubocop'
|
20
|
+
s.add_development_dependency 'simplecov'
|
21
|
+
|
22
|
+
# Debugging
|
23
|
+
s.add_development_dependency 'awesome_print'
|
24
|
+
s.add_development_dependency 'pry-byebug'
|
25
|
+
|
26
|
+
# for testing a gem with a rails app (controller specs)
|
27
|
+
# https://codingdaily.wordpress.com/2011/01/14/test-a-gem-with-the-rails-3-stack/
|
28
|
+
s.add_development_dependency 'bundler'
|
29
|
+
s.add_development_dependency 'capybara'
|
30
|
+
s.add_development_dependency 'rails', '> 4.0'
|
31
|
+
s.add_development_dependency 'rspec-rails'
|
32
|
+
s.add_development_dependency 'sqlite3'
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActionComponent
|
2
|
+
# Renders a given component
|
3
|
+
class Component
|
4
|
+
class Renderer < ActionView::Renderer
|
5
|
+
class ComponentTemplateFileNotFound < StandardError; end
|
6
|
+
|
7
|
+
attr_reader :view_model
|
8
|
+
|
9
|
+
def initialize(lookup_context, view_model)
|
10
|
+
@lookup_context = lookup_context
|
11
|
+
@view_model = view_model
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(component_path:)
|
15
|
+
file_path = template_path_from_component_path(component_path)
|
16
|
+
super(view_model, file: file_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def template_path_from_component_path(component_path, template_file_name: ActionComponent.configuration.template_file_name)
|
20
|
+
File.join(component_path, template_file_name).to_s
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActionComponent
|
2
|
+
# Renders a given component
|
3
|
+
class Component
|
4
|
+
class ViewModel
|
5
|
+
include ActionComponent::ImporterHelper
|
6
|
+
|
7
|
+
def initialize(**args)
|
8
|
+
generate_methods_from_hash(args)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def generate_methods_from_hash(hash)
|
14
|
+
hash.each do |key, val|
|
15
|
+
define_singleton_method key.to_sym do
|
16
|
+
val
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module ActionComponent
|
2
|
+
# Represents a component with a template, style and javascript file
|
3
|
+
class Component
|
4
|
+
class InvalidVMError < StandardError; end
|
5
|
+
class << self
|
6
|
+
def helper_object
|
7
|
+
@helper_object = Class.new(ActionView::Base) do
|
8
|
+
include ::Rails.application.routes.url_helpers
|
9
|
+
include ::Rails.application.routes.mounted_helpers
|
10
|
+
end.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def helper_vm_params
|
14
|
+
{
|
15
|
+
h: helper_object,
|
16
|
+
helper: helper_object
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :view_model_data, :component_path
|
22
|
+
|
23
|
+
def initialize(component_path:, lookup_context: nil, view_model_data: {})
|
24
|
+
@component_path = component_path.to_s.gsub(%r{^/}, '')
|
25
|
+
@lookup_context = lookup_context
|
26
|
+
@view_model_data = view_model_data
|
27
|
+
end
|
28
|
+
|
29
|
+
def render
|
30
|
+
renderer.render(component_path: @component_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def renderer
|
34
|
+
ActionComponent::Component::Renderer.new(lookup_context, create_view_model)
|
35
|
+
end
|
36
|
+
|
37
|
+
def lookup_context
|
38
|
+
@lookup_context ||= ActionView::LookupContext.new(
|
39
|
+
[
|
40
|
+
full_component_path
|
41
|
+
]
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_view_model
|
46
|
+
vm_class = ActionComponent::Component::ViewModel
|
47
|
+
|
48
|
+
begin
|
49
|
+
vm_class = find_custom_vm_class!
|
50
|
+
rescue NameError
|
51
|
+
vm_class = ActionComponent::Component::ViewModel
|
52
|
+
end
|
53
|
+
|
54
|
+
vm_class.new(**view_model_data.merge(view_model_default_data))
|
55
|
+
end
|
56
|
+
|
57
|
+
def view_model_default_data
|
58
|
+
# lookup_context is necessary for when there is an exception in our template
|
59
|
+
# this is used in order to better describe the error stack
|
60
|
+
self.class.helper_vm_params.merge(lookup_context: lookup_context)
|
61
|
+
end
|
62
|
+
|
63
|
+
def full_component_path
|
64
|
+
Rails.root.join(ActionComponent.configuration.components_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def find_custom_vm_class!
|
70
|
+
vm_file_path = Pathname.new(component_path).join(ActionComponent.configuration.view_model_file_name)
|
71
|
+
vm_class = ActiveSupport::Inflector.camelize(vm_file_path).constantize
|
72
|
+
|
73
|
+
unless vm_class.ancestors.include?(ActionComponent::Component::ViewModel)
|
74
|
+
error_msg = "#{vm_class} cannot be used as a ViewModel. Make sure that it inherits from ActionComponent::Component::ViewModel."
|
75
|
+
raise ActionComponent::Component::InvalidVMError, error_msg
|
76
|
+
end
|
77
|
+
|
78
|
+
vm_class
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActionComponent
|
2
|
+
# Exposes component rendering methods to Rails views
|
3
|
+
|
4
|
+
module ImporterHelper
|
5
|
+
# Description of #import_action_component
|
6
|
+
#
|
7
|
+
# @param local_component_name [String] Local's component name (in the view scope)
|
8
|
+
# @param opts [Hash] default: {} Options.
|
9
|
+
# @example
|
10
|
+
def import_action_component(local_component_name, opts = {})
|
11
|
+
raise "No path informed when importing component #{local_component_name}" if opts[:path].blank?
|
12
|
+
|
13
|
+
define_singleton_method(local_component_name) do |**args|
|
14
|
+
create_component(opts[:path], args).render
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_component(component_path, view_model_data)
|
19
|
+
ActionComponent::Component.new(
|
20
|
+
component_path: component_path,
|
21
|
+
view_model_data: view_model_data.merge(c: controller, controller: controller)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
class ViewComponent
|
4
|
+
class Rails < Rails::Railtie
|
5
|
+
config.view_component = ActiveSupport::OrderedOptions.new
|
6
|
+
|
7
|
+
initializer 'view_component' do
|
8
|
+
::ActionView::Base.send(:include, ActionComponent::ImporterHelper)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'actioncomponent/importer_helper'
|
2
|
+
require 'actioncomponent/component'
|
3
|
+
require 'actioncomponent/component/view_model'
|
4
|
+
require 'actioncomponent/component/renderer'
|
5
|
+
require 'actioncomponent/railtie'
|
6
|
+
|
7
|
+
module ActionComponent
|
8
|
+
# Configuration class for ActionComponent
|
9
|
+
# @attr components_path [String] Components folder path (defaults to 'app/components')
|
10
|
+
# @attr components_path [String] Component's template file name (defaults to 'template')
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :components_path
|
13
|
+
attr_accessor :template_file_name
|
14
|
+
attr_accessor :view_model_file_name
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@components_path = 'app/components'
|
18
|
+
@template_file_name = 'template'
|
19
|
+
@view_model_file_name = 'view_model'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configuration
|
24
|
+
@configuration ||= Configuration.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.configure
|
28
|
+
yield(configuration)
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actioncomponent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vinícius Oyama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
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: simplecov
|
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: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: capybara
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rails
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '4.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '4.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec-rails
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sqlite3
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: 'Stop using views: frontend components architecture for Ruby on Rails'
|
168
|
+
email: contact@viniciusoyama.com
|
169
|
+
executables: []
|
170
|
+
extensions: []
|
171
|
+
extra_rdoc_files: []
|
172
|
+
files:
|
173
|
+
- ".codeclimate"
|
174
|
+
- ".gitignore"
|
175
|
+
- ".rspec"
|
176
|
+
- ".rubocop.yml"
|
177
|
+
- ".rubocop_todo.yml"
|
178
|
+
- ".travis.yml"
|
179
|
+
- ".yardopts"
|
180
|
+
- Gemfile
|
181
|
+
- README.md
|
182
|
+
- actioncomponent.gemspec
|
183
|
+
- lib/actioncomponent.rb
|
184
|
+
- lib/actioncomponent/component.rb
|
185
|
+
- lib/actioncomponent/component/renderer.rb
|
186
|
+
- lib/actioncomponent/component/view_model.rb
|
187
|
+
- lib/actioncomponent/importer_helper.rb
|
188
|
+
- lib/actioncomponent/railtie.rb
|
189
|
+
homepage: http://rubygems.org/gems/actioncomponent
|
190
|
+
licenses:
|
191
|
+
- MIT
|
192
|
+
metadata: {}
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 2.7.8
|
210
|
+
signing_key:
|
211
|
+
specification_version: 4
|
212
|
+
summary: 'Stop using views: frontend components architecture for Ruby on Rails'
|
213
|
+
test_files: []
|