view_component/test
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
..
sandbox Refactor compiler for clarity (#2091) 2024-09-11 14:43:58 -06:00
test_engine Add support for using view components in rails engine (#1951) 2024-08-27 10:12:42 -06:00
view_component
test_helper.rb Refactor compiler for clarity (#2091) 2024-09-11 14:43:58 -06:00