render_with_view 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ce39e99f14378e09ecf2d05a778d02b1184260e19dd9b03faa6495cd19852f9
4
- data.tar.gz: 357ae6071ce03ac319d32e7ee380f8582539c0d2734c382d6a8f81ba102b6d72
3
+ metadata.gz: 8aa151fcf7f21842f19aac1b46c4e94fa525a1ba00beff1f4034042153100faf
4
+ data.tar.gz: ae2a1259739e9bc8c2de8237c0631e2385ec7a3cbef82e4afbea99016e04345c
5
5
  SHA512:
6
- metadata.gz: 9768fc7965cfa1fd6fbcca1f71b6cfd9241af8bacd5b67a15f0a122311d1a1339fbd7ce61efdefe3df9ac1774172074d175f285affba840303e6657efecc84ee
7
- data.tar.gz: 43d43d3d3c2b751b0d82dd2ef6c198a332a1ddad97c04ed85560611ff497a11e7d049f828c9727e268fde9d8c5e66a9e9bc15581e3095700c7fc4bb4a5201231
6
+ metadata.gz: e864e6c20b78d8e6c181a52cd1b1d6daa0d5dd12df50a44422f6757f7be5d54df4598764d6dab9a3adf9ec49c22b8a22181f67fe1a4e71881a3c97e683b8845c
7
+ data.tar.gz: 2044c39043b71feb3a41239ac802bcdd21c73a9b100c1f02180a84b067047cd1644c9f1834fa91c42e2244afc0719a57c94a0cb0cd1843132d98949cd69a7935
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "02:00"
8
+ open-pull-requests-limit: 10
@@ -0,0 +1,17 @@
1
+ name: Tests
2
+ on: [push]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu-latest]
9
+ ruby: ["3.0", "3.1", "3.2"]
10
+ runs-on: ${{ matrix.os }}
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true
17
+ - run: bundle exec rake
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 (2023-08-29)
4
+
5
+ Start of this document.
6
+
7
+ ### Changed:
8
+
9
+ - Use ActiveSupport::Concern instead of locals
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  gemspec
data/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
- require 'bundler'
1
+ require "bundler"
2
+
2
3
  Bundler::GemHelper.install_tasks
3
4
 
4
- require 'rspec/core/rake_task'
5
+ require "rspec/core/rake_task"
6
+
5
7
  RSpec::Core::RakeTask.new(:spec) do |spec|
6
- spec.pattern = 'spec/**/*_spec.rb'
8
+ spec.pattern = "spec/**/*_spec.rb"
7
9
  end
8
- task :default => :spec
9
10
 
11
+ task(:default => :spec)
@@ -1,12 +1,12 @@
1
- RSpec::Matchers.define :set_view_local do |key, expected = nil|
1
+ RSpec::Matchers.define(:set_view_local) do |key, expected = nil|
2
2
  match do |block|
3
3
  block.call if block && block.is_a?(Proc)
4
4
 
5
- value = assigns('__view__').send(key.to_sym) rescue nil
5
+ value = assigns("__view__").send(key.to_sym) rescue nil
6
6
 
7
7
  return !!value unless expected
8
8
 
9
- expect(expected).to eq(value)
9
+ expect(expected).to(eq(value))
10
10
  end
11
11
 
12
12
  supports_block_expectations
@@ -1,3 +1,3 @@
1
1
  module RenderWithView
2
- VERSION = '0.1.3'
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,23 +1,36 @@
1
- require 'render_with_view/version'
2
- require 'render_with_view/half_open_struct'
1
+ require "active_support/concern"
2
+ require "render_with_view/version"
3
+ require "render_with_view/half_open_struct"
3
4
 
4
5
  module RenderWithView
6
+ extend ActiveSupport::Concern
7
+
5
8
  class View < HalfOpenStruct
6
9
  end
7
10
 
8
- def render_with_view *args
9
- if !args.first.is_a?(Hash)
10
- tmpl = args.shift
11
- else
12
- tmpl = action_name
11
+ included do
12
+ helper_method :view
13
+
14
+ def view
15
+ raise ViewNotDefinedError, "View not defined" if !@__view__
16
+
17
+ @__view__
13
18
  end
14
- locals = args.shift
15
- opts = args.shift || {}
16
19
 
17
- # save to ivar for testing purposes
18
- @__view__ = View.new(locals)
20
+ def render_with_view(*args)
21
+ if !args.first.is_a?(Hash)
22
+ tmpl = args.shift
23
+ else
24
+ tmpl = action_name
25
+ end
26
+
27
+ view = args.shift
28
+ opts = args.shift || {}
19
29
 
20
- render tmpl, opts.merge(locals: { view: @__view__ })
30
+ # save to ivar for testing purposes
31
+ @__view__ = View.new(view)
32
+
33
+ render(tmpl, opts)
34
+ end
21
35
  end
22
36
  end
23
-
@@ -2,18 +2,18 @@
2
2
  require File.expand_path("../lib/render_with_view/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = 'render_with_view'
6
- s.summary = 'Be explicit about what you send to your Rails views'
5
+ s.name = "render_with_view"
6
+ s.summary = "Be explicit about what you send to your Rails views"
7
7
  s.version = RenderWithView::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ['Mikkel Malmberg']
10
- s.email = ['mikkel@brnbw.com']
11
- s.homepage = 'https://github.com/mikker/render_with_view'
12
- s.license = 'MIT'
9
+ s.authors = ["Mikkel Malmberg"]
10
+ s.email = ["mikkel@brnbw.com"]
11
+ s.homepage = "https://github.com/mikker/render_with_view"
12
+ s.license = "MIT"
13
13
 
14
- s.add_dependency 'rails'
15
- s.add_development_dependency 'rspec'
14
+ s.add_dependency("rails")
15
+ s.add_development_dependency("rspec")
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
- s.require_path = "lib"
18
+ s.require_path = "lib"
19
19
  end
@@ -1,13 +1,13 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module RenderWithView
4
4
  RSpec.describe HalfOpenStruct do
5
5
  it "can be initialized with a hash, and values read and written" do
6
6
  s = HalfOpenStruct.new(name: "Joe")
7
- expect(s.name).to eq "Joe"
7
+ expect(s.name).to eq("Joe")
8
8
 
9
9
  s.age = 42
10
- expect(s.age).to eq 42
10
+ expect(s.age).to eq(42)
11
11
  end
12
12
 
13
13
  it "raises trying to read an unknown value" do
@@ -16,7 +16,7 @@ module RenderWithView
16
16
  expect { s.age }.to raise_error("Unknown key: age")
17
17
 
18
18
  s.age = 42
19
- expect(s.age).to eq 42
19
+ expect(s.age).to eq(42)
20
20
  end
21
21
 
22
22
  it "raises for unknown methods" do
@@ -28,18 +28,18 @@ module RenderWithView
28
28
  # Considered an API like "s.age?" but that's ambiguous with undefined vs. falsy values.
29
29
  it "lets you query for values being defined" do
30
30
  s = HalfOpenStruct.new
31
- expect(s.include?(:age)).to be false
31
+ expect(s.include?(:age)).to be(false)
32
32
 
33
33
  s.age = 42
34
- expect(s.include?(:age)).to be true
34
+ expect(s.include?(:age)).to be(true)
35
35
  end
36
36
 
37
37
  it "lets you fetch values with a fallback" do
38
38
  s = HalfOpenStruct.new
39
- expect(s.fetch(:age, :fallback)).to eq :fallback
39
+ expect(s.fetch(:age, :fallback)).to eq(:fallback)
40
40
 
41
41
  s.age = 42
42
- expect(s.fetch(:age, :fallback)).to eq 42
42
+ expect(s.fetch(:age, :fallback)).to eq(42)
43
43
  end
44
44
  end
45
45
  end
@@ -1,21 +1,21 @@
1
- require 'spec_helper'
2
- require 'render_with_view/rspec_matcher'
1
+ require "spec_helper"
2
+ require "render_with_view/rspec_matcher"
3
3
 
4
- RSpec.describe 'RSpec matcher' do
4
+ RSpec.describe "RSpec matcher" do
5
5
  let(:ctrl) { FakeController.new }
6
- subject { ctrl.render_with_view :index, thing: 1 }
6
+ subject { ctrl.render_with_view(:index, thing: 1) }
7
7
 
8
8
  # short form
9
- it { should set_view_local :thing }
10
- it { should_not set_view_local :other_thing }
9
+ it { should(set_view_local(:thing)) }
10
+ it { should_not(set_view_local(:other_thing)) }
11
11
 
12
12
  # long form
13
13
  it "takes and matches arguments" do
14
- expect(subject).to set_view_local(:thing, 1)
15
- expect(subject).to_not set_view_local(:thing, 2)
14
+ expect(subject).to(set_view_local(:thing, 1))
15
+ expect(subject).to_not(set_view_local(:thing, 2))
16
16
  end
17
17
 
18
- def assigns key
18
+ def assigns(key)
19
19
  ctrl.instance_variable_get("@#{key}".to_sym)
20
20
  end
21
21
  end
@@ -1,50 +1,48 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  RSpec.describe RenderWithView do
4
4
 
5
5
  describe "#render_with_view" do
6
6
  it "calls render with template and assigned view" do
7
- user = { id: 1 }
7
+ user = {id: 1}
8
8
  ctrl = FakeController.new
9
9
 
10
- ctrl.render_with_view :index, user: user
10
+ ctrl.render_with_view(:index, user: user)
11
11
 
12
12
  tmpl, args = ctrl.calls.last
13
- expect(tmpl).to eq :index
14
- expect(args[:locals][:view].user).to eq(user)
13
+ expect(tmpl).to(eq(:index))
15
14
  end
16
15
 
17
16
  it "defaults to action_name template" do
18
- user = { id: 1 }
17
+ user = {id: 1}
19
18
  ctrl = FakeController.new
20
19
 
21
- ctrl.render_with_view user: user
20
+ ctrl.render_with_view(user: user)
22
21
 
23
22
  tmpl, * = ctrl.calls.last
24
- expect(tmpl).to eq :new
23
+ expect(tmpl).to(eq(:new))
25
24
  end
26
25
 
27
26
  it "saves to an instance var behind the scenes" do
28
- user = { id: 1 }
27
+ user = {id: 1}
29
28
  ctrl = FakeController.new
30
29
 
31
- ctrl.render_with_view :index, user: user
30
+ ctrl.render_with_view(:index, user: user)
32
31
 
33
32
  ivar = ctrl.instance_variable_get(:@__view__)
34
- expect(ivar).to be_a RenderWithView::View
35
- expect(ivar.user).to eq user
33
+ expect(ivar).to(be_a(RenderWithView::View))
34
+ expect(ivar.user).to(eq(user))
36
35
  end
37
36
 
38
37
  it "includes options" do
39
- user = { id: 1 }
40
- opts = { status: 401 }
38
+ user = {id: 1}
39
+ opts = {status: 401}
41
40
  ctrl = FakeController.new
42
41
 
43
42
  ctrl.render_with_view(:edit, {user: user}, opts)
44
43
  tmpl, opts = ctrl.calls.last
45
- expect(tmpl).to eq :edit
46
- expect(opts[:status]).to eq(401)
44
+ expect(tmpl).to(eq(:edit))
45
+ expect(opts[:status]).to(eq(401))
47
46
  end
48
47
  end
49
-
50
48
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
- require 'rspec/core'
2
- require 'render_with_view'
1
+ require "rspec/core"
2
+ require "render_with_view"
3
3
 
4
4
  class FakeController
5
+ def self.helper_method(*args)
6
+ end
7
+
5
8
  include RenderWithView
6
9
 
7
10
  attr_reader :calls
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_with_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-08 00:00:00.000000000 Z
11
+ date: 2023-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,14 +38,17 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
41
+ description:
42
42
  email:
43
43
  - mikkel@brnbw.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".github/dependabot.yml"
49
+ - ".github/workflows/test.yml"
48
50
  - ".gitignore"
51
+ - CHANGELOG.md
49
52
  - Gemfile
50
53
  - LICENSE
51
54
  - README.md
@@ -63,7 +66,7 @@ homepage: https://github.com/mikker/render_with_view
63
66
  licenses:
64
67
  - MIT
65
68
  metadata: {}
66
- post_install_message:
69
+ post_install_message:
67
70
  rdoc_options: []
68
71
  require_paths:
69
72
  - lib
@@ -78,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
81
  - !ruby/object:Gem::Version
79
82
  version: '0'
80
83
  requirements: []
81
- rubygems_version: 3.0.3
82
- signing_key:
84
+ rubygems_version: 3.4.19
85
+ signing_key:
83
86
  specification_version: 4
84
87
  summary: Be explicit about what you send to your Rails views
85
88
  test_files: []