labjs-rails 0.0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", ">= 3.0.0"
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.5.2"
9
+ gem "rcov", ">= 0"
10
+ end
@@ -0,0 +1,85 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ arel (2.0.3)
32
+ builder (2.1.2)
33
+ erubis (2.6.6)
34
+ abstract (>= 1.0.0)
35
+ git (1.2.5)
36
+ i18n (0.4.2)
37
+ jeweler (1.5.2)
38
+ bundler (~> 1.0.0)
39
+ git (>= 1.2.5)
40
+ rake
41
+ mail (2.2.13)
42
+ activesupport (>= 2.3.6)
43
+ i18n (>= 0.4.0)
44
+ mime-types (~> 1.16)
45
+ treetop (~> 1.4.8)
46
+ mime-types (1.16)
47
+ polyglot (0.3.1)
48
+ rack (1.2.1)
49
+ rack-mount (0.6.13)
50
+ rack (>= 1.0.0)
51
+ rack-test (0.5.6)
52
+ rack (>= 1.0)
53
+ rails (3.0.3)
54
+ actionmailer (= 3.0.3)
55
+ actionpack (= 3.0.3)
56
+ activerecord (= 3.0.3)
57
+ activeresource (= 3.0.3)
58
+ activesupport (= 3.0.3)
59
+ bundler (~> 1.0)
60
+ railties (= 3.0.3)
61
+ railties (3.0.3)
62
+ actionpack (= 3.0.3)
63
+ activesupport (= 3.0.3)
64
+ rake (>= 0.8.7)
65
+ thor (~> 0.14.4)
66
+ rake (0.8.7)
67
+ rcov (0.9.9)
68
+ shoulda (2.11.3)
69
+ thor (0.14.4)
70
+ treetop (1.4.9)
71
+ polyglot (>= 0.3.1)
72
+ tzinfo (0.3.23)
73
+
74
+ PLATFORMS
75
+ ruby
76
+
77
+ DEPENDENCIES
78
+ bundler (~> 1.0.0)
79
+ jeweler (~> 1.5.2)
80
+ rails (>= 3.0.0)
81
+ rcov
82
+ shoulda
83
+
84
+ METADATA
85
+ version: 1.0.6
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Christopher Hein
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ = labjs-rails
2
+
3
+ *********** WORK IN PROGRESS ***********
4
+
5
+
6
+ Helper for adding Labjs instead of using javascript_include_tag
7
+
8
+ == Usage
9
+
10
+ You have to initialize the Labjs before you start using it. Using the file name you have labjs saved as in /javascripts
11
+
12
+ <%= labjs_load('labjs') %>
13
+
14
+ After you have done this you can use labjs_include_tag to chain your loading
15
+ - This allows you to wait after individual loads by using a hash and having the include the word require
16
+
17
+ <%= labjs_include_tag('require_jquery' => 'jquery.min', 'require_pageloader' => 'jquery.pageloader.min', 'shading' => 'jquery.shading.min', 'scrolling' => 'jquery.scrollingcontent.min', 'require_fancy_blend' => 'jquery.fancyblend.min') %>
18
+
19
+ == Contributing to labjs-rails
20
+
21
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
22
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
23
+ * Fork the project
24
+ * Start a feature/bugfix branch
25
+ * Commit and push until you are happy with your contribution
26
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
27
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
28
+
29
+ == Copyright
30
+
31
+ Copyright (c) 2011 Christopher Hein. See LICENSE.txt for
32
+ further details.
33
+
34
+ == Credits
35
+
36
+ http://labjs.com/ for writing labjs
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "labjs-rails"
16
+ gem.homepage = "http://github.com/christopherhein/labjs-rails"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Add labjs to your rails apps}
19
+ gem.description = %Q{Quick way of adding labjs to your rails applications through a view helpers}
20
+ gem.email = "me@christopherhein.com"
21
+ gem.authors = ["Christopher Hein"]
22
+ end
23
+ Jeweler::RubygemsDotOrgTasks.new
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/test_*.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ task :default => :test
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "labjs-rails #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0.2
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{labjs-rails}
8
+ s.version = "0.0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Christopher Hein"]
12
+ s.date = %q{2011-01-21}
13
+ s.description = %q{Quick way of adding labjs to your rails applications through a view helpers}
14
+ s.email = %q{me@christopherhein.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/labjs-rails.rb",
28
+ "lib/labjs-rails/tag_helper.rb",
29
+ "test/helper.rb",
30
+ "test/test_tag_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/christopherhein/labjs-rails}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.7}
36
+ s.summary = %q{Add labjs to your rails apps}
37
+ s.test_files = [
38
+ "test/helper.rb",
39
+ "test/test_tag_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<rails>, [">= 2.3.5"])
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<rails>, [">= 2.3.5"])
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<rails>, [">= 2.3.5"])
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,43 @@
1
+ module Labjs
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ desc "This generator downloads and installs LABjs"
5
+ class_option :version, :type => :string, :default => "master", :desc => "Which version of LABjs to fetch"
6
+ @@default_version = "master"
7
+ @@dist_url = "https://github.com/getify/LABjs/raw/{version}/{file}"
8
+
9
+ def remove_labjs
10
+ %w(LAB.src.js LAB.min.js).each do |js|
11
+ remove_file "public/javascripts/#{js}"
12
+ end
13
+ end
14
+
15
+ def download_labjs
16
+ say_status("fetching", "LABjs (#{options.version})", :green)
17
+ get_labjs(options.version)
18
+ rescue OpenURI::HTTPError
19
+ say_status("warning", "could not find LABjs (#{options.version})", :yellow)
20
+ say_status("warning", labjs_url(options.version, 'LAB.src.js'), :yellow)
21
+ say_status("warning", labjs_url(options.version, 'LAB.min.js'), :yellow)
22
+
23
+ if @@default_version != options.version
24
+ say_status("fetching", "LABjs (#{@@default_version})", :green)
25
+ get_labjs(@@default_version)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def get_labjs(version)
32
+ %w(LAB.src.js LAB.min.js).each do |js|
33
+ get labjs_url(version, js), "public/javascripts/#{js}"
34
+ end
35
+ end
36
+
37
+ def labjs_url(version, file)
38
+ @@dist_url.gsub("{version}", version).gsub("{file}", file)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ require File.join(File.dirname(__FILE__), 'labjs-rails', 'tag_helper')
2
+
3
+ ActionController::Base.helper(Labjs::TagHelper)
@@ -0,0 +1,48 @@
1
+ module Labjs
2
+ DEFAULT_DIR = "javascripts"
3
+
4
+ module TagHelper
5
+
6
+ def labjs_load(file, dir=DEFAULT_DIR)
7
+ file = labjs_format(file, dir)
8
+ "<script type=\"text/javascript\" src=\"#{file}\"></script>".html_safe
9
+ end
10
+
11
+ def labjs_include_tag(*sources)
12
+ options = sources.extract_options!
13
+ scripts = "<script type=\"text/javascript\">"
14
+ scripts += "$LAB"
15
+ options.each do |key, value|
16
+ if key.to_s == "require"
17
+ value.each do |file|
18
+ script = labjs_format(file)
19
+ scripts += ".script('#{script}').wait()"
20
+ end
21
+ end
22
+ end
23
+ options.each do |key, value|
24
+ if key.to_s == "files"
25
+ value.each do |file|
26
+ script = labjs_format(file)
27
+ scripts += ".script('#{script}')"
28
+ end
29
+ end
30
+ end
31
+
32
+ scripts += "</script>"
33
+ scripts.html_safe
34
+ end
35
+
36
+ def labjs_format(file, dir=DEFAULT_DIR)
37
+ unless file =~ /http:/
38
+ file = "/#{dir}/#{file}" unless file =~ /\/?#{dir}/
39
+ file.gsub!(/\/+/, '/')
40
+ file = "#{file}.js" unless file =~ /\.js$/
41
+ file = "/#{file}" unless file =~ /^\//
42
+ end
43
+ file
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+
14
+ require 'rails/all'
15
+ require 'shoulda'
16
+ require 'rails/test_help'
17
+ require 'rails/generators'
18
+ require 'labjs-rails'
19
+
20
+ class SomeController
21
+ include Labjs::TagHelper
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+ require 'generators/labjs/install/install_generator'
3
+
4
+ class Labjs::Generators::InstallGeneratorTest < Rails::Generators::TestCase
5
+ tests Labjs::Generators::InstallGenerator
6
+ destination File.join(File.dirname(__FILE__), 'tmp')
7
+ teardown :cleanup_destination_root
8
+
9
+ context 'the LABjs install generator' do
10
+
11
+ should 'download the default master LABjs files' do
12
+ run_generator %w(labjs:install)
13
+ assert_file 'public/javascripts/LAB.src.js'
14
+ assert_file 'public/javascripts/LAB.min.js'
15
+ end
16
+
17
+ should 'download the versioned LABjs files' do
18
+ run_generator %w(labjs:install --version master)
19
+ assert_file 'public/javascripts/LAB.src.js'
20
+ assert_file 'public/javascripts/LAB.min.js'
21
+ end
22
+
23
+ end
24
+
25
+ private
26
+
27
+ def cleanup_destination_root
28
+ FileUtils.rm_r(destination_root)
29
+ end
30
+
31
+ end
@@ -0,0 +1,24 @@
1
+ require 'helper'
2
+
3
+ class TestTagHelper < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @controller = SomeController.new
7
+ end
8
+
9
+ should "return initalize LABjs" do
10
+ assert_equal "<script type=\"text/javascript\" src=\"/javascripts/labjs.js\"></script>", @controller.labjs_load("/javascripts/labjs.js")
11
+ assert_equal "<script type=\"text/javascript\" src=\"/javascripts/labjs.js\"></script>", @controller.labjs_load("labjs.js")
12
+ assert_equal "<script type=\"text/javascript\" src=\"/javascripts/labjs.js\"></script>", @controller.labjs_load("javascripts/labjs.js")
13
+ assert_equal "<script type=\"text/javascript\" src=\"/javascripts/labjs.js\"></script>", @controller.labjs_load("javascripts/labjs")
14
+ assert_equal "<script type=\"text/javascript\" src=\"/javascripts/labjs.js\"></script>", @controller.labjs_load("labjs")
15
+ end
16
+
17
+ should "return valid script labjs tags" do
18
+ assert_equal "<script type=\"text/javascript\">$LAB.script('/javascripts/jquery.min.js').wait()</script>", @controller.labjs_include_tag(:require => ["jquery.min"])
19
+ assert_equal "<script type=\"text/javascript\">$LAB.script('/javascripts/jquery.min.js').wait().script('/javascripts/jquery.ui.js').script('/javascripts/jquery.cookie.js')</script>", @controller.labjs_include_tag(:files => ['jquery.ui', 'jquery.cookie'], :require => ['jquery.min'])
20
+ assert_equal "<script type=\"text/javascript\">$LAB.script('/javascripts/jquery.min.js').wait().script('/javascripts/jquery.ui.js').wait().script('/javascripts/jquery.cookie.js')</script>", @controller.labjs_include_tag(:files => ['jquery.cookie'], :require => ['jquery.min', 'jquery.ui'])
21
+ end
22
+
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: labjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Christopher Hein
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-21 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: bundler
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 1
58
+ - 0
59
+ - 0
60
+ version: 1.0.0
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: jeweler
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 1
73
+ - 5
74
+ - 2
75
+ version: 1.5.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: rcov
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *id005
92
+ description: Quick way of adding labjs to your rails applications through a view helpers
93
+ email: me@christopherhein.com
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.rdoc
101
+ files:
102
+ - .document
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ - Rakefile
108
+ - VERSION
109
+ - labjs-rails.gemspec
110
+ - lib/generators/labjs/install/install_generator.rb
111
+ - lib/labjs-rails.rb
112
+ - lib/labjs-rails/tag_helper.rb
113
+ - test/helper.rb
114
+ - test/test_generator.rb
115
+ - test/test_tag_helper.rb
116
+ has_rdoc: true
117
+ homepage: http://github.com/christopherhein/labjs-rails
118
+ licenses:
119
+ - MIT
120
+ post_install_message:
121
+ rdoc_options: []
122
+
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 495925348763976860
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ requirements: []
143
+
144
+ rubyforge_project:
145
+ rubygems_version: 1.3.7
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Add labjs to your rails apps
149
+ test_files:
150
+ - test/helper.rb
151
+ - test/test_generator.rb
152
+ - test/test_tag_helper.rb