Граф коммитов

2606 Коммитов

Автор SHA1 Сообщение Дата
Simon Fish e8bc4ef344
Make GlobalConfig a proxy for Rails app config or ViewComponent base config as necessary 2024-10-08 17:00:14 +01:00
Simon Fish 4e5301b799
Use ActiveSupport::Configurable to cascade config
ViewComponent::Base itself will always use the defaults. Any classes inheriting from ViewComponent::Base will cascade config down using InheritableOptions, only specifying any overrides.
Generate options being on their own "layer of config is currently unresolved - it might be that config needs to be a new object inheriting from InheritableOptions that has method accessors for everything in that namespace.

It seems like this solution is now applicable to everything, not just strict_helper_enabled?
2024-10-08 17:00:02 +01:00
Simon Fish c4a0d9404e
WIP: Extract strict_helpers_enabled? to component-local config 2024-10-08 16:59:50 +01:00
Reegan Viljoen 5a5727a86a
update changelog 2024-10-08 16:59:27 +01:00
Reegan Viljoen d3fa7030e3
fix: comment location for csrf and csp nonces 2024-10-08 16:59:27 +01:00
Reegan Viljoen 29f888a42d
add: test for missing coverage 2024-10-08 16:59:27 +01:00
Reegan Viljoen fa526d19ea
replace strict_helpers_enabled with helpers_enabled 2024-10-08 16:59:27 +01:00
Reegan Viljoen b76beaaf26
replace helper delegation with use_helpers 2024-10-08 16:59:27 +01:00
Reegan Viljoen da9a3e7721
fix tests 2024-10-08 16:59:27 +01:00
Reegan Viljoen 6511a918c6
revert "fix: linting errors" 2024-10-08 16:59:27 +01:00
Reegan Viljoen f257c84339
Merge branch 'main' into rv-add-strict-helpers 2024-10-08 16:59:27 +01:00
Reegan Viljoen 65d8b932e6
add: strict helpers 2024-10-08 16:59:26 +01:00
Reegan Viljoen 5357491856
add: changelog entry 2024-10-08 16:59:08 +01:00
Reegan Viljoen 43e1373cf0
add: use_helper to base 2024-10-08 16:58:40 +01:00
Simon Fish 161cee37f7
Update changelog 2024-10-08 15:03:39 +01:00
Simon Fish 2c0daf68e9
Lint 2024-10-08 14:54:34 +01:00
Simon Fish 4c89cbc368
Remove component-local config for now
No settings actually use it, but this would be the way to introduce it once we come to need it.
2024-10-08 14:46:46 +01:00
Simon Fish 1f40e96b8a
Bump expected allocations for Ruby 3.4 2024-10-08 14:36:54 +01:00
Simon Fish 2531907b95
Don't attempt to write to show_previews_source in engine initializer 2024-10-08 14:09:33 +01:00
Simon Fish f56832ef4f
Use GlobalConfig as config entrypoint in test engine 2024-10-08 14:06:39 +01:00
Simon Fish a655192a96
Ensure Rails.application is defined, use in preview source feature 2024-10-08 13:53:06 +01:00
Simon Fish 0ba800be0d
Make GlobalConfig a proxy for Rails app config or ViewComponent base config as necessary 2024-10-08 13:52:50 +01:00
Simon Fish 4b4ba769ea
Source test controller from Rails config if available 2024-10-08 13:51:32 +01:00
Simon Fish 71c23c605b
Use ActiveSupport::Configurable to cascade config
ViewComponent::Base itself will always use the defaults. Any classes inheriting from ViewComponent::Base will cascade config down using InheritableOptions, only specifying any overrides.
Generate options being on their own "layer of config is currently unresolved - it might be that config needs to be a new object inheriting from InheritableOptions that has method accessors for everything in that namespace.

This was initially written to support extracting the incoming strict_helpers_enabled? option, but applies to everything.
2024-10-08 13:50:50 +01:00
Alberto Rocha f4b5e18424
Fix #vc_test_request example (#2119)
* Fix #vc_test_request example

Fix the example provided for #vc_test_request to use "vc_test_request" instead of "request".

* Update CHANGELOG
2024-10-07 11:28:15 -06:00
Oleksii Vasyliev a9378955bd
Use struct instead openstruct in lib code (#2123) 2024-10-07 12:20:55 -04:00
Joel Hawksley 1178c8b2c2
resolve ruby warnings in dev (#2120) 2024-10-04 16:13:27 -06:00
Denis Zaratan Pasin 51f0b15a1c
Add TypeScript support (#2117)
* Add TypeScript support

* Small fixes

* Trailling whitespace

* Markdown fix

* Apply suggestions from code review

Thanks @joelhawksley

Co-authored-by: Joel Hawksley <joelhawksley@github.com>

---------

Co-authored-by: Joel Hawksley <joelhawksley@github.com>
2024-10-03 08:29:33 -06:00
Joel Hawksley c7eca74949
release 3.16.0 (#2116) 2024-10-01 12:30:36 -06:00
Joel Hawksley f87c87b661
Add template information to multiple template error messages. (#2115)
* Add template information to multiple template error messages.

In service of helping debug https://github.com/ViewComponent/view_component/issues/2114,
this change fleshes out the template error messages to include
the current list of templates.

* add newline
2024-10-01 11:05:32 -06:00
Jonathan Underwood 553d63f422
Add ostruct to gemspec (#2107)
* Add ostruct to gemspec

* Update docs/CHANGELOG.md

* load ostruct directly in Ruby >= 3.3

* bundle

---------

Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Co-authored-by: Joel Hawksley <joel@hawksley.org>
2024-10-01 10:24:10 -06:00
Joel Hawksley a528f1cf05
release 3.15.1 (#2110) 2024-09-30 09:30:49 -06:00
Joel Hawksley 6fa2a91771
Re-add `@private`, undocumented `.identifier` method that was only me… (#2109)
* Re-add `@private`, undocumented `.identifier` method that was only meant for internal framework use but was used by some downstream consumers. This method will be removed in a coming minor release.

* add nocov marks
2024-09-30 09:29:44 -06:00
Joel Hawksley 0dc9342b35
release 3.15.0 (#2105) 2024-09-27 14:11:06 -06:00
Joel Hawksley 383f775223
update Rails and Ruby EOL support message (#2102)
* update Rails and Ruby EOL support message

* clarify changelog

* vale

* use existing deprecation warnings in engine.rb
2024-09-26 14:12:54 -06:00
Joel Hawksley 4dfc7a9b29
bundle update (#2098) 2024-09-26 10:23:22 -06:00
Joel Hawksley def1448076
Add basic internal testing for memory allocations (#2097)
* Add basic internal testing for memory allocations

* add RUBY_VERSION to debug output

* fix allocation counts

* fix allocation counts

* use compile cache helper

* try using cache clearing

* try using more specific ruby version targets and ensure compilation

* add allocation counts for CI ruby versions

* use counts from CI

* move require to top of file

* try removing component from compile cache to stabilize allocations

* another stabilization attempt
2024-09-25 15:48:23 -06:00
Graham Rogers fe39b4d797
Update `with_controller_class` type documentation (#2094)
* Update `with_controller_class` type documentation

* Updated CHANGELOG.md

---------

Co-authored-by: Joel Hawksley <joel@hawksley.org>
2024-09-16 13:47:48 -06:00
Joel Hawksley 36adbed477
require ostruct (#2096) 2024-09-16 11:13:19 -06:00
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
Joel Hawksley 451543a53f
Add support for multiple formats (#2079)
* 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

* compiler should check for variant/format render combinations

* standardrb

---------

Co-authored-by: GitHub Actions Bot <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Blake Williams <blakewilliams@github.com>
2024-09-06 20:52:44 +00:00
Joel Hawksley 45ffb7a08a
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
Joel Hawksley 8f30d27ef2
use latest upload/download actions (#2088) 2024-09-04 16:34:29 -06:00
Joel Hawksley 3e509df86d
bundle update (#2087) 2024-09-04 10:36:28 -06:00
Adil Lari 7b737b4ece
Add Kicksite to "Who uses ViewComponent?" section (#2083)
* Update index.md

* place alphabetically

* update CHANGELOG
2024-08-30 12:48:20 -06:00
Petrik de Heus 598750ed57
Register stats directories with Rails::CodeStatistics.register_directory (#2081)
* Register stats directories with Rails::CodeStatistics.register_directory.

Rails `main` uses Thor for the `bin/rails stats` command instead of
Rake. This means stats directories need to be added in the Railtie.

The global constant STATS_DIRECTORIES defined by Rails, has been
deprecated in favor of Rails::CodeStatistics.register_directory.

8c7754dfdf/railties/CHANGELOG.md?plain=1#L1-L11

* add changelog

* Update docs/CHANGELOG.md

---------

Co-authored-by: Joel Hawksley <joel@hawksley.org>
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
2024-08-27 18:27:18 +00:00
Joel Hawksley d2d1247e6a
add favicon to fix flaky tests (#2082)
We've recently been seeing some flaky system test failures such as
https://github.com/ViewComponent/view_component/actions/runs/10582240672/job/29321458276?pr=2081
with the error `No route matches [GET] "/favicon.ico"`. It appears
as though the browser is trying to load a favicon and when it fails
to load before the test exits, causes the test to fail.
2024-08-27 11:03:14 -06:00
Andrew H Schwartz d514f5d952
Add slot methods to a module instead of the component class itself (#2040)
* Add distinct GeneratedSlotMethods module to ViewComponents and define `#{slot}` and `#{slot?}` methods on this module, allowing these methods to be overridden with access to `super` implementation.

* Update docs/CONTRIBUTING.md

* Update docs/CHANGELOG.md

---------

Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Co-authored-by: Joel Hawksley <joel@hawksley.org>
2024-08-27 16:29:32 +00:00
Tomasz Kowalewski 80c7c8e811
Add support for using view components in rails engine (#1951)
* Add module namespacing to generated components and other files

First step to add support for using view components in rails engine

* Config#default_preview_paths should include preview paths generated for rails engine

* Add some dummy tests

* Create test group for engine tests

* Fix test and simplecov setup for engine tests

* Tweak tests

* Allow to run tests with 'm' ;)

* Fix tests

* Improve tests

* Fix preview paths

* Return unique values for default_preview_path

* One step closer with tests

* Remove trailing whitespaces

* Update CHANGELOG

* Update contributors list

* Remove .keep

* Update changelog - be more precise in changes description

* Don't wrap with module namespace in tests and specs

Instead of wraping test/spec with module namespacing
pass module namespace inline with described class

* Rename Dummy => TestEngine

---------

Co-authored-by: Joel Hawksley <joel@hawksley.org>
2024-08-27 10:12:42 -06:00
Joel Hawksley 2d48c49563
release 3.14.0 (#2080) 2024-08-26 12:24:20 -06:00