renderit 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -24,6 +24,6 @@ In order to use those tempates, default view or layout have to be present. You w
24
24
 
25
25
  In order to use this gem with rails 2.3.*, you just have to put 'config.gem "renderit"' string in config/environment.rb file.
26
26
 
27
- In order to user this gem with rails 3, you have to require 'renderit' gem in Gemfile and create some file (I prefer renderit.rb) in config/initializers folder where 'RenderIt.load_config' line should be present.
27
+ In order to user this gem with rails 3, you have to require 'renderit' gem in Gemfile.
28
28
 
29
29
  Copyright (c) 2010 Andrey Romanov. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.2
data/lib/renderit.rb CHANGED
@@ -4,8 +4,8 @@ class RenderIt
4
4
  'ie' => 'msie (\d+\.\d).*\)(?!\s*opera)',
5
5
  'firefox' => 'gecko.*?firefox\/(\d+\.\d)',
6
6
  'chrome' => 'applewebkit.*?chrome\/(\d+\.\d)',
7
- 'safari' => 'applewebkit.*?version\/(\d+.\d)\.\d(?!\s*mobile).*?safari',
8
- 'safarimobile' => 'applewebkit.*?version\/(\d+.\d)\.\d\smobile.*?safari',
7
+ 'safari' => 'applewebkit.*?version\/(\d+.\d)(?![.\d\s]*mobile)',
8
+ 'safarimobile' => 'applewebkit.*?version\/(\d+.\d)[.\d\s]*mobile.*?safari',
9
9
  'opera' => 'opera.*?version\/(\d+\.\d)'
10
10
  }
11
11
  VERSION_MATCH_REGEXP = Regexp.new("([a-z]+)(.*)", "i")
@@ -36,6 +36,7 @@ class RenderIt
36
36
  return Browser.new(browser_name, version[1])
37
37
  end
38
38
  end
39
+ nil
39
40
  end
40
41
 
41
42
 
@@ -58,7 +59,6 @@ class RenderIt
58
59
  def self.load_config
59
60
  if File.exist?(File.join(Rails.root, 'config/renderit.yml'))
60
61
  renderit_config = YAML::load_file(File.join(Rails.root, 'config/renderit.yml'))
61
-
62
62
  #Loading browsers config
63
63
  browsers_config = renderit_config['browsers']||{}
64
64
  browsers_config.merge!(DEFAULT_BROWSERS_CONFIG)
@@ -85,7 +85,7 @@ class RenderIt
85
85
 
86
86
  write_inheritable_attribute(:templates_config, templates_config)
87
87
  end
88
-
88
+ true
89
89
  end
90
90
 
91
91
  end
@@ -147,6 +147,13 @@ if RAILS_THREE_REGEXP =~ Rails.version # If rails version is 3
147
147
  end
148
148
  end
149
149
 
150
+ class MyRailtie < Rails::Railtie
151
+ initializer "renderit_initialization" do
152
+ RenderIt.load_config
153
+ end
154
+ end
155
+
156
+
150
157
 
151
158
  else # If rails version is 2.3.*
152
159
 
data/renderit.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{renderit}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrey Romanov"]
12
- s.date = %q{2010-08-09}
12
+ s.date = %q{2010-08-16}
13
13
  s.description = %q{Renders different templates depending on browser user_agent.}
14
14
  s.email = %q{judo.ras@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,8 +25,10 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "lib/renderit.rb",
27
27
  "renderit.gemspec",
28
- "test/helper.rb",
29
- "test/test_renderit.rb"
28
+ "spec/config/renderit.yml",
29
+ "spec/renderit_spec.rb",
30
+ "spec/spec_helper.rb",
31
+ "spec/spec_initializer.rb"
30
32
  ]
31
33
  s.homepage = %q{http://github.com/romanoff/renderit}
32
34
  s.rdoc_options = ["--charset=UTF-8"]
@@ -34,8 +36,9 @@ Gem::Specification.new do |s|
34
36
  s.rubygems_version = %q{1.3.7}
35
37
  s.summary = %q{Renders different templates depending on browser user_agent.}
36
38
  s.test_files = [
37
- "test/helper.rb",
38
- "test/test_renderit.rb"
39
+ "spec/spec_helper.rb",
40
+ "spec/renderit_spec.rb",
41
+ "spec/spec_initializer.rb"
39
42
  ]
40
43
 
41
44
  if s.respond_to? :specification_version then
@@ -43,12 +46,12 @@ Gem::Specification.new do |s|
43
46
  s.specification_version = 3
44
47
 
45
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<rspec>, [">= 0"])
47
50
  else
48
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_dependency(%q<rspec>, [">= 0"])
49
52
  end
50
53
  else
51
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rspec>, [">= 0"])
52
55
  end
53
56
  end
54
57
 
@@ -0,0 +1,2 @@
1
+ templates:
2
+ new: chrome>4, firefox>3.5, opera>10.5
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe RenderIt do
4
+
5
+ it "should load config file" do
6
+ RenderIt.load_config.should == true
7
+ end
8
+
9
+ it "should parse Chrome browser user_agent" do
10
+ browser = RenderIt.get_browser("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.9 (KHTML, like Gecko) Chrome/6.0.401.1 Safari/533.9")
11
+ browser.name.should == 'chrome'
12
+ browser.version.should == '6.0'
13
+ end
14
+
15
+ it "should parse Firefox browser user_agent" do
16
+ browser = RenderIt.get_browser("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100416 Mandriva Linux/1.9.2.3-0.2mdv2010.0 (2010.0) Firefox/3.6.3")
17
+ browser.name.should == 'firefox'
18
+ browser.version.should == '3.6'
19
+ end
20
+
21
+ it "should parse IE browser user_agent" do
22
+ browser = RenderIt.get_browser("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)")
23
+ browser.name.should == 'ie'
24
+ browser.version.should == '8.0'
25
+ end
26
+
27
+ it "should parse Opera browser user_agent" do
28
+ browser = RenderIt.get_browser("Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.5.24 Version/10.53")
29
+ browser.name.should == 'opera'
30
+ browser.version.should == '10.5'
31
+ end
32
+
33
+ it "should parse Safari browser user_agent" do
34
+ browser = RenderIt.get_browser("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16")
35
+ browser.name.should == 'safari'
36
+ browser.version.should == '5.0'
37
+ end
38
+
39
+ it "should parse SafariMobile browser user_agent" do
40
+ browser = RenderIt.get_browser("Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; ru-ru) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20")
41
+ browser.name.should == 'safarimobile'
42
+ browser.version.should == '3.1'
43
+ end
44
+
45
+ it "should parse SafariMobile browser user_agent" do
46
+ browser = RenderIt.get_browser("UNDEFINED USER_AGENT")
47
+ browser.should be_nil
48
+ end
49
+
50
+ it "should return 'new' template name" do
51
+ request = create_request("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.9 (KHTML, like Gecko) Chrome/6.0.401.1 Safari/533.9")
52
+ RenderIt.get_template_name(request).should == 'new'
53
+ end
54
+
55
+ it "should return blank template name if browser is old" do
56
+ request = create_request("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)")
57
+ RenderIt.get_template_name(request).should == ''
58
+ end
59
+
60
+ it "should return blank template name if unknown browser" do
61
+ request = create_request("UNDEFINED USER_AGENT")
62
+ RenderIt.get_template_name(request).should == ''
63
+ end
64
+
65
+ end
66
+
67
+ def create_request(user_agent)
68
+ request = Object.new
69
+ request.stub!(:env).and_return({'HTTP_USER_AGENT' => user_agent})
70
+ return request
71
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'yaml'
4
+ require 'spec_initializer'
5
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
6
+ require 'renderit'
@@ -0,0 +1,24 @@
1
+ class Rails
2
+ class Railtie
3
+ end
4
+ def self.version
5
+ '3.0.0.RC'
6
+ end
7
+
8
+ def self.root
9
+ File.dirname(__FILE__)
10
+ end
11
+ end
12
+
13
+
14
+ def write_inheritable_attribute(key, value)
15
+ @attributes ||= {}
16
+ @attributes[key] = value
17
+ end
18
+
19
+ def read_inheritable_attribute(key)
20
+ (@attributes||{})[key]
21
+ end
22
+
23
+ def initializer(*args)
24
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renderit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrey Romanov
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-09 00:00:00 +03:00
18
+ date: 2010-08-16 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: thoughtbot-shoulda
22
+ name: rspec
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
@@ -50,8 +50,10 @@ files:
50
50
  - VERSION
51
51
  - lib/renderit.rb
52
52
  - renderit.gemspec
53
- - test/helper.rb
54
- - test/test_renderit.rb
53
+ - spec/config/renderit.yml
54
+ - spec/renderit_spec.rb
55
+ - spec/spec_helper.rb
56
+ - spec/spec_initializer.rb
55
57
  has_rdoc: true
56
58
  homepage: http://github.com/romanoff/renderit
57
59
  licenses: []
@@ -87,5 +89,6 @@ signing_key:
87
89
  specification_version: 3
88
90
  summary: Renders different templates depending on browser user_agent.
89
91
  test_files:
90
- - test/helper.rb
91
- - test/test_renderit.rb
92
+ - spec/spec_helper.rb
93
+ - spec/renderit_spec.rb
94
+ - spec/spec_initializer.rb
data/test/helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'renderit'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,4 +0,0 @@
1
- require 'helper'
2
-
3
- class TestRenderit < Test::Unit::TestCase
4
- end