view_component 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of view_component might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ead17ef5662526a74a4aa9547ba94b86dc9e4d30985ed44ab2d6ab8bdbbfd10b
4
- data.tar.gz: 85013db59afe8594749a400205d2b94c3f7314a144c256081825e29125511dc9
3
+ metadata.gz: 9dddd6d65c2dc550deac20d7bcaf84051f1c4b2f8c219ed8e402e8c058524c03
4
+ data.tar.gz: 2fa94dc83ac665667f3559364c77a4682ee9f7fb71219ed3eb3cce2ba8ed6354
5
5
  SHA512:
6
- metadata.gz: ab3c8366510c44a48473d9fa1186c823b1576b51e4aef745869adc033f254cfa4c0eea8e40ee1c9ce82f394150669958db3b25a430cb6bdade085edb18bd458c
7
- data.tar.gz: 7c1767eb36013da60db2b6a0feb9af340a571573ecbd7b4552cf3c8c1ec4de019e852832a95123c4067c56db6602c1ab8e12c85ac6e55e3c2a68904db7d0ddef
6
+ metadata.gz: ec78468d11cbf6c8011b39b6000156ce19e9caef4082dd68f0561422fb88d5cc5e11c2e8966c33a4ac0e50f0bc455934847519e4229d47756ce9fa4af2576c06
7
+ data.tar.gz: bac3e1f5b3619c5c2f310e700862e6a2f0dfee69ec770079400ff5744c49c976741fdc5f6b019f0e0ab5858396dd236aa90cc94247c15ba0c73c5f423f80a1ff
@@ -1,5 +1,17 @@
1
1
  # master
2
2
 
3
+ * Allow using inline render method(s) defined on a parent.
4
+
5
+ *Simon Rand*
6
+
7
+ * Fix bug where inline variant render methods would never be called.
8
+
9
+ *Simon Rand*
10
+
11
+ * ViewComponent preview index views use Rails internal layout instead of application's layout
12
+
13
+ *Juan Manuel Ramallo*
14
+
3
15
  # v2.2.2
4
16
 
5
17
  * Add `Base.format` for better compatibility with `ActionView::Template`.
data/README.md CHANGED
@@ -3,24 +3,14 @@ A view component framework for Rails.
3
3
 
4
4
  **Current Status**: Used in production at GitHub. Because of this, all changes will be thoroughly vetted, which could slow down the process of contributing. We will do our best to actively communicate status of pull requests with any contributors. If you have any substantial changes that you would like to make, it would be great to first [open an issue](http://github.com/github/view_component/issues/new) to discuss them with us.
5
5
 
6
- ## Migration in progress
6
+ ## Migration from ActionView::Component
7
7
 
8
- This gem is in the process of a name / API change from `ActionView::Component` to `ViewComponent`, see https://github.com/github/view_component/issues/206.
8
+ This gem used to be called `ActionView::Component`.
9
+ See [issue #206] for some background on the name change.
10
+ Learn more about what changed and how to migrate [here][migration-info].
9
11
 
10
- ### What's changing in the migration
11
-
12
- 1. `ActionView::Component::Base` is now `ViewComponent::Base`.
13
- 1. Components can only be rendered with `render(MyComponent.new)` syntax.
14
- 1. Validations are no longer supported by default.
15
-
16
- ### How to migrate to ViewComponent
17
-
18
- 1. Update `Gemfile` to use `view_component`.
19
- 1. In `application.rb`, require `view_component/engine`.
20
- 1. Update components to inherit from `ViewComponent::Base`.
21
- 1. Update component tests to inherit from `ViewComponent::TestCase`.
22
- 1. Update component previews to inherit from `ViewComponent::Preview`.
23
- 1. Include `ViewComponent::TestHelpers` in the appropriate test helper file.
12
+ [issue #206]: https://github.com/github/view_component/issues/206
13
+ [migration-info]: https://github.com/github/view_component/blob/v2.0.0/README.md#migration-in-progress
24
14
 
25
15
  ## Roadmap
26
16
 
@@ -211,6 +201,22 @@ class InlineComponent < ViewComponent::Base
211
201
  end
212
202
  ```
213
203
 
204
+ It is also possible to render variants inline by creating additional `call_` methods.
205
+
206
+ ```ruby
207
+ class InlineVariantComponent < ViewComponent::Base
208
+ def call
209
+ link_to "Default", default_path
210
+ end
211
+
212
+ def call_phone
213
+ link_to "Phone", phone_path
214
+ end
215
+ end
216
+ ```
217
+
218
+ Using a mixture of templates and inline render methods in a component is supported, however only one should be provided per component (or variant).
219
+
214
220
  ### Conditional Rendering
215
221
 
216
222
  Components can implement a `#render?` method to determine if they should be rendered.
@@ -535,7 +541,7 @@ config.view_component.preview_path = "#{Rails.root}/lib/component_previews"
535
541
 
536
542
  #### Configuring TestController
537
543
 
538
- Component tests and previews assume the existence of an `ApplicationController` class, be can beconfigured using the `test_controller` option:
544
+ Component tests and previews assume the existence of an `ApplicationController` class, be can be configured using the `test_controller` option:
539
545
 
540
546
  `config/application.rb`
541
547
  ```ruby
@@ -631,6 +637,11 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/github
631
637
  |@blakewilliams|@seanpdoyle|@tclem|@nashby|@jaredcwhite|
632
638
  |Boston, MA|New York, NY|San Francisco, CA|Minsk|Portland, OR|
633
639
 
640
+ |<img src="https://avatars.githubusercontent.com/simonrand?s=256" alt="simonrand" width="128" />|
641
+ |:---:|
642
+ |@simonrand|
643
+ |Dublin, Ireland|
644
+
634
645
  ## License
635
646
 
636
647
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -4,7 +4,6 @@ require "rails/application_controller"
4
4
 
5
5
  class Rails::ViewComponentsController < Rails::ApplicationController # :nodoc:
6
6
  prepend_view_path File.expand_path("../../../lib/railties/lib/rails/templates/rails", __dir__)
7
- prepend_view_path "#{Rails.root}/app/views/" if defined?(Rails.root)
8
7
 
9
8
  around_action :set_locale, only: :previews
10
9
  before_action :find_preview, only: :previews
@@ -29,6 +28,7 @@ class Rails::ViewComponentsController < Rails::ApplicationController # :nodoc:
29
28
  render "components/previews"
30
29
  # rubocop:enable GitHub/RailsControllerRenderPathsExist
31
30
  else
31
+ prepend_application_view_paths
32
32
  @example_name = File.basename(params[:path])
33
33
  @render_args = @preview.render_args(@example_name)
34
34
  layout = @render_args[:layout]
@@ -62,4 +62,8 @@ class Rails::ViewComponentsController < Rails::ApplicationController # :nodoc:
62
62
  yield
63
63
  end
64
64
  end
65
+
66
+ def prepend_application_view_paths
67
+ prepend_view_path Rails.root.join("app/views") if defined?(Rails.root)
68
+ end
65
69
  end
@@ -168,10 +168,6 @@ module ViewComponent
168
168
  @compiled && ActionView::Base.cache_template_loading
169
169
  end
170
170
 
171
- def inlined?
172
- instance_methods(false).grep(/^call/).present? && templates.empty?
173
- end
174
-
175
171
  def compile!
176
172
  compile(raise_template_errors: true)
177
173
  end
@@ -180,13 +176,17 @@ module ViewComponent
180
176
  # We could in theory do this on app boot, at least in production environments.
181
177
  # Right now this just compiles the first time the component is rendered.
182
178
  def compile(raise_template_errors: false)
183
- return if compiled? || inlined?
179
+ return if compiled?
184
180
 
185
181
  if template_errors.present?
186
182
  raise ViewComponent::TemplateError.new(template_errors) if raise_template_errors
187
183
  return false
188
184
  end
189
185
 
186
+ define_singleton_method(:variants) do
187
+ templates.map { |template| template[:variant] } + variants_from_inline_calls(inline_calls)
188
+ end
189
+
190
190
  # If template name annotations are turned on, a line is dynamically
191
191
  # added with a comment. In this case, we want to return a different
192
192
  # starting line number so errors that are raised will point to the
@@ -211,10 +211,6 @@ module ViewComponent
211
211
  @compiled = true
212
212
  end
213
213
 
214
- def variants
215
- templates.map { |template| template[:variant] }
216
- end
217
-
218
214
  # we'll eventually want to update this to support other types
219
215
  def type
220
216
  "text/html"
@@ -247,6 +243,33 @@ module ViewComponent
247
243
 
248
244
  private
249
245
 
246
+ def compiled_template(file_path)
247
+ handler = ActionView::Template.handler_for_extension(File.extname(file_path).gsub(".", ""))
248
+ template = File.read(file_path)
249
+
250
+ if handler.method(:call).parameters.length > 1
251
+ handler.call(self, template)
252
+ else
253
+ handler.call(OpenStruct.new(source: template, identifier: identifier, type: type))
254
+ end
255
+ end
256
+
257
+ def inline_calls
258
+ @inline_calls ||=
259
+ begin
260
+ # Fetch only ViewComponent ancestor classes to limit the scope of
261
+ # finding inline calls
262
+ view_component_ancestors =
263
+ ancestors.take_while { |ancestor| ancestor != ViewComponent::Base } - included_modules
264
+
265
+ view_component_ancestors.flat_map { |ancestor| ancestor.instance_methods(false).grep(/^call/) }.uniq
266
+ end
267
+ end
268
+
269
+ def inline_calls_defined_on_self
270
+ @inline_calls_defined_on_self ||= instance_methods(false).grep(/^call/)
271
+ end
272
+
250
273
  def matching_views_in_source_location
251
274
  return [] unless source_location
252
275
  (Dir["#{source_location.chomp(File.extname(source_location))}.*{#{ActionView::Template.template_handler_extensions.join(',')}}"] - [source_location])
@@ -269,7 +292,10 @@ module ViewComponent
269
292
  @template_errors ||=
270
293
  begin
271
294
  errors = []
272
- errors << "Could not find a template file for #{self}." if templates.empty?
295
+
296
+ if (templates + inline_calls).empty?
297
+ errors << "Could not find a template file or inline render method for #{self}."
298
+ end
273
299
 
274
300
  if templates.count { |template| template[:variant].nil? } > 1
275
301
  errors << "More than one template found for #{self}. There can only be one default template file per component."
@@ -284,18 +310,27 @@ module ViewComponent
284
310
  unless invalid_variants.empty?
285
311
  errors << "More than one template found for #{'variant'.pluralize(invalid_variants.count)} #{invalid_variants.map { |v| "'#{v}'" }.to_sentence} in #{self}. There can only be one template file per variant."
286
312
  end
313
+
314
+ if templates.find { |template| template[:variant].nil? } && inline_calls_defined_on_self.include?(:call)
315
+ errors << "Template file and inline render method found for #{self}. There can only be a template file or inline render method per component."
316
+ end
317
+
318
+ duplicate_template_file_and_inline_variant_calls =
319
+ templates.pluck(:variant) & variants_from_inline_calls(inline_calls_defined_on_self)
320
+
321
+ unless duplicate_template_file_and_inline_variant_calls.empty?
322
+ count = duplicate_template_file_and_inline_variant_calls.count
323
+
324
+ errors << "Template #{'file'.pluralize(count)} and inline render #{'method'.pluralize(count)} found for #{'variant'.pluralize(count)} #{duplicate_template_file_and_inline_variant_calls.map { |v| "'#{v}'" }.to_sentence} in #{self}. There can only be a template file or inline render method per variant."
325
+ end
326
+
287
327
  errors
288
328
  end
289
329
  end
290
330
 
291
- def compiled_template(file_path)
292
- handler = ActionView::Template.handler_for_extension(File.extname(file_path).gsub(".", ""))
293
- template = File.read(file_path)
294
-
295
- if handler.method(:call).parameters.length > 1
296
- handler.call(self, template)
297
- else
298
- handler.call(OpenStruct.new(source: template, identifier: identifier, type: type))
331
+ def variants_from_inline_calls(calls)
332
+ calls.reject { |call| call == :call }.map do |variant_call|
333
+ variant_call.to_s.sub("call_", "").to_sym
299
334
  end
300
335
  end
301
336
  end
@@ -3,8 +3,8 @@
3
3
  module ViewComponent
4
4
  module VERSION
5
5
  MAJOR = 2
6
- MINOR = 2
7
- PATCH = 2
6
+ MINOR = 3
7
+ PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-07 00:00:00.000000000 Z
11
+ date: 2020-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -143,21 +143,10 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - ".github/ISSUE_TEMPLATE"
147
- - ".github/PULL_REQUEST_TEMPLATE"
148
- - ".github/workflows/ruby_on_rails.yml"
149
- - ".gitignore"
150
- - ".rubocop.yml"
151
146
  - CHANGELOG.md
152
- - CODE_OF_CONDUCT.md
153
- - CONTRIBUTING.md
154
- - Gemfile
155
- - Gemfile.lock
156
147
  - LICENSE.txt
157
148
  - README.md
158
- - Rakefile
159
149
  - app/controllers/rails/view_components_controller.rb
160
- - docs/case-studies/jellyswitch.md
161
150
  - lib/rails/generators/component/USAGE
162
151
  - lib/rails/generators/component/component_generator.rb
163
152
  - lib/rails/generators/component/templates/component.rb.tt
@@ -187,12 +176,6 @@ files:
187
176
  - lib/view_component/test_case.rb
188
177
  - lib/view_component/test_helpers.rb
189
178
  - lib/view_component/version.rb
190
- - script/bootstrap
191
- - script/console
192
- - script/install
193
- - script/release
194
- - script/test
195
- - view_component.gemspec
196
179
  homepage: https://github.com/github/view_component
197
180
  licenses:
198
181
  - MIT
@@ -1,27 +0,0 @@
1
- <!-- **** Filing a Feature Request? Include these sections. **** -->
2
-
3
- ### Feature request
4
- <!-- Provide a summary of the behavior. -->
5
-
6
- ### Motivation
7
-
8
- <!-- What would you like to do with this feature? Can you provide
9
- context or references to similar behavior in other libraries? -->
10
-
11
- <!-- **** Filing a Bug Report? Include these sections: **** -->
12
-
13
- ### Steps to reproduce
14
- <!-- Provide a series of steps or, better yet, a link to a repo to demonstrate the bug you've identified. -->
15
-
16
- ### Expected behavior
17
- <!-- Tell us what should happen -->
18
-
19
- ### Actual behavior
20
- <!-- Tell us what happens instead -->
21
-
22
- ### System configuration
23
- **Rails version**:
24
-
25
- **Ruby version**:
26
-
27
- **Gem version**:
@@ -1,17 +0,0 @@
1
- <!-- See https://github.com/github/view_component/blob/master/CONTRIBUTING.md#submitting-a-pull-request -->
2
-
3
- ### Summary
4
-
5
- <!-- Provide a general description of the code changes in your pull
6
- request... were there any bugs you had fixed? If so, mention them. If
7
- these bugs have open GitHub issues, be sure to tag them here as well,
8
- to keep the conversation linked together. -->
9
-
10
- ### Other Information
11
-
12
- <!-- If there's anything else that's important and relevant to your pull
13
- request, mention that information here. This could include
14
- benchmarks, or other information.
15
-
16
- If you are updating any of the CHANGELOG files or are asked to update the
17
- CHANGELOG files by reviewers, please add the CHANGELOG entry at the top of the file. -->
@@ -1,35 +0,0 @@
1
- name: Ruby on Rails
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- build:
7
- runs-on: ubuntu-latest
8
- strategy:
9
- matrix:
10
- rails_version: [5.0.0, 5.2.3, 6.0.0, master]
11
- ruby_version: [2.4.x, 2.5.x, 2.6.x, 2.7.x]
12
- exclude:
13
- - rails_version: master
14
- ruby_version: 2.4.x
15
- - rails_version: 6.0.0
16
- ruby_version: 2.4.x
17
- steps:
18
- - uses: actions/checkout@master
19
- - name: Setup Ruby
20
- uses: actions/setup-ruby@v1
21
- with:
22
- ruby-version: ${{ matrix.ruby_version }}
23
- - name: Update rubygems when testing with Ruby 2.4.x
24
- if: startsWith(matrix.ruby_version, '2.4')
25
- run: |
26
- gem update --system --no-document
27
- - name: Build and test with Rake
28
- run: |
29
- gem install bundler:1.17.3
30
- bundle update
31
- bundle install --jobs 4 --retry 3
32
- bundle exec rake
33
- bundle exec rubocop
34
- env:
35
- RAILS_VERSION: ${{ matrix.rails_version }}
data/.gitignore DELETED
@@ -1,53 +0,0 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /spec/examples.txt
9
- /test/tmp/
10
- /test/version_tmp/
11
- /tmp/
12
- /test/log/*
13
- /test/app/tmp/*
14
- /test/tmp/*
15
-
16
- # Used by dotenv library to load environment variables.
17
- # .env
18
-
19
- ## Specific to RubyMotion:
20
- .dat*
21
- .repl_history
22
- build/
23
- *.bridgesupport
24
- build-iPhoneOS/
25
- build-iPhoneSimulator/
26
-
27
- ## Specific to RubyMotion (use of CocoaPods):
28
- #
29
- # We recommend against adding the Pods directory to your .gitignore. However
30
- # you should judge for yourself, the pros and cons are mentioned at:
31
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
- #
33
- # vendor/Pods/
34
-
35
- ## Documentation cache and generated files:
36
- /.yardoc/
37
- /_yardoc/
38
- /doc/
39
- /rdoc/
40
-
41
- ## Environment normalization:
42
- /.bundle/
43
- /vendor/bundle
44
- /lib/bundler/man/
45
-
46
- # for a library or gem, you might want to ignore these files since the code is
47
- # intended to run in multiple environments; otherwise, check them in:
48
- # Gemfile.lock
49
- # .ruby-version
50
- # .ruby-gemset
51
-
52
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
- .rvmrc
@@ -1,8 +0,0 @@
1
- inherit_gem:
2
- rubocop-github:
3
- - config/default.yml
4
- - config/rails.yml
5
-
6
- AllCops:
7
- Exclude:
8
- - "test/tmp/**/*"
@@ -1,76 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, sex characteristics, gender identity and expression,
9
- level of experience, education, socio-economic status, nationality, personal
10
- appearance, race, religion, or sexual identity and orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies within all project spaces, and it also applies when
49
- an individual is representing the project or its community in public spaces.
50
- Examples of representing a project or community include using an official
51
- project e-mail address, posting via an official social media account, or acting
52
- as an appointed representative at an online or offline event. Representation of
53
- a project may be further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at opensource@github.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
-
73
- [homepage]: https://www.contributor-covenant.org
74
-
75
- For answers to common questions about this code of conduct, see
76
- https://www.contributor-covenant.org/faq
@@ -1,46 +0,0 @@
1
- # Contributing
2
-
3
- [fork]: https://github.com/github/view_component/fork
4
- [pr]: https://github.com/github/view_component/compare
5
- [style]: https://github.com/styleguide/ruby
6
- [code-of-conduct]: CODE_OF_CONDUCT.md
7
-
8
- Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
9
-
10
- Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.txt).
11
-
12
- Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
13
-
14
- ## Submitting a pull request
15
-
16
- 0. [Fork][fork] and clone the repository
17
- 0. Configure and install the dependencies: `bundle`
18
- 0. Make sure the tests pass on your machine: `bundle exec rake`
19
- 0. Create a new branch: `git checkout -b my-branch-name`
20
- 0. Make your change, add tests, and make sure the tests still pass
21
- 0. Add an entry to the top of `CHANGELOG.md` for your changes
22
- 0. If it's your first time contributing, add yourself to the contributors at the bottom of `README.md`
23
- 0. Push to your fork and [submit a pull request][pr]
24
- 0. Pat your self on the back and wait for your pull request to be reviewed and merged.
25
-
26
- Here are a few things you can do that will increase the likelihood of your pull request being accepted:
27
-
28
- - Write tests.
29
- - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
30
- - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
31
-
32
- ## Releasing
33
-
34
- If you are the current maintainer of this gem:
35
-
36
- 1. Create a branch for the release: `git checkout -b release-vxx.xx.xx`
37
- 1. Bump gem version in `lib/view_component/version.rb`. Try to adhere to SemVer.
38
- 1. Add version heading/entries to `CHANGELOG.md`.
39
- 1. Make sure your local dependencies are up to date: `bundle`
40
- 1. Ensure that tests are green: `bundle exec rake`
41
- 1. Make a PR to github/view_component.
42
- 1. Build a local gem: `gem build view_component.gemspec`
43
- 1. Merge github/view_component PR
44
- 1. Tag and push: `git tag vx.xx.xx; git push --tags`
45
- 1. Create a GitHub release with the pushed tag (https://github.com/github/view_component/releases/new) and populate it with a list of the commits from `git log --pretty=format:"- %s" --reverse refs/tags/[OLD TAG]...refs/tags/[NEW TAG]`
46
- 1. Push to rubygems.org -- `gem push view_component-VERSION.gem`
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
- gemspec
5
-
6
- rails_version = "#{ENV['RAILS_VERSION'] || '6.0.2.2'}"
7
-
8
- gem "rails", rails_version == "master" ? { github: "rails/rails" } : rails_version
@@ -1,202 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- view_component (2.2.2)
5
- capybara (~> 3)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (6.0.2.2)
11
- actionpack (= 6.0.2.2)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.2.2)
15
- actionpack (= 6.0.2.2)
16
- activejob (= 6.0.2.2)
17
- activerecord (= 6.0.2.2)
18
- activestorage (= 6.0.2.2)
19
- activesupport (= 6.0.2.2)
20
- mail (>= 2.7.1)
21
- actionmailer (6.0.2.2)
22
- actionpack (= 6.0.2.2)
23
- actionview (= 6.0.2.2)
24
- activejob (= 6.0.2.2)
25
- mail (~> 2.5, >= 2.5.4)
26
- rails-dom-testing (~> 2.0)
27
- actionpack (6.0.2.2)
28
- actionview (= 6.0.2.2)
29
- activesupport (= 6.0.2.2)
30
- rack (~> 2.0, >= 2.0.8)
31
- rack-test (>= 0.6.3)
32
- rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.2.2)
35
- actionpack (= 6.0.2.2)
36
- activerecord (= 6.0.2.2)
37
- activestorage (= 6.0.2.2)
38
- activesupport (= 6.0.2.2)
39
- nokogiri (>= 1.8.5)
40
- actionview (6.0.2.2)
41
- activesupport (= 6.0.2.2)
42
- builder (~> 3.1)
43
- erubi (~> 1.4)
44
- rails-dom-testing (~> 2.0)
45
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- activejob (6.0.2.2)
47
- activesupport (= 6.0.2.2)
48
- globalid (>= 0.3.6)
49
- activemodel (6.0.2.2)
50
- activesupport (= 6.0.2.2)
51
- activerecord (6.0.2.2)
52
- activemodel (= 6.0.2.2)
53
- activesupport (= 6.0.2.2)
54
- activestorage (6.0.2.2)
55
- actionpack (= 6.0.2.2)
56
- activejob (= 6.0.2.2)
57
- activerecord (= 6.0.2.2)
58
- marcel (~> 0.3.1)
59
- activesupport (6.0.2.2)
60
- concurrent-ruby (~> 1.0, >= 1.0.2)
61
- i18n (>= 0.7, < 2)
62
- minitest (~> 5.1)
63
- tzinfo (~> 1.1)
64
- zeitwerk (~> 2.2)
65
- addressable (2.7.0)
66
- public_suffix (>= 2.0.2, < 5.0)
67
- ast (2.4.0)
68
- better_html (1.0.14)
69
- actionview (>= 4.0)
70
- activesupport (>= 4.0)
71
- ast (~> 2.0)
72
- erubi (~> 1.4)
73
- html_tokenizer (~> 0.0.6)
74
- parser (>= 2.4)
75
- smart_properties
76
- builder (3.2.4)
77
- capybara (3.32.1)
78
- addressable
79
- mini_mime (>= 0.1.3)
80
- nokogiri (~> 1.8)
81
- rack (>= 1.6.0)
82
- rack-test (>= 0.6.3)
83
- regexp_parser (~> 1.5)
84
- xpath (~> 3.2)
85
- concurrent-ruby (1.1.6)
86
- crass (1.0.6)
87
- erubi (1.9.0)
88
- globalid (0.4.2)
89
- activesupport (>= 4.2.0)
90
- haml (5.1.2)
91
- temple (>= 0.8.0)
92
- tilt
93
- html_tokenizer (0.0.7)
94
- i18n (1.8.2)
95
- concurrent-ruby (~> 1.0)
96
- jaro_winkler (1.5.4)
97
- loofah (2.4.0)
98
- crass (~> 1.0.2)
99
- nokogiri (>= 1.5.9)
100
- mail (2.7.1)
101
- mini_mime (>= 0.1.1)
102
- marcel (0.3.3)
103
- mimemagic (~> 0.3.2)
104
- method_source (1.0.0)
105
- mimemagic (0.3.4)
106
- mini_mime (1.0.2)
107
- mini_portile2 (2.4.0)
108
- minitest (5.1.0)
109
- nio4r (2.5.2)
110
- nokogiri (1.10.9)
111
- mini_portile2 (~> 2.4.0)
112
- parallel (1.19.1)
113
- parser (2.7.0.5)
114
- ast (~> 2.4.0)
115
- public_suffix (4.0.4)
116
- rack (2.2.2)
117
- rack-test (1.1.0)
118
- rack (>= 1.0, < 3)
119
- rails (6.0.2.2)
120
- actioncable (= 6.0.2.2)
121
- actionmailbox (= 6.0.2.2)
122
- actionmailer (= 6.0.2.2)
123
- actionpack (= 6.0.2.2)
124
- actiontext (= 6.0.2.2)
125
- actionview (= 6.0.2.2)
126
- activejob (= 6.0.2.2)
127
- activemodel (= 6.0.2.2)
128
- activerecord (= 6.0.2.2)
129
- activestorage (= 6.0.2.2)
130
- activesupport (= 6.0.2.2)
131
- bundler (>= 1.3.0)
132
- railties (= 6.0.2.2)
133
- sprockets-rails (>= 2.0.0)
134
- rails-dom-testing (2.0.3)
135
- activesupport (>= 4.2.0)
136
- nokogiri (>= 1.6)
137
- rails-html-sanitizer (1.3.0)
138
- loofah (~> 2.3)
139
- railties (6.0.2.2)
140
- actionpack (= 6.0.2.2)
141
- activesupport (= 6.0.2.2)
142
- method_source
143
- rake (>= 0.8.7)
144
- thor (>= 0.20.3, < 2.0)
145
- rainbow (3.0.0)
146
- rake (13.0.1)
147
- regexp_parser (1.7.0)
148
- rubocop (0.74.0)
149
- jaro_winkler (~> 1.5.1)
150
- parallel (~> 1.10)
151
- parser (>= 2.6)
152
- rainbow (>= 2.2.2, < 4.0)
153
- ruby-progressbar (~> 1.7)
154
- unicode-display_width (>= 1.4.0, < 1.7)
155
- rubocop-github (0.13.0)
156
- rubocop (~> 0.70)
157
- rubocop-performance (~> 1.3.0)
158
- rubocop-performance (1.3.0)
159
- rubocop (>= 0.68.0)
160
- ruby-progressbar (1.10.1)
161
- slim (4.0.1)
162
- temple (>= 0.7.6, < 0.9)
163
- tilt (>= 2.0.6, < 2.1)
164
- smart_properties (1.15.0)
165
- sprockets (4.0.0)
166
- concurrent-ruby (~> 1.0)
167
- rack (> 1, < 3)
168
- sprockets-rails (3.2.1)
169
- actionpack (>= 4.0)
170
- activesupport (>= 4.0)
171
- sprockets (>= 3.0.0)
172
- temple (0.8.2)
173
- thor (1.0.1)
174
- thread_safe (0.3.6)
175
- tilt (2.0.10)
176
- tzinfo (1.2.6)
177
- thread_safe (~> 0.1)
178
- unicode-display_width (1.6.1)
179
- websocket-driver (0.7.1)
180
- websocket-extensions (>= 0.1.0)
181
- websocket-extensions (0.1.4)
182
- xpath (3.2.0)
183
- nokogiri (~> 1.8)
184
- zeitwerk (2.3.0)
185
-
186
- PLATFORMS
187
- ruby
188
-
189
- DEPENDENCIES
190
- better_html (~> 1)
191
- bundler (~> 1.14)
192
- haml (~> 5)
193
- minitest (= 5.1.0)
194
- rails (= 6.0.2.2)
195
- rake (~> 13.0)
196
- rubocop (= 0.74)
197
- rubocop-github (~> 0.13.0)
198
- slim (~> 4.0)
199
- view_component!
200
-
201
- BUNDLED WITH
202
- 1.17.3
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
10
- end
11
-
12
- task default: :test
@@ -1,76 +0,0 @@
1
- Name: Dave Paola
2
-
3
- Github Handle: [@dpaola2](https://github.com/dpaola2)
4
-
5
- [Jellyswitch](https://www.jellyswitch.com) is a coworking space management platform
6
-
7
- In response to [this tweet](https://twitter.com/joelhawksley/status/1232674647327547394):
8
-
9
- I recently began refactoring many of my partials into components. Along the way I discovered an interesting use case, which was to componentize the various bootstrap components I was already using.
10
-
11
- Some examples:
12
-
13
- - I've componentized the specific layout that I've designed using the grid system. I have defined a `FullWidthLayout` component that wraps its contents in the correct classes to give my layout a good design on both mobile and desktop. (On desktop, there is a sidebar, and on mobile, the sidebar floats on top in a collapsed fashion.)
14
- - [Modals](https://getbootstrap.com/docs/4.4/components/modal/) are now componentized and accept arguments. I had them as partials before, but having ruby classes is an upgrade.
15
- - [Breadcrumbs](https://getbootstrap.com/docs/4.4/components/breadcrumb/) same as above.
16
-
17
- Here's one that I use a LOT: `OnOffSwitch`:
18
-
19
- ```ruby
20
- class OnOffSwitch < ApplicationComponent
21
- def initialize(predicate:, path:, disabled: false, label: nil)
22
- @predicate = predicate
23
- @path = path
24
- @disabled = disabled
25
- @label = label
26
- end
27
-
28
- private
29
-
30
- attr_reader :predicate, :path, :disabled, :label
31
-
32
- def icon_class
33
- if predicate
34
- "fas fa-toggle-on"
35
- else
36
- "fas fa-toggle-off"
37
- end
38
- end
39
- end
40
- ```
41
-
42
- ```erb
43
- <div class="d-flex align-items-center">
44
- <% if !disabled %>
45
- <%= link_to path, class: "text-body", remote: true do %>
46
- <span style="font-size: 20pt">
47
- <% if predicate %>
48
- <span class="text-success">
49
- <i class="<%= icon_class %>"></i>
50
- </span>
51
- <% else %>
52
- <span class="text-danger">
53
- <i class="<%= icon_class %>"></i>
54
- </span>
55
- <% end %>
56
- </span>
57
- <% end %>
58
- <% else %>
59
- <span style="font-size: 20pt">
60
- <span class="text-muted">
61
- <i class="<%= icon_class %>"></i>
62
- </span>
63
- </span>
64
- <% end %>
65
- &nbsp;
66
- <%= content %>
67
- </div>
68
- ```
69
-
70
- Here is an example of how this looks:
71
-
72
- <img width="653" alt="Screenshot 2020-02-26 08 34 07" src="https://user-images.githubusercontent.com/150509/75365920-cbfb9500-5872-11ea-8234-f1343629a462.png">
73
-
74
- I have found that refactoring complex views is made easier and faster by first putting them into a component, extracting the conditionals and other logic into private methods and proceeding from there. And I wind up with a very nice set of well-factored components and sub-components, with argument lists and validations and so on. I think the rails community is really going to benefit from this library, and I'm hugely appreciative of y'all's efforts on it!
75
-
76
- I plan to release an early version of the bootstrap components we've developed at some point in the near future. I would love to collaborate and learn the most appropriate way to structure that contribution.
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "view_component"
6
-
7
- require "irb"
8
- IRB.start(__FILE__)
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle exec rake install
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle exec rake release
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle exec rake
@@ -1,45 +0,0 @@
1
- # coding: utf-8
2
- # frozen_string_literal: true
3
-
4
- lib = File.expand_path("../lib", __FILE__)
5
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
- require "view_component/version"
7
-
8
- Gem::Specification.new do |spec|
9
- spec.name = "view_component"
10
- spec.version = ViewComponent::VERSION::STRING
11
- spec.authors = ["GitHub Open Source"]
12
- spec.email = ["opensource+view_component@github.com"]
13
-
14
- spec.summary = %q{View components for Rails}
15
- spec.homepage = "https://github.com/github/view_component"
16
- spec.license = "MIT"
17
-
18
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
- # to allow pushing to a single host or delete this section to allow pushing to any host.
20
- if spec.respond_to?(:metadata)
21
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
- else
23
- raise "RubyGems 2.0 or newer is required to protect against " \
24
- "public gem pushes."
25
- end
26
-
27
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
- f.match(%r{^(test|spec|features)/})
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- spec.required_ruby_version = ">= 2.3.0"
35
-
36
- spec.add_runtime_dependency "capybara", "~> 3"
37
- spec.add_development_dependency "bundler", "~> 1.14"
38
- spec.add_development_dependency "rake", "~> 13.0"
39
- spec.add_development_dependency "minitest", "= 5.1.0"
40
- spec.add_development_dependency "haml", "~> 5"
41
- spec.add_development_dependency "slim", "~> 4.0"
42
- spec.add_development_dependency "better_html", "~> 1"
43
- spec.add_development_dependency "rubocop", "= 0.74"
44
- spec.add_development_dependency "rubocop-github", "~> 0.13.0"
45
- end