nanoc-javascript-concatenator 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .rvmrc
2
+ .yardoc
3
+ Gemfile.lock
4
+ doc
5
+ pkg
6
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 John Nishinaga
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Nanoc JavaScript Concatenator
2
+
3
+ [![Build Status](https://secure.travis-ci.org/jingoro/nanoc-javascript-concatenator.png?branch=master)](http://travis-ci.org/jingoro/nanoc-javascript-concatenator)
4
+
5
+ A simple way to concatenate JavaScript files in Nanoc.
6
+
7
+ ## Installation
8
+
9
+ ### 1. Install the gem
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'nanoc-javascript-concatenator'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nanoc-javascript-concatenator
22
+
23
+ ### 2. Require the gem
24
+
25
+ Add this line to your site's `lib/default.rb`:
26
+
27
+ require 'nanoc/filters/javascript_concatenator'
28
+
29
+ ## Usage
30
+
31
+ Add a file to concatenate any JavaScript files together, e.g., `js/all.js`:
32
+
33
+ //= require include/first.js
34
+ //= require include/second.js
35
+ //= require include/third.js
36
+
37
+ Compile it with the `concat_js` filter in `Rules`:
38
+
39
+ compile '/js/all/' do
40
+ filter :concat_js
41
+ end
42
+
43
+ Ignore any included JavaScript in `Rules`:
44
+
45
+ route '/js/include/*/' do
46
+ nil
47
+ end
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'yard'
4
+ YARD::Rake::YardocTask.new
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require 'nanoc/filters/javascript_concatenator"
@@ -0,0 +1,52 @@
1
+ require 'nanoc'
2
+
3
+ module Nanoc
4
+ module Filters
5
+ class JavascriptConcatenator < Nanoc::Filter
6
+
7
+ VERSION = '0.0.1'
8
+
9
+ identifier :concat_js
10
+
11
+ REQUIRE_RE = /^\s*\/\/\s*=?\s*require\s+(.+?)\s*$/
12
+
13
+ # Provides a simple to include other JavaScript files so you can concatenate
14
+ # multiple JavaScript files together.
15
+ #
16
+ # Example:
17
+ #
18
+ # //= require file-one.js
19
+ # //= require relative/path/to/file-two.js
20
+ # //= require /absolute/path/to/file-three.js
21
+ #
22
+ # This method takes no options.
23
+ #
24
+ # @param [String] content The JavaScript
25
+ #
26
+ # @return [String] The resulting JavaScript
27
+ def run(content, args = {})
28
+ current_dir_pathname = Pathname.new(@item[:content_filename]).dirname.realpath
29
+ required_items = []
30
+ content = content.gsub(REQUIRE_RE) do |orig|
31
+ imported_pathname = Pathname.new($1)
32
+ imported_pathname = current_dir_pathname + imported_pathname if imported_pathname.relative?
33
+ if imported_pathname.exist?
34
+ imported_filename = imported_pathname.realpath
35
+ @items.each do |i|
36
+ if !i[:content_filename].nil? &&
37
+ Pathname.new(i[:content_filename]).realpath == imported_filename
38
+ required_items << i
39
+ end
40
+ end
41
+ "\n;" + File.read(imported_filename)
42
+ else
43
+ orig
44
+ end
45
+ end
46
+ depend_on required_items.uniq if required_items.size > 0
47
+ content
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["John Nishinaga"]
5
+ gem.email = ["jingoro@casa-z.org"]
6
+ gem.description = %q{Nanoc JavaScript concatenator filter}
7
+ gem.summary = %q{A simple way to concatenate JavaScript files in Nanoc}
8
+ gem.homepage = "https://github.com/jingoro/nanoc-javascript-concatenator"
9
+
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ gem.name = "nanoc-javascript-concatenator"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = '0.0.1'
16
+
17
+ gem.add_dependency 'nanoc', '>= 3.3.0'
18
+ gem.add_development_dependency 'rake'
19
+ gem.add_development_dependency 'rspec'
20
+ gem.add_development_dependency 'yard'
21
+ gem.add_development_dependency 'bluecloth'
22
+ end
@@ -0,0 +1,86 @@
1
+ require 'nanoc/filters/javascript_concatenator'
2
+
3
+ describe Nanoc::Filters::JavascriptConcatenator do
4
+
5
+ let(:first_path) { File.expand_path('../js/first.js', __FILE__) }
6
+ let(:second_path) { File.expand_path('../js/second.js', __FILE__) }
7
+
8
+ before do
9
+ item = { :content_filename => File.expand_path('../foo.js', __FILE__) }
10
+ subject.instance_variable_set(:@item, item)
11
+ subject.instance_variable_set(:@items, []) # ignore dependency checking
12
+ end
13
+
14
+ it 'should ignore standard comments' do
15
+ js = <<-JS
16
+ // free
17
+ // foo
18
+ /* some other comments
19
+ blah blah
20
+ */
21
+ // blah
22
+ JS
23
+ subject.run(js).should == js
24
+ end
25
+
26
+ it 'should include a relative path' do
27
+ js = <<-JS
28
+ // begin
29
+ // require js/first.js
30
+ // end
31
+ JS
32
+ subject.run(js).should == <<-JS
33
+ // begin
34
+
35
+ ;var first = 1;
36
+
37
+ // end
38
+ JS
39
+ end
40
+
41
+ it 'should include an absolute path' do
42
+ js = <<-JS
43
+ // begin
44
+ // require #{first_path}
45
+ // end
46
+ JS
47
+ subject.run(js).should == <<-JS
48
+ // begin
49
+
50
+ ;var first = 1;
51
+
52
+ // end
53
+ JS
54
+ end
55
+
56
+ it 'should ignore missing files' do
57
+ js = <<-JS
58
+ // begin
59
+ // require js/non-existent.js
60
+ // end
61
+ JS
62
+ subject.run(js).should == js
63
+ end
64
+
65
+ it 'should concatenate multiple files' do
66
+ js = <<-JS
67
+ // begin
68
+ // require js/first.js
69
+ // require js/non-existent.js
70
+ // require #{second_path}
71
+ // end
72
+ JS
73
+ subject.run(js).should == <<-JS
74
+ // begin
75
+
76
+ ;var first = 1;
77
+
78
+ // require js/non-existent.js
79
+
80
+ ;var SECOND = 'yo';
81
+
82
+ // end
83
+ JS
84
+ end
85
+
86
+ end
data/spec/js/first.js ADDED
@@ -0,0 +1 @@
1
+ var first = 1;
data/spec/js/second.js ADDED
@@ -0,0 +1 @@
1
+ var SECOND = 'yo';
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-javascript-concatenator
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Nishinaga
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-28 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nanoc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 11
29
+ segments:
30
+ - 3
31
+ - 3
32
+ - 0
33
+ version: 3.3.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: yard
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: bluecloth
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ description: Nanoc JavaScript concatenator filter
93
+ email:
94
+ - jingoro@casa-z.org
95
+ executables: []
96
+
97
+ extensions: []
98
+
99
+ extra_rdoc_files: []
100
+
101
+ files:
102
+ - .gitignore
103
+ - .travis.yml
104
+ - Gemfile
105
+ - LICENSE
106
+ - README.md
107
+ - Rakefile
108
+ - lib/nanoc-javascript-concatenator.rb
109
+ - lib/nanoc/filters/javascript_concatenator.rb
110
+ - nanoc-javascript-concatenator.gemspec
111
+ - spec/javascript_concatenator_spec.rb
112
+ - spec/js/first.js
113
+ - spec/js/second.js
114
+ homepage: https://github.com/jingoro/nanoc-javascript-concatenator
115
+ licenses: []
116
+
117
+ post_install_message:
118
+ rdoc_options: []
119
+
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ requirements: []
141
+
142
+ rubyforge_project:
143
+ rubygems_version: 1.8.10
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: A simple way to concatenate JavaScript files in Nanoc
147
+ test_files:
148
+ - spec/javascript_concatenator_spec.rb
149
+ - spec/js/first.js
150
+ - spec/js/second.js
151
+ has_rdoc: