rack-backbone 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CH CH CH CHANGES #
2
2
 
3
+ ## Friday the 11th of October 2013, v0.1.0 ##
4
+
5
+ * Added option `debug` for getting the unminified version of the script, to help with debugging.
6
+
7
+ ----
8
+
3
9
 
4
10
  ## Thursday the 10th of October 2013 ##
5
11
 
data/lib/rack/backbone.rb CHANGED
@@ -55,11 +55,14 @@ STR
55
55
 
56
56
  # @param [Hash] env The rack env hash.
57
57
  # @option options [Symbol] organisation Choose which CDN to use, either :jsdelivr, or :cloudflare (the default). This will override anything set via the `use` statement. Pass in `false` to force use of the local Backbonejs script. `nil` will force choosing the default CDN.
58
+ # @option options [TrueClass] :debug Pass `true` to get the unminified version of the script from the CDN.
58
59
  # @return [String] The HTML script tags to get the CDN.
59
60
  def self.cdn( env, options={} )
60
61
  if env.nil? || env.has_key?(:organisation)
61
62
  fail ArgumentError, "The Rack::Backbone.cdn method needs the Rack environment passed to it, or at the very least, an empty hash."
62
63
  end
64
+
65
+ debug = options.fetch :debug, false
63
66
 
64
67
  organisation = options[:organisation]
65
68
  if organisation.nil?
@@ -68,7 +71,6 @@ STR
68
71
  :media_temple
69
72
  end
70
73
 
71
- warn "organisation = #{organisation.inspect}"
72
74
  unless organisation == false
73
75
  script_src = case organisation
74
76
  when :cloudflare
@@ -78,7 +80,10 @@ STR
78
80
  else
79
81
  CDN::CLOUDFLARE
80
82
  end
81
- %Q!<script src='#{script_src}'></script>\n#{FALLBACK_TOP}#{env["rack.backbone.http_path"]}#{FALLBACK_BOTTOM}!
83
+
84
+ script_src = "#{script_src[0..-8]}.js" if debug
85
+
86
+ %Q!<script src='#{script_src}'></script>\n#{FALLBACK_TOP}#{env["rack.backbone.http_path"]}#{FALLBACK_BOTTOM}!
82
87
  else
83
88
  "<script src='#{env["rack.backbone.http_path"]}'></script>"
84
89
  end
@@ -2,7 +2,7 @@ module Rack
2
2
  class Backbone
3
3
 
4
4
  # the version of this library
5
- VERSION = "0.0.5"
5
+ VERSION = "0.1.0"
6
6
 
7
7
  # the version of Backbone it supports.
8
8
  BACKBONE_VERSION = "1.0.0"
@@ -5,7 +5,14 @@ require_relative "../lib/rack/backbone.rb"
5
5
 
6
6
  class Rack::Backbone # for clarity!
7
7
 
8
+ shared_examples "the debug option is set" do
9
+ it { should_not include expected }
10
+ it { should include unminified }
11
+ it { should_not end_with ".min.js" }
12
+ end
13
+
8
14
  describe "The class methods" do
15
+
9
16
  let(:path) {::File.join(DEFAULT_OPTIONS[:http_path],BACKBONE_FILE_NAME)}
10
17
  let(:env) { {"rack.backbone.http_path" => path} }
11
18
  let(:default_options) { {} }
@@ -14,19 +21,51 @@ describe "The class methods" do
14
21
  context "Given the organisation option" do
15
22
  context "of nil (the default)" do
16
23
  let(:options) { {:organisation => nil } }
17
- it { should == "<script src='#{CDN::CLOUDFLARE}'></script>\n#{FALLBACK_TOP}#{path}#{FALLBACK_BOTTOM}" }
24
+ let(:expected){ "<script src='#{CDN::CLOUDFLARE}'></script>\n#{FALLBACK_TOP}#{path}#{FALLBACK_BOTTOM}"}
25
+ it { should == expected }
26
+ context "and debug" do
27
+ let(:unminified) { "#{CDN::CLOUDFLARE[0..-8]}.js" }
28
+ let(:options) {
29
+ {:organisation => nil, :debug => true }
30
+ }
31
+ it_should_behave_like "the debug option is set"
32
+ end
18
33
  end
19
34
  context "of :jsdelivr" do
20
35
  let(:options) { {:organisation => :jsdelivr } }
21
- it { should == "<script src='#{CDN::JSDELIVR}'></script>\n#{FALLBACK_TOP}#{path}#{FALLBACK_BOTTOM}" }
36
+ let(:expected){ "<script src='#{CDN::JSDELIVR}'></script>\n#{FALLBACK_TOP}#{path}#{FALLBACK_BOTTOM}" }
37
+ it { should == expected }
38
+ context "and debug" do
39
+ let(:unminified) { "#{CDN::JSDELIVR[0..-8]}.js" }
40
+ let(:options) {
41
+ {:organisation => :jsdelivr, :debug => true }
42
+ }
43
+ it_should_behave_like "the debug option is set"
44
+ end
22
45
  end
23
46
  context "of :cloudflare" do
24
47
  let(:options) { {:organisation => :cloudflare } }
25
- it { should == "<script src='#{CDN::CLOUDFLARE}'></script>\n#{FALLBACK_TOP}#{path}#{FALLBACK_BOTTOM}" }
48
+ let(:expected){ "<script src='#{CDN::CLOUDFLARE}'></script>\n#{FALLBACK_TOP}#{path}#{FALLBACK_BOTTOM}"}
49
+ it { should == expected }
50
+ context "and debug" do
51
+ let(:unminified) { "#{CDN::CLOUDFLARE[0..-8]}.js" }
52
+ let(:options) {
53
+ {:organisation => nil, :debug => true }
54
+ }
55
+ it_should_behave_like "the debug option is set"
56
+ end
26
57
  end
27
58
  context "of false, to get the fallback script only" do
28
59
  let(:options) { {:organisation => false } }
29
- it { should == "<script src='#{path}'></script>" }
60
+ let(:expected){ "<script src='#{path}'></script>" }
61
+ it { should == expected }
62
+ context "and debug" do
63
+ let(:unminified) { "#{CDN::CLOUDFLARE[0..-8]}.js" }
64
+ let(:options) {
65
+ {:organisation => false, :debug => true }
66
+ }
67
+ it { should == expected }
68
+ end
30
69
  end
31
70
  end
32
71
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-backbone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-10 00:00:00.000000000 Z
12
+ date: 2013-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -95,7 +95,7 @@ files:
95
95
  - lib/rack/backbone.rb
96
96
  - lib/rack/backbone/version.rb
97
97
  - rack-backbone.gemspec
98
- - spec/rack_jquery_spec.rb
98
+ - spec/rack_backbone_spec.rb
99
99
  - spec/spec_helper.rb
100
100
  - spec/support/shared/all_pages.rb
101
101
  - vendor/assets/javascripts/backbone-1.0.0-min.js
@@ -126,6 +126,6 @@ signing_key:
126
126
  specification_version: 3
127
127
  summary: The description says it all.
128
128
  test_files:
129
- - spec/rack_jquery_spec.rb
129
+ - spec/rack_backbone_spec.rb
130
130
  - spec/spec_helper.rb
131
131
  - spec/support/shared/all_pages.rb