exvo_helpers 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,10 +7,12 @@ Ruby gem providing helper methods for various Exvo apps/services. It takes into
7
7
  Results are from the 'development' Rails environment:
8
8
 
9
9
  ```ruby
10
+ Exvo::Helpers.cdn_host => 'www.exvo.local'
10
11
  Exvo::Helpers.cfs_host => 'cfs.exvo.local'
11
12
  Exvo::Helpers.desktop_host => 'www.exvo.local'
12
13
  Exvo::Helpers.themes_host => 'themes.exvo.local'
13
14
 
15
+ Exvo::Helpers.cdn_uri => 'http://www.exvo.local'
14
16
  Exvo::Helpers.cfs_uri => 'http://cfs.exvo.local'
15
17
  Exvo::Helpers.desktop_uri => 'http://www.exvo.local'
16
18
  Exvo::Helpers.themes_uri => 'http://themes.exvo.local'
@@ -29,6 +31,7 @@ Exvo::Helpers.auth_uri => 'http://exvo.auth.local'
29
31
  There are two ways to do it. One is by the means of ENV variables (preferred one):
30
32
 
31
33
  ```ruby
34
+ ENV['CDN_HOST'] = 'test.cdn.exvo.com'
32
35
  ENV['CFS_HOST'] = 'test.cfs.exvo.com'
33
36
  ENV['DESKTOP_HOST'] = 'test.exvo.com'
34
37
  ENV['THEMES_HOST'] = 'test.themes.exvo.com'
@@ -37,6 +40,7 @@ ENV['THEMES_HOST'] = 'test.themes.exvo.com'
37
40
  The other one is to set it in the application's config file:
38
41
 
39
42
  ```ruby
43
+ Exvo::Helpers.cdn_host = 'test.cfs.exvo.com'
40
44
  Exvo::Helpers.cfs_host = 'test.cfs.exvo.com'
41
45
  Exvo::Helpers.desktop_host = 'test.exvo.com'
42
46
  Exvo::Helpers.themes_host = 'test.themes.exvo.com'
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
+ s.add_dependency 'rails', ['~> 3.0']
20
+
19
21
  s.add_development_dependency 'rspec', ['>= 2.7']
20
22
  s.add_development_dependency 'guard', ['>= 0.8.0']
21
23
  s.add_development_dependency 'guard-rspec', ['>= 0.4.0']
@@ -1,2 +1,7 @@
1
1
  require "exvo_helpers/version"
2
2
  require "exvo_helpers/helpers"
3
+ require "exvo_helpers/view_helpers"
4
+
5
+ module Exvo
6
+ require 'exvo_helpers/railtie' if defined?(Rails)
7
+ end
@@ -2,6 +2,21 @@ module Exvo
2
2
 
3
3
  module Helpers
4
4
 
5
+ # CDN BUNDLES
6
+
7
+ def self.cdn_uri
8
+ "http://#{cdn_host}"
9
+ end
10
+
11
+ def self.cdn_host
12
+ @@cdn_host ||= ENV['CDN_HOST'] || default_opts[env.to_sym][:cdn_host]
13
+ end
14
+
15
+ def self.cdn_host=(host)
16
+ @@cdn_host = host
17
+ end
18
+
19
+
5
20
  # CFS
6
21
 
7
22
  def self.cfs_uri
@@ -85,21 +100,25 @@ module Exvo
85
100
  def self.default_opts
86
101
  {
87
102
  :production => {
103
+ :cdn_host => 'cdn.exvo.com',
88
104
  :cfs_host => 'cfs.exvo.com',
89
105
  :desktop_host => 'www.exvo.com',
90
106
  :themes_host => 'themes.exvo.com'
91
107
  },
92
108
  :staging => {
109
+ :cdn_host => 'staging.cdn.exvo.com',
93
110
  :cfs_host => 'staging.cfs.exvo.com',
94
111
  :desktop_host => 'www.exvo.co',
95
112
  :themes_host => 'staging.themes.exvo.com'
96
113
  },
97
114
  :development => {
115
+ :cdn_host => 'www.exvo.local',
98
116
  :cfs_host => 'cfs.exvo.local',
99
117
  :desktop_host => 'www.exvo.local',
100
118
  :themes_host => 'themes.exvo.local'
101
119
  },
102
120
  :test => {
121
+ :cdn_host => 'www.exvo.local',
103
122
  :cfs_host => 'cfs.exvo.local',
104
123
  :desktop_host => 'www.exvo.local',
105
124
  :themes_host => 'themes.exvo.local'
@@ -0,0 +1,11 @@
1
+ require "rails"
2
+
3
+ module Exvo
4
+ class Railtie < Rails::Railtie
5
+ initializer "exvo_helpers.add_to_rails_view_helpers" do |app|
6
+ ActiveSupport.on_load :action_view do
7
+ ActionView::Base.send :include, Exvo::ViewHelpers
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ExvoHelpers
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,19 @@
1
+ module Exvo
2
+
3
+ module ViewHelpers
4
+
5
+ # special link starting with '//' in production so that the webserver can choose between HTTP and HTTPS
6
+ def javascript_bundle_include_tag(bundle)
7
+ case Exvo::Helpers.env.to_sym
8
+ when :production
9
+ javascript_include_tag "//#{ Exvo::Helpers.cdn_host }/javascripts/#{bundle}.js"
10
+ when :staging
11
+ javascript_include_tag "http://#{ Exvo::Helpers.cdn_host }/javascripts/#{bundle}.js"
12
+ else
13
+ javascript_include_tag "http://#{ Exvo::Helpers.cdn_host }/javascripts/bundles/#{bundle}.js"
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Exvo do
3
+ describe Exvo::Helpers do
4
4
 
5
5
  describe ".env class method" do
6
6
  it "returns 'production' when Rails.env is set to 'production'" do
@@ -18,47 +18,55 @@ describe Exvo do
18
18
 
19
19
  describe "host methods in production environment" do
20
20
  before do
21
- Exvo::Helpers.should_receive(:env).and_return('production')
21
+ Exvo::Helpers.stub(:env).and_return('production')
22
22
  end
23
23
 
24
- specify { Exvo::Helpers.themes_host.should eql('themes.exvo.com') }
24
+ specify { Exvo::Helpers.cdn_host.should eql('cdn.exvo.com') }
25
25
  specify { Exvo::Helpers.cfs_host.should eql('cfs.exvo.com') }
26
26
  specify { Exvo::Helpers.desktop_host.should eql('www.exvo.com') }
27
+ specify { Exvo::Helpers.themes_host.should eql('themes.exvo.com') }
27
28
  end
28
29
 
29
30
  describe "ENV setting overrides the defaults" do
31
+ let(:cdn_host) { "test.cdn.exvo.com" }
30
32
  let(:cfs_host) { "test.cfs.exvo.com" }
31
33
  let(:desktop_host) { "test.exvo.com" }
32
34
  let(:themes_host) { "test.themes.exvo.com" }
33
35
 
34
36
  before do
35
37
  # clear any previous memoization
38
+ Exvo::Helpers.cdn_host = nil
36
39
  Exvo::Helpers.cfs_host = nil
37
40
  Exvo::Helpers.desktop_host = nil
38
41
  Exvo::Helpers.themes_host = nil
39
42
 
40
43
  # set ENV
44
+ ENV["CDN_HOST"] = cdn_host
41
45
  ENV["CFS_HOST"] = cfs_host
42
46
  ENV["DESKTOP_HOST"] = desktop_host
43
47
  ENV["THEMES_HOST"] = themes_host
44
48
  end
45
49
 
50
+ specify { Exvo::Helpers.cdn_host.should eql(cdn_host) }
46
51
  specify { Exvo::Helpers.cfs_host.should eql(cfs_host) }
47
52
  specify { Exvo::Helpers.desktop_host.should eql(desktop_host) }
48
53
  specify { Exvo::Helpers.themes_host.should eql(themes_host) }
49
54
  end
50
55
 
51
56
  describe "setting host directly overrides the defaults" do
57
+ let(:cdn_host) { "new.cdn.exvo.com" }
52
58
  let(:cfs_host) { "new.cfs.exvo.com" }
53
59
  let(:desktop_host) { "new.exvo.com" }
54
60
  let(:themes_host) { "new.themes.exvo.com" }
55
61
 
56
62
  before do
63
+ Exvo::Helpers.cdn_host = cdn_host
57
64
  Exvo::Helpers.cfs_host = cfs_host
58
65
  Exvo::Helpers.desktop_host = desktop_host
59
66
  Exvo::Helpers.themes_host = themes_host
60
67
  end
61
68
 
69
+ specify { Exvo::Helpers.cdn_host.should eql(cdn_host) }
62
70
  specify { Exvo::Helpers.cfs_host.should eql(cfs_host) }
63
71
  specify { Exvo::Helpers.desktop_host.should eql(desktop_host) }
64
72
  specify { Exvo::Helpers.themes_host.should eql(themes_host) }
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ class SpecViewHelper
4
+ include Exvo::ViewHelpers
5
+ end
6
+
7
+ describe Exvo::ViewHelpers do
8
+
9
+ describe "javascript_bundle_include_tag" do
10
+
11
+ let(:view_helper) { SpecViewHelper.new }
12
+
13
+ it "should return the javascript_include_tag based on env" do
14
+ Exvo::Helpers.stub(:env).and_return('production')
15
+ view_helper.should_receive(:javascript_include_tag).with("//cdn.exvo.com/javascripts/plugins.js")
16
+ view_helper.javascript_bundle_include_tag("plugins")
17
+ end
18
+ end
19
+
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exvo_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-27 00:00:00.000000000Z
12
+ date: 2011-11-18 00:00:00.000000000Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &78439060 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *78439060
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rspec
16
- requirement: &79583560 !ruby/object:Gem::Requirement
27
+ requirement: &78438710 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '2.7'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *79583560
35
+ version_requirements: *78438710
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: guard
27
- requirement: &79583300 !ruby/object:Gem::Requirement
38
+ requirement: &78438360 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: 0.8.0
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *79583300
46
+ version_requirements: *78438360
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: guard-rspec
38
- requirement: &79583060 !ruby/object:Gem::Requirement
49
+ requirement: &78438020 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 0.4.0
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *79583060
57
+ version_requirements: *78438020
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rb-fsevent
49
- requirement: &79582870 !ruby/object:Gem::Requirement
60
+ requirement: &78437820 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *79582870
68
+ version_requirements: *78437820
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: rb-inotify
60
- requirement: &79582640 !ruby/object:Gem::Requirement
71
+ requirement: &78437580 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,7 +76,7 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *79582640
79
+ version_requirements: *78437580
69
80
  description: Ruby gem providing helper *_uri/*_host methods for Exvo services/apps
70
81
  like DESKTOP/CFS/AUTH/THEMES.
71
82
  email:
@@ -81,8 +92,11 @@ files:
81
92
  - exvo_helpers.gemspec
82
93
  - lib/exvo_helpers.rb
83
94
  - lib/exvo_helpers/helpers.rb
95
+ - lib/exvo_helpers/railtie.rb
84
96
  - lib/exvo_helpers/version.rb
97
+ - lib/exvo_helpers/view_helpers.rb
85
98
  - spec/exvo_helpers/helpers_spec.rb
99
+ - spec/exvo_helpers/view_helpers_spec.rb
86
100
  - spec/spec_helper.rb
87
101
  homepage: https://github.com/Exvo/exvo_helpers/
88
102
  licenses: []