representative_view 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,10 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in representative_view.gemspec
4
4
  gemspec
5
5
 
6
+ if ENV["ACTIONPACK_VERSION"]
7
+ gem "actionpack", ENV["ACTIONPACK_VERSION"]
8
+ end
9
+
6
10
  group :test do
7
11
  gem "rake"
8
12
  gem "rspec", "~> 2.0.1"
@@ -0,0 +1,24 @@
1
+ require 'representative_view/view_helpers'
2
+
3
+ module RepresentativeView
4
+
5
+ class ActionPack2Handler < ActionView::TemplateHandler
6
+
7
+ include ActionView::TemplateHandlers::Compilable
8
+
9
+ def compile(template)
10
+ require 'representative/json'
11
+ require 'representative/nokogiri'
12
+ <<-RUBY
13
+ representative_view do |r|
14
+ #{template.source}
15
+ end
16
+ RUBY
17
+ end
18
+
19
+ end
20
+
21
+
22
+ end
23
+
24
+ ActionView::Template.register_template_handler(:rep, RepresentativeView::ActionPack2Handler)
@@ -0,0 +1,25 @@
1
+ require 'representative_view/view_helpers'
2
+
3
+ module RepresentativeView
4
+
5
+ class ActionPack3Handler < ActionView::Template::Handler
6
+
7
+ include ActionView::Template::Handlers::Compilable
8
+
9
+ self.default_format = Mime::XML
10
+
11
+ def compile(template)
12
+ require 'representative/json'
13
+ require 'representative/nokogiri'
14
+ <<-RUBY
15
+ representative_view do |r|
16
+ #{template.source}
17
+ end
18
+ RUBY
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+ ActionView::Template.register_template_handler(:rep, RepresentativeView::ActionPack3Handler)
@@ -1,3 +1,3 @@
1
1
  module RepresentativeView
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,28 +2,14 @@ require 'action_view'
2
2
 
3
3
  module RepresentativeView
4
4
 
5
- class TemplateHandler < ActionView::Template::Handler
6
-
7
- include ActionView::Template::Handlers::Compilable
8
-
9
- self.default_format = Mime::XML
10
-
11
- def compile(template)
12
- require 'representative/json'
13
- require 'representative/nokogiri'
14
- <<-RUBY
15
- representative_view do |r|
16
- #{template.source}
17
- end
18
- RUBY
19
- end
20
-
21
- end
22
-
23
5
  module ViewHelpers
24
6
 
25
7
  def mime_type
26
- format_extension = formats.first
8
+ if respond_to?(:template_format)
9
+ format_extension = template_format
10
+ else
11
+ format_extension = formats.first
12
+ end
27
13
  Mime::Type.lookup_by_extension(format_extension.to_s) || begin
28
14
  raise "unrecognised format #{format_extension.inspect}"
29
15
  end
@@ -51,10 +37,8 @@ module RepresentativeView
51
37
 
52
38
  end
53
39
 
54
- ActionView::Template.register_template_handler(:rep, RepresentativeView::TemplateHandler)
55
-
56
40
  class ActionView::Base
57
41
 
58
42
  include RepresentativeView::ViewHelpers
59
43
 
60
- end
44
+ end
@@ -1 +1,2 @@
1
- require 'representative_view/template_handler'
1
+ require "action_pack/version"
2
+ require "representative_view/action_pack_#{ActionPack::VERSION::MAJOR}_handler"
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.platform = Gem::Platform::RUBY
15
15
 
16
16
  gem.add_runtime_dependency("representative", "~> 0.3.1")
17
- gem.add_runtime_dependency("actionpack", "~> 3.0.1")
17
+ gem.add_runtime_dependency("actionpack", "> 2.3.0", "< 4.0.0")
18
18
  gem.add_runtime_dependency("nokogiri", ">= 1.4.2")
19
19
  gem.add_runtime_dependency("json", ">= 1.4.5")
20
20
 
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'action_controller'
2
3
 
3
4
  describe "a Representative template" do
4
5
 
data/spec/spec_helper.rb CHANGED
@@ -21,7 +21,11 @@ module Fixtures
21
21
 
22
22
  def render(file, format = :xml, assigns = {})
23
23
  @base = ActionView::Base.new($template_dir.to_str, assigns)
24
- @base.lookup_context.freeze_formats([format])
24
+ if @base.respond_to?(:template_format=) # actionpack-2
25
+ @base.template_format = format
26
+ elsif @base.respond_to?(:lookup_context) # actionpack-3
27
+ @base.lookup_context.freeze_formats([format])
28
+ end
25
29
  @base.render(:file => file)
26
30
  end
27
31
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: representative_view
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Williams
@@ -38,14 +38,22 @@ dependencies:
38
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ">"
42
42
  - !ruby/object:Gem::Version
43
- hash: 5
43
+ hash: 3
44
44
  segments:
45
+ - 2
45
46
  - 3
46
47
  - 0
47
- - 1
48
- version: 3.0.1
48
+ version: 2.3.0
49
+ - - <
50
+ - !ruby/object:Gem::Version
51
+ hash: 63
52
+ segments:
53
+ - 4
54
+ - 0
55
+ - 0
56
+ version: 4.0.0
49
57
  prerelease: false
50
58
  type: :runtime
51
59
  requirement: *id002
@@ -96,8 +104,10 @@ files:
96
104
  - README.markdown
97
105
  - Rakefile
98
106
  - lib/representative_view.rb
99
- - lib/representative_view/template_handler.rb
107
+ - lib/representative_view/action_pack_2_handler.rb
108
+ - lib/representative_view/action_pack_3_handler.rb
100
109
  - lib/representative_view/version.rb
110
+ - lib/representative_view/view_helpers.rb
101
111
  - representative_view.gemspec
102
112
  - spec/fixtures/books.rb
103
113
  - spec/representative_view/template_handler_spec.rb