render_anywhere 0.0.9 → 0.0.10

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
  SHA1:
3
- metadata.gz: ba3bc90ad284db7753424a01c8beb51f6d6d4ceb
4
- data.tar.gz: 65335839bfef80fa259d6dabfc1ce442cf0695ee
3
+ metadata.gz: 5fc511f1345c16b34abfced3bb7464dc3d99a7e3
4
+ data.tar.gz: d9443fec7d7b0efde78c1d3f73237b731c12b178
5
5
  SHA512:
6
- metadata.gz: 29f012183221054aba41b48c74ce14c4761b620968bac3a46c8a56b9b101dc284acf6364900eb72bbdfdd2fad00ed58aa1ce4d8ea6a9dbec6e989335ba597e6e
7
- data.tar.gz: 93d4a108833e867bf924e1bfe6cd2ee23e7c556977e65408faa40a64b4b99b4a33a5a41d2b8ed33db62ed62cffdf81b446c1ab59a5e7e91d2313a23cc9f2f40d
6
+ metadata.gz: a300e7fca51c72bab15e45f525d3cc0bbb43309a7d6542ca1b3e8762e0d0bc0803f275a77b064ea10de6d353b99763f2d44db8ba4c5c062277f8ef46e0bdb5f7
7
+ data.tar.gz: b23cd116f132cdd50e0a483dbe236a87a814fce80f35ef9cae81901ae49ed8d9e4f9f611b29b687ef076d9987aaa71e3835eb910c944617ae35c53424a071986
data/.gitignore CHANGED
@@ -2,3 +2,6 @@ pkg/*
2
2
  *.gem
3
3
  .bundle
4
4
  Gemfile.lock
5
+ log/
6
+
7
+ gemfiles/*.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise "3.2" do
2
+ gem "rails", "~> 3.2.15"
3
+ gemspec
4
+ end
5
+
6
+ appraise "4.0" do
7
+ gem "rails", "~> 4.0.0"
8
+ gemspec
9
+ end
10
+
11
+ appraise "4.1" do
12
+ gem "rails", "~> 4.1.0"
13
+ gemspec
14
+ end
data/README.md CHANGED
@@ -6,17 +6,22 @@ Out of the box, Rails can render templates in a controller context only. This li
6
6
  Installation
7
7
  ------------------
8
8
 
9
+ ```bash
9
10
  gem install render_anywhere
11
+ ```
10
12
 
11
13
  Usage
12
14
  --------------------
13
15
 
14
16
  Put render_anywhere in your Gemfile:
15
17
 
18
+ ```ruby
16
19
  gem 'render_anywhere', :require => false
20
+ ```
17
21
 
18
22
  In your Rails app, in a rake task, model, background job, or where ever you like, require render_anywhere, include the module and call render with the same arguments as ActionController::Base#render takes. It will return a string.
19
23
 
24
+ ```ruby
20
25
  require 'render_anywhere'
21
26
 
22
27
  class AnyClass
@@ -39,7 +44,14 @@ In your Rails app, in a rake task, model, background job, or where ever you like
39
44
  def set_instance_variable(var, value)
40
45
  set_instance_variable(var, value)
41
46
  end
47
+
48
+ class RenderingController < RenderAnywhere::RenderingController
49
+ # include custom modules here, define accessors, etc. For example:
50
+ attr_accessor :current_user
51
+ helper_method :current_user
52
+ end
42
53
  end
54
+ ```
43
55
 
44
56
  Thanks
45
57
  --------------------
@@ -48,6 +60,13 @@ Thanks
48
60
 
49
61
  The basic approach used here came from [this gist](https://gist.github.com/977181) by [Julien Guimont aka juggy](https://github.com/juggy). Thanks!
50
62
 
63
+ Contributing
64
+ --------------------
65
+
66
+ Run tests with `rake` or `rspec`.
67
+
68
+ Run tests against different versions of rails with `appraisal rake` or `appraisal rspec`.
69
+
51
70
  Author
52
71
  --------------------
53
72
 
@@ -56,4 +75,4 @@ Luke Melia, [@lukemelia](https://twitter.com/lukemelia), [lukemelia.com](http://
56
75
  License
57
76
  --------------------
58
77
 
59
- The MIT License. Copyright (c) 2011, Yapp, Inc.
78
+ The MIT License. Copyright (c) 2011, Yapp, Inc.
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ task :default => [:spec]
7
+
8
+ desc "Run the specs."
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.pattern = "spec/**/*_spec.rb"
11
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2.15"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 4.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 4.1.0"
6
+
7
+ gemspec :path => "../"
@@ -8,6 +8,7 @@ module RenderAnywhere
8
8
  def render(*args)
9
9
  rendering_controller.render_to_string(*args)
10
10
  end
11
+
11
12
  def set_render_anywhere_helpers(*args)
12
13
  args.each do |helper_name|
13
14
  rendering_controller.class_eval do
@@ -15,13 +16,15 @@ module RenderAnywhere
15
16
  end
16
17
  end
17
18
  end
19
+
18
20
  def set_instance_variable(var, value)
19
21
  rendering_controller.class_eval do
20
22
  attr_accessor :"#{var}"
21
23
  end
22
24
  rendering_controller.public_send("#{var}=", value)
23
25
  end
26
+
24
27
  def rendering_controller
25
- @rendering_controller ||= RenderAnywhere::RenderingController.new
28
+ @rendering_controller ||= self.class.const_get("RenderingController").new
26
29
  end
27
30
  end
@@ -1,7 +1,7 @@
1
1
  require 'ostruct'
2
2
 
3
3
  module RenderAnywhere
4
- class RenderingController < AbstractController::Base
4
+ class RenderingController < ActionController::Metal
5
5
  # Include all the concerns we need to make this work
6
6
  include AbstractController::Logger
7
7
  include AbstractController::Rendering
@@ -1,3 +1,3 @@
1
1
  module RenderAnywhere
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -21,4 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  s.add_dependency('rails', '>= 3.0.7')
24
+
25
+ s.add_development_dependency 'rspec'
26
+ s.add_development_dependency 'appraisal'
24
27
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe RenderAnywhere do
4
+
5
+ class UserRenderer
6
+ include RenderAnywhere
7
+
8
+ def initialize(user)
9
+ @user = user
10
+ end
11
+
12
+ def render_ivar
13
+ set_instance_variable(:user, @user)
14
+ render 'spec/views/user_ivar', :layout => false
15
+ end
16
+
17
+ def render_current_user
18
+ rendering_controller.action_name = 'show'
19
+ rendering_controller.controller_name = 'user'
20
+ rendering_controller.current_user = @user
21
+ render 'spec/views/current_user', :layout => false
22
+ end
23
+
24
+ class RenderingController < RenderAnywhere::RenderingController
25
+ attr_accessor :controller_name
26
+ attr_accessor :current_user
27
+ helper_method :current_user
28
+ end
29
+ end
30
+
31
+ class OtherRenderer
32
+ include RenderAnywhere
33
+ end
34
+
35
+ User = Struct.new(:name)
36
+
37
+ let(:me) { User.new("Guzman") }
38
+ subject { UserRenderer.new(me) }
39
+
40
+ context "#rendering_controller" do
41
+ it "creates a RenderingController of the class nested inside the class using RenderAnywhere" do
42
+ expect(subject.rendering_controller).to be_a(UserRenderer::RenderingController)
43
+ end
44
+
45
+ it "creates a RenderingController of default class" do
46
+ expect(OtherRenderer.new.rendering_controller).to be_a(RenderAnywhere::RenderingController)
47
+ end
48
+ end
49
+
50
+ context "#render" do
51
+ it "renders with ivar" do
52
+ expect(subject.render_ivar).to eq("The current user is Guzman.\n")
53
+ end
54
+
55
+ it "renders with render_current_user" do
56
+ expect(subject.render_current_user).to eq("The current user is Guzman.\nThe controller name is user.\nThe controller action is show.\n")
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,42 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+
9
+ require 'bundler/setup'
10
+
11
+ $:.unshift File.expand_path("../../lib", __FILE__)
12
+
13
+ require 'rails'
14
+ require 'action_controller'
15
+
16
+ require 'render_anywhere'
17
+
18
+
19
+ RSpec.configure do |config|
20
+ config.treat_symbols_as_metadata_keys_with_true_values = true
21
+ config.run_all_when_everything_filtered = true
22
+ config.filter_run :focus
23
+
24
+ # Run specs in random order to surface order dependencies. If you find an
25
+ # order dependency and want to debug it, you can fix the order by providing
26
+ # the seed, which is printed after each run.
27
+ # --seed 1234
28
+ config.order = 'random'
29
+ end
30
+
31
+ class TestRailsApp < Rails::Application
32
+ config.secret_key_base = '1234'
33
+ config.eager_load = false if Rails::VERSION::MAJOR == 4
34
+
35
+ initialize!
36
+ end
37
+
38
+ module ApplicationHelper
39
+ end
40
+
41
+ class ApplicationController < ActionController::Base
42
+ end
@@ -0,0 +1,3 @@
1
+ The current user is <%= current_user.name %>.
2
+ The controller name is <%= controller.controller_name %>.
3
+ The controller action is <%= controller.action_name %>.
@@ -0,0 +1 @@
1
+ The current user is <%= @user.name %>.
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: render_anywhere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Melia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.0.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: appraisal
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  description: 'Out of the box, Rails will render templates in a controller context
28
56
  only. This gem allows for calling "render" from anywhere: models, background jobs,
29
57
  rake tasks, you name it.'
@@ -33,15 +61,24 @@ executables: []
33
61
  extensions: []
34
62
  extra_rdoc_files: []
35
63
  files:
36
- - .gitignore
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - Appraisals
37
67
  - Gemfile
38
68
  - LICENCE
39
69
  - README.md
40
70
  - Rakefile
71
+ - gemfiles/3.2.gemfile
72
+ - gemfiles/4.0.gemfile
73
+ - gemfiles/4.1.gemfile
41
74
  - lib/render_anywhere.rb
42
75
  - lib/render_anywhere/rendering_controller.rb
43
76
  - lib/render_anywhere/version.rb
44
77
  - render_anywhere.gemspec
78
+ - spec/lib/render_anywhere_spec.rb
79
+ - spec/spec_helper.rb
80
+ - spec/views/current_user.html.erb
81
+ - spec/views/user_ivar.html.erb
45
82
  homepage: ''
46
83
  licenses:
47
84
  - MIT
@@ -52,18 +89,22 @@ require_paths:
52
89
  - lib
53
90
  required_ruby_version: !ruby/object:Gem::Requirement
54
91
  requirements:
55
- - - '>='
92
+ - - ">="
56
93
  - !ruby/object:Gem::Version
57
94
  version: '0'
58
95
  required_rubygems_version: !ruby/object:Gem::Requirement
59
96
  requirements:
60
- - - '>='
97
+ - - ">="
61
98
  - !ruby/object:Gem::Version
62
99
  version: '0'
63
100
  requirements: []
64
101
  rubyforge_project: render_anywhere
65
- rubygems_version: 2.1.11
102
+ rubygems_version: 2.2.2
66
103
  signing_key:
67
104
  specification_version: 4
68
105
  summary: Render Rails templates to a string from anywhere.
69
- test_files: []
106
+ test_files:
107
+ - spec/lib/render_anywhere_spec.rb
108
+ - spec/spec_helper.rb
109
+ - spec/views/current_user.html.erb
110
+ - spec/views/user_ivar.html.erb