planbcd-rails 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e92e7c57c1883b8432fd5a3c1b86aa4450ab48c6
4
+ data.tar.gz: bb7d6d59dd227b1d9e9d0403166de2b4d84428fe
5
+ SHA512:
6
+ metadata.gz: 189066d4b57ec15859d892fb3502d8d9fa2bfcb62ef1f3d2620439644097c71324c5c0c3e624960590a754df8698467feff6fd0c903fb62a6989e313a118e9c6
7
+ data.tar.gz: 5e49f5cbd9d0cee7420d5832eb52380877f19ee719b2b8caa335a1788e24df1b657c62b05c0b3313d41de49ed2baf40e445f99d1be4ff10e9b5eed836fcc640f
data/.gitignore ADDED
@@ -0,0 +1,33 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /log/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ ## Misc
29
+ Gemfile.lock
30
+ gemfiles/*.lock
31
+ .ruby-version
32
+ .ruby-gemset
33
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ gemfile:
8
+ - gemfiles/gemfile
9
+ - gemfiles/rails.3.1.x.gemfile
10
+ - gemfiles/rails.3.2.x.gemfile
11
+ - gemfiles/rails.4.0.x.gemfile
12
+ - gemfiles/rails.4.1.x.gemfile
13
+
14
+ script: "bundle exec rake spec"
15
+
16
+ branches:
17
+ only:
18
+ - master
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Daisuke Taniwaki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # planbcd-rails
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/planbcd-rails.png)](https://rubygems.org/gems/planbcd-rails) [![Build Status](https://secure.travis-ci.org/dtaniwaki/planbcd-rails.png?branch=master)](http://travis-ci.org/dtaniwaki/planbcd-rails) [![Coverage Status](https://coveralls.io/repos/dtaniwaki/planbcd-rails/badge.png)](https://coveralls.io/r/dtaniwaki/planbcd-rails)
4
+
5
+ PlanBCD For Rails! So great.
6
+
7
+ ## Installation
8
+
9
+ Add the planbcd-rails gem to your Gemfile.
10
+
11
+ ```ruby
12
+ gem "planbcd-rails"
13
+ ```
14
+
15
+ And run `bundle install`. The rest of the installation depends on
16
+ whether the asset pipeline is being used.
17
+
18
+ Then, initialize planbcd.
19
+
20
+ ```ruby
21
+ bundle exec rails generate planbcd:install
22
+ ```
23
+
24
+ ## TODO
25
+
26
+ - Add an option to insert the PlanBCD tag to any page
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new [Pull Request](../../pull/new/master)
35
+
36
+ ## Copyright
37
+
38
+ Copyright (c) 2014 Daisuke Taniwaki. See [LICENSE](LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+ task :default => :spec
data/gemfiles/gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path => '../'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '~> 3.1.0'
4
+ gemspec :path => '../'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '~> 3.2.0'
4
+ gemspec :path => '../'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '~> 4.0.0'
4
+ gemspec :path => '../'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '~> 4.1.0'
4
+ gemspec :path => '../'
@@ -0,0 +1,15 @@
1
+ require 'rails'
2
+
3
+ module PlanBCD
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ namespace 'planbcd:install'
7
+ desc "Creates configuration file for PlanBCD."
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ def copy_initializer
11
+ template "planbcd.rb", "config/initializers/planbcd.rb"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ PlanBCD::Rails.configure do |c|
2
+ # Set your JS file found in your offer.
3
+ # c.js = "//localhost/abc/def.js"
4
+ # c.js = proc { |controller| controller.is_something? ? "//localhost/abc/def_1.js" : "//localhost/abc/def_2.js" }
5
+ end
@@ -0,0 +1,7 @@
1
+ module PlanBCD
2
+ module Rails
3
+ class Configuration
4
+ attr_accessor :js
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module PlanBCD
2
+ module Rails
3
+ class Exception < ::Exception; end
4
+ class RuntimeError < Exception; end
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/railtie'
2
+ require 'planbcd/rails/view_helpers'
3
+
4
+ module PlanBCD
5
+ module Rails
6
+ class Railtie < ::Rails::Railtie
7
+ initializer "planbcd-rails" do
8
+ ActionView::Base.send :include, ViewHelpers
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module PlanBCD
2
+ module Rails
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require 'active_support/core_ext/string/output_safety'
2
+ require 'active_support/core_ext/object/blank'
3
+
4
+ module PlanBCD
5
+ module Rails
6
+ module ViewHelpers
7
+ def pbcd_init
8
+ unless js = PlanBCD::Rails.configuration.js.presence
9
+ raise PlanBCD::Rails::RuntimeError, "PlanBCD Javascript is not loaded."
10
+ end
11
+
12
+ if js.respond_to?(:call)
13
+ js = js.call(controller)
14
+ else
15
+ js.gsub!(%r|^https?://|, '//')
16
+ end
17
+
18
+ s = '<script type="text/javascript">'
19
+ s += %Q~(function(){!function(a,b,c,d,e){return d="http"+("https:"===c?"s":"")+":"+d,a.planBCDObject=e,a[e]||(a[e]=function(){var b;return((b=a[e]).q||(b.q=[])).push(arguments),a[e].l=1*new Date}),b.write(unescape('%3Cscript type="text/javascript" src="'+d+'"%3E%3C/script%3E'))}(window,document,document.location.protocol,"#{js}","pbcd")}).call(this);~
20
+ s += '</script>'
21
+
22
+ s.html_safe
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ require 'planbcd/rails/configuration'
2
+ require 'planbcd/rails/error'
3
+ require 'planbcd/rails/railtie'
4
+ require 'planbcd/rails/version'
5
+
6
+ module PlanBCD
7
+ module Rails
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.configure(&block)
13
+ block.call(configuration)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ require 'planbcd/rails'
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../lib/planbcd/rails/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "planbcd-rails"
5
+ gem.version = PlanBCD::Rails::VERSION
6
+ gem.platform = Gem::Platform::RUBY
7
+ gem.authors = ["Daisuke Taniwaki"]
8
+ gem.email = ["daisuketaniwaki@gmail.com"]
9
+ gem.homepage = "http://rubygems.org/gems/planbcd-rails"
10
+ gem.summary = "Use PlanBCD with Rails 3+"
11
+ gem.description = "This gem provides view helpers for PlanBCD."
12
+ gem.license = "MIT"
13
+
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_dependency "rails", ">= 3.0", "< 5.0"
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "coveralls"
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'action_view'
3
+
4
+ describe PlanBCD::Rails::Railtie do
5
+ before :all do
6
+ app = Class.new(Rails::Application)
7
+ app.initialize!
8
+ end
9
+ subject { ActionView::Base.new }
10
+
11
+ it "should have planbcd helpers" do
12
+ expect(subject).to respond_to(:pbcd_init)
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe PlanBCD::Rails::ViewHelpers do
4
+ include PlanBCD::Rails::ViewHelpers
5
+
6
+ describe "#pbcd_init" do
7
+ let(:js) { '//planb.cd/test.js' }
8
+ before do
9
+ PlanBCD::Rails.configure do |c|
10
+ c.js = js
11
+ end
12
+ end
13
+ it "generate planbcd tag" do
14
+ expect(pbcd_init).to eq(%Q~<script type=\"text/javascript\">(function(){!function(a,b,c,d,e){return d=\"http\"+(\"https:\"===c?\"s\":\"\")+\":\"+d,a.planBCDObject=e,a[e]||(a[e]=function(){var b;return((b=a[e]).q||(b.q=[])).push(arguments),a[e].l=1*new Date}),b.write(unescape('%3Cscript type=\"text/javascript\" src=\"'+d+'\"%3E%3C/script%3E'))}(window,document,document.location.protocol,\"//planb.cd/test.js\",\"pbcd\")}).call(this);</script>~)
15
+ end
16
+ context "js has scheme" do
17
+ let(:js) { 'http://planb.cd/test.js' }
18
+ it "generate planbcd tag without scheme" do
19
+ expect(pbcd_init).to eq(%Q~<script type=\"text/javascript\">(function(){!function(a,b,c,d,e){return d=\"http\"+(\"https:\"===c?\"s\":\"\")+\":\"+d,a.planBCDObject=e,a[e]||(a[e]=function(){var b;return((b=a[e]).q||(b.q=[])).push(arguments),a[e].l=1*new Date}),b.write(unescape('%3Cscript type=\"text/javascript\" src=\"'+d+'\"%3E%3C/script%3E'))}(window,document,document.location.protocol,\"//planb.cd/test.js\",\"pbcd\")}).call(this);</script>~)
20
+ end
21
+ end
22
+ context "js is proc" do
23
+ let(:a_controller) { double }
24
+ let(:js) { proc { |controller| '//planb.cd/proc.js' } }
25
+ before do
26
+ allow(self).to receive(:controller).and_return(a_controller)
27
+ end
28
+ it "generate planbcd tag" do
29
+ expect(pbcd_init).to eq(%Q~<script type=\"text/javascript\">(function(){!function(a,b,c,d,e){return d=\"http\"+(\"https:\"===c?\"s\":\"\")+\":\"+d,a.planBCDObject=e,a[e]||(a[e]=function(){var b;return((b=a[e]).q||(b.q=[])).push(arguments),a[e].l=1*new Date}),b.write(unescape('%3Cscript type=\"text/javascript\" src=\"'+d+'\"%3E%3C/script%3E'))}(window,document,document.location.protocol,\"//planb.cd/proc.js\",\"pbcd\")}).call(this);</script>~)
30
+ end
31
+ end
32
+ context "js is nil" do
33
+ let(:js) { nil }
34
+ it "raises error" do
35
+ expect {
36
+ pbcd_init
37
+ }.to raise_error(PlanBCD::Rails::RuntimeError)
38
+ end
39
+ end
40
+ context "js is empty" do
41
+ let(:js) { '' }
42
+ it "raises error" do
43
+ expect {
44
+ pbcd_init
45
+ }.to raise_error(PlanBCD::Rails::RuntimeError)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+
5
+ require 'rails'
6
+ require 'planbcd/rails'
7
+
8
+ RSpec.configure do |config|
9
+ end
10
+
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: planbcd-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Daisuke Taniwaki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: coveralls
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: This gem provides view helpers for PlanBCD.
76
+ email:
77
+ - daisuketaniwaki@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".travis.yml"
84
+ - Gemfile
85
+ - LICENSE
86
+ - README.md
87
+ - Rakefile
88
+ - gemfiles/gemfile
89
+ - gemfiles/rails.3.1.x.gemfile
90
+ - gemfiles/rails.3.2.x.gemfile
91
+ - gemfiles/rails.4.0.x.gemfile
92
+ - gemfiles/rails.4.1.x.gemfile
93
+ - lib/generators/planbcd/install_generator.rb
94
+ - lib/generators/planbcd/templates/planbcd.rb
95
+ - lib/planbcd-rails.rb
96
+ - lib/planbcd/rails.rb
97
+ - lib/planbcd/rails/configuration.rb
98
+ - lib/planbcd/rails/error.rb
99
+ - lib/planbcd/rails/railtie.rb
100
+ - lib/planbcd/rails/version.rb
101
+ - lib/planbcd/rails/view_helpers.rb
102
+ - planbcd-rails.gemspec
103
+ - spec/planbcd/rails/railtie_spec.rb
104
+ - spec/planbcd/rails/view_helpers_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: http://rubygems.org/gems/planbcd-rails
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.0.14
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Use PlanBCD with Rails 3+
130
+ test_files:
131
+ - spec/planbcd/rails/railtie_spec.rb
132
+ - spec/planbcd/rails/view_helpers_spec.rb
133
+ - spec/spec_helper.rb
134
+ has_rdoc: