Skip to content

Commit b0293ad

Browse files
committed
Add view helper props_options
A small shorthand for Props::Options.new. Now we can do ``` json.note props_options .partial(“club_notes/notes”, locals: {club_note: @club_note} .fragment(“club_note_#{@club_note.id}”) ```
1 parent 073de75 commit b0293ad

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

lib/props_template.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require "props_template/searcher"
1111
require "props_template/handler"
1212
require "props_template/options"
13+
require "props_template/helper"
1314
require "props_template/version"
1415

1516
require "active_support"

lib/props_template/helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Props
2+
module Helper
3+
def props_options
4+
Props::Options.new
5+
end
6+
end
7+
end

lib/props_template/railtie.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Railtie < ::Rails::Railtie
66
initializer :props_template do
77
ActiveSupport.on_load :action_view do
88
ActionView::Template.register_template_handler :props, Props::Handler
9+
ActionView::Base.include Props::Helper
910
require "props_template/dependency_tracker"
1011
require "props_template/layout_patch"
1112
require "props_template/partial_patch"

spec/helper_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require_relative "support/helper"
2+
require_relative "support/rails_helper"
3+
4+
RSpec.describe "Props::Helper" do
5+
it "returns Props::Options instance" do
6+
json = render(<<~PROPS)
7+
opts = props_options
8+
json.is_a_props_options opts.is_a? Props::Options
9+
PROPS
10+
11+
expect(json).to eql_json({is_a_props_options: true})
12+
end
13+
end

spec/support/rails_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
require "action_dispatch"
1212

1313
class FakeView < ActionView::Base
14+
include Props::Helper
15+
1416
# include Rails.application.routes.url_helpers
1517
# undef_method :fragment_name_with_digest if method_defined? :fragment_name_with_digest
1618
# undef_method :cache_fragment_name if method_defined? :cache_fragment_name

0 commit comments

Comments
 (0)