A framework for building reusable, testable & encapsulated view components in Ruby on Rails.
Перейти к файлу
Joel Hawksley ec0434cc18
Refactor compiler for clarity (#2091)
* add test case

* two tests remaining

* first time all green

* Fix final line endings

* add docs, changelog, test helpers

* Fix final line endings

* streamline compiler method generation

* simplification

* refactor to remove index usage

* clearer control flow

* lint

* md lint

* remove remaining hardcoded formats

* Update lib/view_component/base.rb

Co-authored-by: Blake Williams <blakewilliams@github.com>

* remove unnecessary `inspect`

* remove unused `identifier`

* inline single-use method

* add safe navigation

* consolidate template collision error messages to include format

* add backticks around variant name in error

* use one line syntax

* no need to return false

* inline single-use method

* remove offhand comment that would be better in the compiler, if at all

* inline barely used variable

* consolidate safe_class_name into default_method_name

* use shorter `component` instead of `component_class`

* remove unnecessary conditional

* remove unnecessary nesting

* inline single use method

* remove intermediate compiler methods

* InlineTemplate is now included by default

* move comment to be in correct location

* start to make inline templates like other templates

* continue to consolidate inline template logic

* inline templates are just templates

* move lock to outside conditional

* use same method_name definition

* all templates have line numbers

* move towards single method definition path with source

* template handler is already present, no need to re-calculate

* just pass the template around instead of four params

* use single class_eval to define template methods

* remove unnecessary skipping of iterator

* make template hashes look the same

* move default slot registration to Slotable

* define render_template_for in one place

* remove duplicated method name construction

* sort nils last

* consolidate construction of safe_name

* inline single-use method that at minimum should have been private

* method name should not depend on templates state

* set method name on template hash

* use method name from template hash

* shorten to one-line

* move conditional into existing file template conditional

* simplify `templates

* remove unused formats method

* always set @templates at the same point vs. lazily

* move compiled_template to Template

* clean up method name duplication

* more clearly identify method name

* move compile_to_component to Template

* construct template objects

* use template object in more places

* move html format check to template

* use format accessor on template

* move variant access to template

* remove uses for method name from hash

* use template object in more locations

* use template object in more places

* use existing template object

* add comment for reload functionality

* no more template hash!

* do not define branches if it's not used

* use single code path for safe method definition for templates

* consolidate render_template_for duplication

* consolidate to one-liner

* consolidate to one-liner

* pass redefinition lock to template

* use template object for inline templates in render_template_for

* remove unused method definition

* simplify error check

* use default method name in fewer cases

* remove unreachable code

* remove method name logic from compiler

* simplify lookup of variants

* inline variants accessor

* remove duplicative normalized_variant_name

* add note about allowing inline_call / template collision

* remove usage of inline_calls_defined_on_self

* remove inline_calls_defined_on_self

* inline_calls is only used once

* add todo around tracking template rendering

* simplify conditional to use templates

* simplify conditional

* make one-liner

* gather_template_errors explicitly

* use attr_reader to match templates

* move logic into template error construction

* couple template compilation with render method definition

* define safe method as part of compilation

* extract Template#inline_call?

* inline inline_calls helper

* use select instead of conditonal map+compact

* simplify logic and naming in duplicate detection

* use more specific naming for variant pairs

* inline

* passing around redef lock was messy

* initializer is longer than 120 chars

* let Ruby construct symbol string

* simplify branch construction

* assign body as result of conditionals

* use each_with_object to simplify

* use syntactic sugar

* naming, method privacy

* use default values

* inline inline_calls

* standardrb

* remove out-of-date comment

* shorten lines

* use .first

* remove attr_reader

* simplify compiler mode to be boolean

* remove attr_reader

* extract constant for default format

* split conditional into two lines for readibilty

* rename compiler mode to development mode

* use any? with method extracted to template

* avoid use of _1

* avoid use of _1

* move Template to its own file

* extract simplest case to conditional

* Fix final line endings

* avoid block variable

* avoid more block variables

* standardrb

* add comment

* memoize instance methods lookup

* memoize instance method check

* use single line for each argument

* add TODO for HTML output safety check

* extract and comment format and variant derivation from path

* simpler extension extraction

* add explainer comments for format and variant extraction

* use Hash with Set value to find conflicting variants

* use single loop instead of two

* standardrb

* indicate constant is in internal

* move redefinition lock back to compiler

* remove loop

---------

Co-authored-by: GitHub Actions Bot <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Blake Williams <blakewilliams@github.com>
2024-09-11 14:43:58 -06:00
.devcontainer
.github use latest upload/download actions (#2088) 2024-09-04 16:34:29 -06:00
app
docs Add support for multiple formats (#2079) 2024-09-06 20:52:44 +00:00
gemfiles Add support for rendering turbo stream tags (#1227) 2024-08-20 14:07:12 -06:00
lib Refactor compiler for clarity (#2091) 2024-09-11 14:43:58 -06:00
performance
script
spec
test Refactor compiler for clarity (#2091) 2024-09-11 14:43:58 -06:00
.erb-lint.yml
.gitignore
.rspec
.rubocop.yml
.standard.yml
.tool-versions
.vale.ini
.yardopts
Appraisals Add support for rendering turbo stream tags (#1227) 2024-08-20 14:07:12 -06:00
CHANGELOG.md
CNAME
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gemfile set default ruby version (#2075) 2024-08-20 14:46:20 -06:00
Gemfile.lock bundle update (#2087) 2024-09-04 10:36:28 -06:00
LICENSE.txt
README.md
Rakefile Add support for using view components in rails engine (#1951) 2024-08-27 10:12:42 -06:00
SECURITY.md
view_component.gemspec Warn if using Ruby < 3.1 or Rails < 7.0, which will not be supported by ViewComponent v4. (#2090) 2024-09-06 14:18:04 -06:00

README.md

ViewComponent logo ViewComponent logo

A framework for building reusable, testable & encapsulated view components in Ruby on Rails.

Documentation

See viewcomponent.org for documentation.

Contributing

This project is intended to be a safe, welcoming space for collaboration. Contributors are expected to adhere to the Contributor Covenant code of conduct. We recommend reading the contributing guide as well.

License

ViewComponent is available as open source under the terms of the MIT License.