Skip to content

Commit f054656

Browse files
authored
Merge pull request #478 from matestack/next-release
1.2.0 Release
2 parents 9c2f305 + 69fe01c commit f054656

File tree

22 files changed

+73
-20
lines changed

22 files changed

+73
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.2.0 Release
4+
5+
### Improvements
6+
7+
* Enable usage of Rails view/route helpers on standalone components used via matestack_component helper #476
8+
39
## v1.1.0 Release
410

511
### Improvements

app/concepts/matestack/ui/core/component/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def add_child(child_class, *args, &block)
245245

246246
# check only allowed keys are passed to isolated components
247247
if child_class < Matestack::Ui::Core::Isolated::Isolated
248-
unless args.empty? || args[0].keys.all? { |key| [:defer, :public_options, :rerender_on, :init_on, :rerender_delay, :matestack_context].include? key }
248+
unless args.empty? || args[0].keys.all? { |key| [:defer, :public_options, :rerender_on, :init_on, :rerender_delay, :matestack_context, :context].include? key }
249249
raise "isolated components can only take params in a public_options hash, which will be exposed to the client side in order to perform an async request with these params."
250250
end
251251
if args.any? { |arg| arg[:init_on].present? } && @matestack_skip_defer == true

app/helpers/matestack/ui/core/application_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def matestack_component(component, options = {}, &block)
102102
controller = (self.class <= ActionController::Base) ? self : @_controller
103103
context = (options[:matestack_context] ||= {}).merge(controller: controller)
104104
Matestack::Ui::Core::Component::Base
105-
.new(options.merge(matestack_context: context))
106-
.send(component, options.merge(matestack_context: context), &block).to_s
105+
.new(options.merge(context: context, matestack_context: context))
106+
.send(component, options.merge(context: context, matestack_context: context), &block).to_s
107107
end
108108
end
109109
end

app/lib/matestack/ui/core/has_view_context.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ module Matestack::Ui::Core::HasViewContext
22
def initialize(*args)
33
super
44
@view_context = @options.dig(:context, :view_context)
5+
unless @view_context
6+
@view_context = @options.dig(:matestack_context, :controller)&.view_context
7+
end
58
end
6-
79
def method_missing(*args, &block)
810
if @view_context.respond_to? args.first
911
@view_context.send(*args, &block)
1012
else
1113
raise NameError, "NameError: undefined method or local variable `#{args.first}' for #{self.class.name}"
1214
end
1315
end
14-
end
16+
end

app/lib/matestack/ui/core/rendering/main_renderer.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ def render(controller_instance, page_class, options)
6161
end
6262
end
6363

64+
# needs refactoring!
65+
# we shouldn't pass in the parts of the controller_instance and the instance itself
6466
def create_context_hash(controller_instance)
6567
{
6668
view_context: controller_instance.view_context,
6769
params: controller_instance.params,
68-
request: controller_instance.request
70+
request: controller_instance.request,
71+
controller: controller_instance # if this is not included here, rails route helpers will fail with undefined method `url_options' for nil:NilClass in some cases
6972
}
7073
end
7174

docs/reactive_apps/100-rails_integration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Matestack's JavaScript needs to be integrated into your Rails application in ord
1111
Add 'matestack-ui-core' to your `package.json` by running:
1212

1313
```
14-
$ yarn add https://github.com/matestack/matestack-ui-core#v1.1.0
14+
$ yarn add https://github.com/matestack/matestack-ui-core#v1.2.0
1515
$ yarn install
1616
```
1717

docs/reactive_apps/1000-tutorial/01_setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ to start the application. Now visit [localhost:3000](http://localhost:3000/) and
6060

6161
To install matestack, run `gem install matestack-ui-core` or add `gem 'matestack-ui-core'` to your Gemfile and run `bundle install`.
6262

63-
For a complete setup with Webpacker, you also need to run `yarn add https://github.com/matestack/matestack-ui-core#v1.1.0` followed by `yarn install`.
63+
For a complete setup with Webpacker, you also need to run `yarn add https://github.com/matestack/matestack-ui-core#v1.2.0` followed by `yarn install`.
6464

6565
Then, add
6666

docs/reactive_components/100-rails_integration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Matestack's JavaScript needs to be integrated into your Rails application in ord
99
Add 'matestack-ui-core' to your `package.json` by running:
1010

1111
```
12-
$ yarn add https://github.com/matestack/matestack-ui-core#v1.1.0
12+
$ yarn add https://github.com/matestack/matestack-ui-core#v1.2.0
1313
$ yarn install
1414
```
1515

docs/start/100-installation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you want to use Matestack's optional reactivity features, please follow this
99
Add 'matestack-ui-core' to your Gemfile
1010

1111
```ruby
12-
gem 'matestack-ui-core', '~> 1.1'
12+
gem 'matestack-ui-core', '~> 1.2'
1313
```
1414

1515
and run

docs/ui_components/100-rails_integration/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ The easiest way to integrate Matestack is by creating custom components and usin
1414

1515
This is a perfect place to start refactoring our application to use matestack. It's easy to start from the inside out, first replacing parts of your UI with components. As partials already are used to structure your UI in smaller reusable parts they are a perfect starting point. So let's refactor our product teaser into a custom component.
1616

17-
After successfully following the [installation guide](/docs/start/100-installation/README.md) we can start. Remember to set the id "matestack-ui" in your corresponding layout.
17+
After successfully following the [installation guide](/docs/start/100-installation/README.md) we can start.
1818

1919
Start by creating a file called `teaser.rb` in `app/matestack/components/products/teaser.rb`. Placement of this file is as you see similar to our partial. In this file we implement our component in pure ruby as follows:
2020

2121
```ruby
2222
class Components::Products::Teaser < Matestack::Ui::Component
23-
include ::Rails.application.routes.url_helpers
2423

2524
requires :product
2625

@@ -37,7 +36,7 @@ class Components::Products::Teaser < Matestack::Ui::Component
3736
end
3837
```
3938

40-
We inherit from `Matestack::Ui::Component` to create our teaser component. As it should display product informations it requires a product. We can access this product through a getter method `product`. To access Rails url helpers we have to include `Rails.application.routes.url_helpers` as components usually get access to them through the pages but we render our component outside a Matestack page. Now we have now a teaser component, but in order to use it we have to register it and include our registration in our `ApplicationController`.
39+
We inherit from `Matestack::Ui::Component` to create our teaser component. As it should display product informations it requires a product. We can access this product through a getter method `product`. Now we have now a teaser component, but in order to use it we have to register it and include our registration in our `ApplicationController`.
4140

4241
Let's register our component by creating a component registry in `app/matestack/components/registry.rb`.
4342

0 commit comments

Comments
 (0)