amber_component 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +2 -2
  3. data/Gemfile.lock +4 -4
  4. data/README.md +327 -4
  5. data/lib/amber_component/minitest_test_case.rb +10 -0
  6. data/lib/amber_component/test_helper.rb +34 -0
  7. data/lib/amber_component/version.rb +1 -1
  8. data/lib/generators/amber_component/install_generator.rb +20 -1
  9. data/lib/generators/amber_component/templates/application_component_test_case.rb +7 -0
  10. data/lib/generators/amber_component_generator.rb +56 -4
  11. data/lib/generators/component_generator.rb +9 -0
  12. data/lib/generators/templates/component.rb.erb +3 -1
  13. data/lib/generators/templates/component_test.rb.erb +11 -3
  14. data/lib/generators/templates/style.css.erb +1 -1
  15. data/lib/generators/templates/style.sass.erb +3 -0
  16. data/lib/generators/templates/style.scss.erb +5 -0
  17. data/lib/generators/templates/view.haml.erb +9 -0
  18. data/lib/generators/templates/view.html.erb.erb +8 -0
  19. data/lib/generators/templates/view.slim.erb +6 -0
  20. metadata +11 -31
  21. data/docs/.bundle/config +0 -2
  22. data/docs/.gitignore +0 -5
  23. data/docs/404.html +0 -25
  24. data/docs/Gemfile +0 -37
  25. data/docs/Gemfile.lock +0 -89
  26. data/docs/README.md +0 -19
  27. data/docs/_config.yml +0 -148
  28. data/docs/_data/amber_component.yml +0 -3
  29. data/docs/_sass/_variables.scss +0 -2
  30. data/docs/_sass/color_schemes/amber_component.scss +0 -11
  31. data/docs/_sass/custom/custom.scss +0 -60
  32. data/docs/api/index.md +0 -8
  33. data/docs/assets/images/logo_wide.png +0 -0
  34. data/docs/changelog/index.md +0 -8
  35. data/docs/favicon.ico +0 -0
  36. data/docs/getting_started/index.md +0 -8
  37. data/docs/getting_started/installation.md +0 -7
  38. data/docs/getting_started/ruby_support.md +0 -7
  39. data/docs/getting_started/wireframes.md +0 -7
  40. data/docs/index.md +0 -17
  41. data/docs/introduction/basic_usage.md +0 -7
  42. data/docs/introduction/index.md +0 -8
  43. data/docs/introduction/why_amber_component.md +0 -7
  44. data/docs/resources/index.md +0 -8
  45. data/docs/styles/index.md +0 -8
  46. data/docs/styles/usage.md +0 -7
  47. data/docs/views/index.md +0 -8
  48. data/docs/views/usage.md +0 -7
  49. data/lib/generators/templates/view.html.erb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45f702b26ec801eb7f67fa45e14c4fac035ff31d9ad6602418b7faa15c8e6004
4
- data.tar.gz: 404f922961c15d865144d8f284511f0b93718bc85f93a1fea1c1b013aa6d815f
3
+ metadata.gz: f1809ef804fefeb8ed7e05b8d1056895f7068663b92b74b464b99bb611981e7c
4
+ data.tar.gz: 7a05630fb2c74850241378c1b2e176373258b0e3a63aa7eae26803fc0a7077d5
5
5
  SHA512:
6
- metadata.gz: 17df8b345dade33fb27c5167b9ee7d17788b2092ecbff5aeb2f6fbeb12a6dd91813e7c2aa9c52b42aafea6e5965869630960b64c1d3da5be3365d4e3f8702148
7
- data.tar.gz: ec46b84d953e9efcc4ae0a36e68f0a733bfd8e76f518eee3cae2c33a655df3be9ec592b09cd8ade8b88707934e55004d03c62c2a48a2152690edd86910b4cd2e
6
+ metadata.gz: b554c4cbaafe3fd6e4cbebe34c4e99ea7d318e50aa38b599b87c35d72bf5a353e0099b0471d643543c6f6227275295f63c0f33432940d7d0de71b8ac29ddd488
7
+ data.tar.gz: 69ef4f133acd94753d9108b56ef44f601fd59435a53dadaf194905190f53db8dcc368dcd3c5da68cfcc027a8a27a4b6a33d99f40b3bb3985cf3c80ce9c79e8bc
data/CONTRIBUTING.md CHANGED
@@ -72,9 +72,9 @@ $ gem install ffi -- --with-cflags="-fdeclspec"
72
72
 
73
73
  > Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
74
74
  >
75
- > current directory: /Users/mateuszdrewniak/.rvm/gems/ruby-3.1.0@dupa/gems/puma-5.6.2/ext/puma_http11
75
+ > current directory: ~/.rvm/gems/ruby-3.1.0@dupa/gems/puma-5.6.2/ext/puma_http11
76
76
  >
77
- > /Users/mateuszdrewniak/.rvm/rubies/ruby-3.1.0/bin/ruby -I /Users/mateuszdrewniak/.rvm/rubies/ruby-3.1.0/lib/ruby/3.1.0 -r ./siteconf20220219-40641-4uxhq6.rb extconf.rb --with-cflags\=-Wno-error\=implicit-function-declaration
77
+ > ~/.rvm/rubies/ruby-3.1.0/bin/ruby -I ~/.rvm/rubies/ruby-3.1.0/lib/ruby/3.1.0 -r ./siteconf20220219-40641-4uxhq6.rb extconf.rb --with-cflags\=-Wno-error\=implicit-function-declaration
78
78
  >
79
79
  > checking for BIO_read() in -lcrypto... *** extconf.rb failed ***
80
80
  >
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- amber_component (0.0.4)
4
+ amber_component (0.0.5)
5
5
  actionview (>= 6)
6
6
  activemodel (>= 6)
7
7
  activesupport (>= 6)
@@ -67,10 +67,10 @@ GEM
67
67
  method_source (1.0.0)
68
68
  mini_portile2 (2.8.0)
69
69
  minitest (5.16.2)
70
- nokogiri (1.13.8)
70
+ nokogiri (1.13.9)
71
71
  mini_portile2 (~> 2.8.0)
72
72
  racc (~> 1.4)
73
- nokogiri (1.13.8-arm64-darwin)
73
+ nokogiri (1.13.9-arm64-darwin)
74
74
  racc (~> 1.4)
75
75
  parallel (1.22.1)
76
76
  parser (3.1.2.1)
@@ -172,4 +172,4 @@ DEPENDENCIES
172
172
  yard
173
173
 
174
174
  BUNDLED WITH
175
- 2.3.14
175
+ 2.3.7
data/README.md CHANGED
@@ -9,13 +9,13 @@
9
9
 
10
10
  # AmberComponent
11
11
 
12
- AmberComponent is a simple component library which seamlessly hooks into your Rails project and allows you to create simple backend components. They work like mini controllers which are bound with their view.
12
+ AmberComponent is a simple component library which seamlessly hooks into your Rails project and allows you to create simple backend components. They work like mini controllers which are bound with their view and stylesheet.
13
13
 
14
14
  Created by [Garbus Beach](https://github.com/garbusbeach) and [Mateusz Drewniak](https://github.com/Verseth).
15
15
 
16
16
  ## Getting started
17
17
 
18
- You can read a lot more about AmberComponent in its [official docs](https://ambercomponent.com).
18
+ You can read a lot more about AmberComponent in its [official docs](https://ambercomponent.com).
19
19
 
20
20
  ## Installation
21
21
 
@@ -27,14 +27,337 @@ If bundler is not being used to manage dependencies, install the gem by executin
27
27
 
28
28
  $ gem install amber_component
29
29
 
30
+ If you're using a Rails application there's an installation generator that you should run:
31
+
32
+ ```sh
33
+ $ bin/rails generate amber_component:install
34
+ ```
35
+
30
36
  ## Usage
31
37
 
32
- If you're using a Rails application there's an installation generator that you should run:
38
+ ## Components
39
+
40
+ Components are located under `app/components`.
41
+
42
+ Every component consists of:
43
+ - a Ruby file which defines its properties, encapsulates logic and may implement helper methods (like a controller)
44
+ - a view/template file (html.erb, haml, slim etc.)
45
+ - a style file (css, scss, sass etc.)
46
+
47
+ An individual component which implements a button may look like this.
48
+
49
+ ```ruby
50
+ # app/components/button_component.rb
51
+
52
+ class ButtonComponent < AmberComponent::Base
53
+ prop :label, required: true
54
+ end
55
+ ```
56
+
57
+ ```html
58
+ <!-- app/components/button_component/view.html.erb -->
59
+
60
+ <div class="button_component">
61
+ <%= label %>
62
+ </div>
63
+ ```
64
+
65
+ ```scss
66
+ // app/components/button_component/style.scss
67
+
68
+ .button_component {
69
+ background-color: indigo;
70
+ border-radius: 1rem;
71
+ transition-duration: 500ms;
72
+
73
+ &:hover {
74
+ background-color: blue;
75
+ }
76
+ }
77
+ ```
78
+
79
+ You can render this component in other components or in a Rails view.
80
+
81
+ ```html
82
+ <!-- app/controller/foo/index.html.erb -->
83
+
84
+ <h1>We're inside FooController</h1>
85
+
86
+ <!-- using a helper method -->
87
+ <%= button_component label: 'Click me!' %>
88
+ <!-- calling a method on the component class -->
89
+ <%= ButtonComponent.call label: 'Click me!' %>
90
+ ```
91
+
92
+ Or even directly in Ruby
93
+
94
+ ```ruby
95
+ # Calling a method on the component class. Outputs an HTML string.
96
+ ButtonComponent.call label: 'Click me!'
97
+ #=> '<div class="button_component">Click me!</div>'
98
+ ```
99
+
100
+ ### Rails helpers inside component templates
101
+
102
+ Component views/template files can make use
103
+ of all ActionView helpers and Rails route helpers.
104
+
105
+ This makes component views very flexible and convenient.
106
+
107
+ ```erb
108
+ <!-- app/components/login_form_component/view.html.erb -->
109
+
110
+ <%= form_with url: sign_up_path, class: "login_form_component" do |f| %>
111
+ <%= f.label :first_name %>
112
+ <%= f.text_field :first_name %>
113
+
114
+ <%= f.label :last_name %>
115
+ <%= f.text_field :last_name %>
116
+
117
+ <%= f.label :email, "Email Address" %>
118
+ <%= f.text_field :email %>
119
+
120
+ <%= f.label :password %>
121
+ <%= f.password_field :password %>
122
+
123
+ <%= f.label :password_confirmation, "Confirm Password" %>
124
+ <%= f.password_field :password_confirmation %>
125
+
126
+ <%= f.submit "Create account" %>
127
+ <% end %>
128
+ ```
129
+
130
+ ### Component properties
131
+
132
+ There is a neat prop DSL.
133
+
134
+ ```ruby
135
+ # app/components/comment_component.rb
136
+
137
+ class CommentComponent < ApplicationComponent
138
+ # will raise an error when not present
139
+ prop :body, required: true
140
+ # will raise an error when an object of a different
141
+ # class is received (uses `is_a?`)
142
+ prop :author, type: User, allow_nil: true
143
+ # the default value
144
+ prop :date, default: -> { DateTime.now }
145
+ end
146
+ ```
147
+
148
+ Props can be passed as keyword arguments
149
+ to the `::call` method of the component class
150
+ or the helper method.
151
+
152
+ ```ruby
153
+ CommentComponent.call body: 'Foo bar', author: User.first
154
+ # only in views and other components
155
+ comment_component body: 'Foo bar', author: User.first
156
+ ```
157
+
158
+ ### Overriding prop getters and setters
159
+
160
+ Getters and setters for properties are
161
+ defined in a module which means that you can override them and call them with `super`.
162
+
163
+ ```ruby
164
+ # app/components/priority_icon_component.rb
165
+
166
+ class PriorityIconComponent < ApplicationComponent
167
+ PriorityStruct = Struct.new :icon, :color
168
+
169
+ PRIORITY_MAP = {
170
+ low: PriorityStruct.new('fa-solid fa-chevrons-down', 'green'),
171
+ medium: PriorityStruct.new('fa-solid fa-chevron-up', 'yellow'),
172
+ high: PriorityStruct.new('fa-solid fa-chevrons-up', 'red')
173
+ }
174
+
175
+ prop :severity, default: -> { :low }
176
+
177
+ def severity=(val)
178
+ # super will call the original
179
+ # implementation of the setter
180
+ super(PRIORITY_MAP[val])
181
+ end
182
+ end
183
+ ```
184
+
185
+ ```html
186
+ <!-- app/components/priority_icon_component/view.html.erb -->
187
+
188
+ <i style="color: <%= severity&.color %>;" class="<%= severity&.icon %>"></i>
189
+ ```
190
+
191
+ ### Helper methods
192
+
193
+ Defining helper methods which are available
194
+ in the template is extremely easy.
195
+
196
+ Just define a method on the component class.
197
+
198
+ ```ruby
199
+ # app/components/comment_component.rb
200
+
201
+ class CommentComponent < ApplicationComponent
202
+ # you can also include helper modules
203
+ include SomeHelper
204
+
205
+ prop :body, required: true
206
+ prop :author, type: Author, allow_nil: true
207
+ prop :date, default: -> { DateTime.now }
208
+
209
+ private
210
+
211
+ def humanized_date
212
+ date.strftime '%Y-%m-%d %H:%M'
213
+ end
214
+
215
+ def author_name
216
+ author&.name || 'Unknown'
217
+ end
218
+
219
+ def author_avatar
220
+ author&.avatar_url || User.placeholder_avatar_url
221
+ end
222
+ end
223
+ ```
224
+
225
+ ```html
226
+ <!-- app/components/comment_component/view.html.erb -->
227
+
228
+ <div class="comment_component">
229
+ <div class="comment_header">
230
+ <img src="<%= author_avatar %>" alt="<%= author_name %> avatar">
231
+
232
+ <div><%= author_name %></div>
233
+ <div class="comment_date"><%= humanized_date %></div>
234
+ </div>
235
+
236
+ <div class="comment_content">
237
+ <%= body %>
238
+ </div>
239
+ </div>
240
+ ```
241
+
242
+ ### Nested components
243
+
244
+ It's possible to nest components or provide
245
+ custom HTML to a component.
246
+
247
+ This works similarly to React's `props.children`.
248
+
249
+ To render the passed nested content call `yield.html_safe` somewhere inside the template/view.
250
+
251
+ ```ruby
252
+ # app/components/modal_component.rb
253
+
254
+ class ModalComponent < ApplicationComponent
255
+ prop :id, required: true
256
+ prop :title, required: true
257
+ end
258
+ ```
259
+
260
+ ```html
261
+ <!-- app/components/modal/view.html.erb -->
262
+
263
+ <div id="<%= id %>" class="modal_component">
264
+ <div class="model_header">
265
+ <%= title %>
266
+ </div>
267
+
268
+ <div class="modal_body">
269
+ <!-- nested content will be rendered here -->
270
+ <%= yield.html_safe %>
271
+ </div>
272
+
273
+ <div class="modal_footer">
274
+ <div class="modal_close_button"></div>
275
+ </div>
276
+ <div>
277
+ ```
278
+
279
+ You can pass a body to this modal by passing
280
+ a block.
281
+
282
+ ```erb
283
+ <!-- app/controller/tasks/show.html.erb -->
284
+
285
+ <%= ModalComponent.call id: 'update-task-modal' title: 'Update the task' do %>
286
+ <h2>This is your task!</h2>
287
+ <%= form_with model: @task do |f| %>
288
+ <%= f.text_field :name %>
289
+ <%= f.text_area :description %>
290
+ <%= f.submit %>
291
+ <% end %>
292
+ <% end %>
293
+ ```
294
+
295
+ Note that this will raise an error when no block/nested content is provided.
296
+
297
+ In order to render nested content
298
+ only when it is present (will work without nested content)
299
+ you can use `yield.html_safe if block_given?`
300
+
301
+ In general `block_given?` will return `true` when a block/nested content is present, otherwise `false`.
302
+
303
+ ### Components with namespaces
304
+
305
+ Components may be defined inside multiple modules/namespaces.
306
+
307
+ ```ruby
308
+ # app/components/sign_up/button_component.rb
309
+
310
+ class SignUp::ButtonComponent < AmberComponent::Base
311
+ prop :label, required: true
312
+ end
313
+ ```
314
+
315
+ ```html
316
+ <!-- app/components/sign_up/button_component/view.html.erb -->
317
+
318
+ <div class="sign_up_button_component">
319
+ <%= label %>
320
+ </div>
321
+ ```
322
+
323
+ ```scss
324
+ // app/components/sign_up/button_component/style.scss
325
+
326
+ .sign_up_button_component {
327
+ background-color: indigo;
328
+ border-radius: 1rem;
329
+ transition-duration: 500ms;
330
+
331
+ &:hover {
332
+ background-color: blue;
333
+ }
334
+ }
335
+ ```
336
+
337
+ You can render such a component by calling the `::call` method
338
+ on its class, or by using the helper method defined on its parent module.
339
+
340
+ ```ruby
341
+ SignUp::ButtonComponent.call label: 'Sign up!'
342
+ SignUp.button_component label: 'Sign up!'
343
+ ```
344
+
345
+ ### Generating Components
346
+
347
+ You an generate new components by running
33
348
 
34
349
  ```sh
35
- $ rails generate amber_component:install
350
+ $ bin/rails generate component foo_bar
36
351
  ```
37
352
 
353
+ or
354
+
355
+ ```sh
356
+ $ bin/rails generate component FooBar
357
+ ```
358
+
359
+ This will generate a new component in `app/components/foo_bar_component.rb` along with a view, stylesheet and test file.
360
+
38
361
  ## Contribute
39
362
 
40
363
  Do you want to contribute to AmberComponent? Open the issues page and check for the help wanted label! But before you start coding, please read our [Contributing Guide](https://github.com/amber-ruby/amber_component/blob/main/CONTRIBUTING.md).
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'test_helper'
4
+
5
+ module AmberComponent
6
+ # A base class for component tests with Minitest
7
+ class MinitestTestCase < ::Minitest::Test
8
+ include TestHelper
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmberComponent
4
+ # Provides assertions for the rendered
5
+ # HTML of components.
6
+ module TestHelper
7
+ begin
8
+ require 'capybara/minitest'
9
+ include ::Capybara::Minitest::Assertions
10
+
11
+ def page
12
+ @page ||= ::Capybara::Node::Simple.new(@rendered_content)
13
+ end
14
+ rescue ::LoadError
15
+ nil
16
+ end
17
+
18
+ # @return [Nokogiri::HTML]
19
+ def document
20
+ ::Nokogiri::HTML.fragment(@rendered_content)
21
+ end
22
+ alias doc document
23
+ alias html document
24
+
25
+ # @param content [String]
26
+ # @return [Nokogiri::HTML]
27
+ def render(content = nil)
28
+ @page = nil
29
+ @rendered_content = content || yield
30
+ document
31
+ end
32
+ alias render_inline render
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ::AmberComponent
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
@@ -13,11 +13,30 @@ module ::AmberComponent
13
13
  # copy rake tasks
14
14
  def copy_tasks
15
15
  copy_file 'application_component.rb', 'app/components/application_component.rb'
16
+ copy_file 'application_component_test_case.rb', 'test/application_component_test_case.rb'
17
+ append_file 'test/test_helper.rb', "require_relative 'application_component_test_case'"
16
18
 
17
- inject_into_file 'app/assets/stylesheets/application.css', after: "*= require_tree .\n" do
19
+ require_components_css_in 'app/assets/stylesheets/application.css'
20
+ require_components_css_in 'app/assets/stylesheets/application.scss'
21
+ require_components_css_in 'app/assets/stylesheets/application.sass'
22
+ require_components_css_in 'app/assets/stylesheets/application.css.scss'
23
+ require_components_css_in 'app/assets/stylesheets/application.css.sass'
24
+ require_components_css_in 'app/assets/stylesheets/application.scss.sass'
25
+ require_components_css_in 'app/assets/stylesheets/application.sass.scss'
26
+ end
27
+
28
+ private
29
+
30
+ # @param file_name [String]
31
+ # @return [void]
32
+ def require_components_css_in(file_name)
33
+ return unless ::File.exist? file_name
34
+
35
+ inject_into_file file_name, after: "*= require_tree .\n" do
18
36
  " *= require_tree ./../../components\n"
19
37
  end
20
38
  end
39
+
21
40
  end
22
41
  end
23
42
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'amber_component/test_helper'
4
+
5
+ class ApplicationComponentTestCase < ::ActiveSupport::TestCase
6
+ include ::AmberComponent::TestHelper
7
+ end
@@ -7,12 +7,39 @@ class AmberComponentGenerator < ::Rails::Generators::NamedBase
7
7
  desc 'Generate a new component'
8
8
  source_root ::File.expand_path('templates', __dir__)
9
9
 
10
- # copy rake tasks
11
- def copy_tasks
10
+ # @return [Array<Symbol>]
11
+ VIEW_FORMATS = %i[html erb haml slim].freeze
12
+ # @return [Array<Symbol>]
13
+ STYLE_FORMATS = %i[css scss sass].freeze
14
+
15
+ class_option :view,
16
+ aliases: ['-v'],
17
+ desc: "Indicate what type of view should be generated eg. #{VIEW_FORMATS}"
18
+
19
+ class_option :css,
20
+ aliases: ['--style', '-c'],
21
+ desc: "Indicate what type of styles should be generated eg. #{STYLE_FORMATS}"
22
+
23
+ def generate_component
24
+ @view_format = (options[:view] || :html).to_sym
25
+ @view_format = :html if @view_format == :erb
26
+
27
+ @style_format = options[:css]&.to_sym
28
+
29
+ unless VIEW_FORMATS.include? @view_format
30
+ puts "No such view format as `#{@view_format}`"
31
+ return
32
+ end
33
+
34
+ if !@style_format.nil? && STYLE_FORMATS.include?(@style_format)
35
+ puts "No such css/style format as `#{@style_format}`"
36
+ return
37
+ end
38
+
12
39
  template 'component.rb.erb', "app/components/#{file_path}.rb"
13
40
  template 'component_test.rb.erb', "test/components/#{file_path}_test.rb"
14
- template 'view.html.erb', "app/components/#{file_path}/view.html.erb"
15
- template 'style.css.erb', "app/components/#{file_path}/style.css"
41
+ create_stylesheet
42
+ create_view
16
43
  end
17
44
 
18
45
  def file_name
@@ -21,4 +48,29 @@ class AmberComponentGenerator < ::Rails::Generators::NamedBase
21
48
 
22
49
  "#{name}_component"
23
50
  end
51
+
52
+ private
53
+
54
+ # @return [void]
55
+ def create_view
56
+ case @view_format
57
+ when :slim
58
+ template 'view.slim.erb', "app/components/#{file_path}/view.slim"
59
+ when :haml
60
+ template 'view.haml.erb', "app/components/#{file_path}/view.haml"
61
+ else
62
+ template 'view.html.erb.erb', "app/components/#{file_path}/view.html.erb"
63
+ end
64
+ end
65
+
66
+ # @return [void]
67
+ def create_stylesheet
68
+ if (@style_format.nil? && defined?(::SassC)) || @style_format == :scss
69
+ template 'style.scss.erb', "app/components/#{file_path}/style.scss"
70
+ elsif @style_format == :sass
71
+ template 'style.sass.erb', "app/components/#{file_path}/style.sass"
72
+ else
73
+ template 'style.css.erb', "app/components/#{file_path}/style.css"
74
+ end
75
+ end
24
76
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require_relative 'amber_component_generator'
5
+
6
+ # A Rails generator which creates a new Amber component.
7
+ class ComponentGenerator < AmberComponentGenerator
8
+ source_root ::File.expand_path('templates', __dir__)
9
+ end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class <%= class_name %> < ::ApplicationComponent
4
- # Your code goes here
4
+ # Props that your component accepts
5
+ prop :description, default: -> { 'Default Description' }
5
6
 
6
7
  after_initialize do
8
+ # some initialization
7
9
  @time = ::Time.now
8
10
  end
9
11
  end
@@ -2,8 +2,16 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- class <%= class_name %>Test < ::ActiveSupport::TestCase
6
- # test 'the truth' do
7
- # assert true
5
+ class <%= class_name %>Test < ::ApplicationComponentTestCase
6
+ # For a full list of available assertions see
7
+ # https://rubydoc.info/github/jnicklas/capybara/Capybara/Node/Matchers
8
+
9
+ # test 'returns correct html' do
10
+ # render do
11
+ # <%= class_name %>.call
12
+ # end
13
+
14
+ # assert_text 'Hello from <%= class_name %>'
15
+ # assert_selector "div.<%= singular_table_name %> p", text: 'Default Description'
8
16
  # end
9
17
  end
@@ -1,3 +1,3 @@
1
- .<%= singular_table_name %> {
1
+ .<%= singular_table_name %> h1 {
2
2
  color: blue;
3
3
  }
@@ -0,0 +1,3 @@
1
+ .<%= singular_table_name %>
2
+ h1
3
+ color: blue
@@ -0,0 +1,5 @@
1
+ .<%= singular_table_name %> {
2
+ h1 {
3
+ color: blue;
4
+ }
5
+ }
@@ -0,0 +1,9 @@
1
+ .<%= singular_table_name %>
2
+ %h1
3
+ Hello from
4
+ %b
5
+ <%= class_name %>
6
+ , initialized at:
7
+ = @time
8
+ %p
9
+ = description
@@ -0,0 +1,8 @@
1
+ <div class='<%= singular_table_name %>'>
2
+ <h1>
3
+ Hello from <b><%= class_name %></b>, initialized at: <%%= @time %>
4
+ </h1>
5
+ <p>
6
+ <%%= description %>
7
+ </p>
8
+ </div>
@@ -0,0 +1,6 @@
1
+ div.<%= singular_table_name %>
2
+ h1
3
+ | Hello from
4
+ b <%= class_name %>
5
+ | , initialized at: #{@time}
6
+ p = description