roger_requirejs 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +28 -0
- data/LICENSE +21 -0
- data/README.md +18 -0
- data/Rakefile +9 -0
- data/lib/roger_requirejs/processor.rb +127 -0
- data/lib/roger_requirejs.rb +8 -0
- data/roger_requirejs.gemspec +23 -0
- data/test/unit/processor_test.rb +61 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTFhMDUxZTRkZTcyMGM3MzAwYjk2OWEwOGIyYzE5NTc4ZTBmZjIzNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDU3OTRjMDM0YzE3YjAwMTJlOThhNDdlMDY1MWFkNDg0YWYwZDgzZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzFhMmM2OTlkNjU5MDQ0NmU3YTA5MDRiZWZlNzMwYWU3MjM4NjIzZTE0ZTJk
|
10
|
+
YzJkMjU0OTE3MzczYjNjNDA3ZmI0MDYyMDI5NjI1ZmVlNjJlZWUyOWZkZGJj
|
11
|
+
NWIwNjNhYjlmYThhNDEyN2U5OTk2YzYwNzliNWNjNjg3MWNjODk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NWQxMWQ2Y2I2OTNmMjBiYzUwYzhiYTBiNzBlZGFhNzUyYTdmODk1ZWE0OWU1
|
14
|
+
MmE2ZWFkN2JjYmZjODM5NzBmYTNkMzUwODMzZDg2NWY3ZTUzYjFiNWI4Y2Y4
|
15
|
+
YzQ0YWRlNTczYzhlMjkwODZkZGFmOTZiZmFjMjJmYzA2YTk0NzI=
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.DS_Store
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
roger_requirejs (1.0.0)
|
5
|
+
roger (~> 0.10.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
hpricot (0.8.6)
|
11
|
+
mime-types (2.2)
|
12
|
+
rack (1.5.2)
|
13
|
+
rake (10.3.1)
|
14
|
+
roger (0.10.0)
|
15
|
+
hpricot (>= 0.6.4)
|
16
|
+
mime-types (~> 2.2)
|
17
|
+
rack (>= 1.0.0)
|
18
|
+
thor (~> 0.16.0)
|
19
|
+
tilt (~> 2.0.1)
|
20
|
+
thor (0.16.0)
|
21
|
+
tilt (2.0.1)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
rake
|
28
|
+
roger_requirejs!
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 DigitPaint
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Roger RequireJS
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/roger_requirejs.png)](http://badge.fury.io/rb/roger_requirejs)
|
4
|
+
[![Build Status](https://travis-ci.org/DigitPaint/roger_requirejs.png?branch=master)](https://travis-ci.org/DigitPaint/roger_requirejs)
|
5
|
+
|
6
|
+
RequireJS processor for Roger
|
7
|
+
|
8
|
+
## Changes and versions
|
9
|
+
|
10
|
+
Have a look at the [CHANGELOG](CHANGELOG.md) to see what's new.
|
11
|
+
|
12
|
+
## Contributors
|
13
|
+
|
14
|
+
[View contributors](https://github.com/digitpaint/roger_requirejs/graphs/contributors)
|
15
|
+
|
16
|
+
## License
|
17
|
+
|
18
|
+
MIT License, see [LICENSE](LICENSE) for more info.
|
data/Rakefile
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require "roger/release"
|
2
|
+
|
3
|
+
module RogerRequirejs
|
4
|
+
class Processor < ::Roger::Release::Processors::Base
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@options = {
|
8
|
+
:build_files => {"javascripts/site.build.js" => {:dir => "javascripts"}},
|
9
|
+
:rjs => "r.js",
|
10
|
+
:node => "node"
|
11
|
+
}.update(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# @option options [Hash] :build_files An a hash of files to build (as key) and the target as a hash with either {:dir => "STRING"} or {:file => "STRING"} in the release to put it as value, each one will be built in a separate directory. (default is {"javascripts/site.build.js" => {:dir => "javascripts"}})
|
16
|
+
# @option options [String] :node The system path for node (defaults to "node" in path)
|
17
|
+
# @option options [String] :rjs The system path to the requirejs optimizer (r.js) (defaults to "../vendor/requirejs/r.js" (relative to source_path))
|
18
|
+
def call(release, options={})
|
19
|
+
@options.update(options)
|
20
|
+
|
21
|
+
begin
|
22
|
+
`#{@options[:node]} -v`
|
23
|
+
rescue Errno::ENOENT
|
24
|
+
raise RuntimeError, "Could not find node in #{@options[:node].inspect}"
|
25
|
+
end
|
26
|
+
|
27
|
+
rjs_command = rjs_check()
|
28
|
+
|
29
|
+
@options[:build_files].each do |build_file, target|
|
30
|
+
build_file = release.build_path + build_file
|
31
|
+
|
32
|
+
if target.kind_of?(Hash)
|
33
|
+
if target[:dir]
|
34
|
+
target = target[:dir]
|
35
|
+
target_type = :dir
|
36
|
+
elsif target[:file]
|
37
|
+
target = target[:file]
|
38
|
+
target_type = :file
|
39
|
+
end
|
40
|
+
else
|
41
|
+
# Old style
|
42
|
+
target_type = :dir
|
43
|
+
end
|
44
|
+
|
45
|
+
target = release.build_path + target
|
46
|
+
release.log(self, "Optimizing #{build_file}")
|
47
|
+
|
48
|
+
# Hack to create tempfile in build
|
49
|
+
t = Tempfile.new("requirejs", release.build_path)
|
50
|
+
tmp_build_dir = t.path
|
51
|
+
t.close
|
52
|
+
t.unlink
|
53
|
+
|
54
|
+
# Run r.js optimizer
|
55
|
+
if target_type == :dir
|
56
|
+
output = `#{rjs_command} -o #{build_file} dir=#{tmp_build_dir}`
|
57
|
+
else
|
58
|
+
output = `#{rjs_command} -o #{build_file} out=#{tmp_build_dir}/out.js`
|
59
|
+
end
|
60
|
+
|
61
|
+
release.debug(self, output)
|
62
|
+
|
63
|
+
# Check if r.js succeeded
|
64
|
+
unless $?.success?
|
65
|
+
raise RuntimeError, "Asset compilation with node failed.\nr.js output:\n #{output}"
|
66
|
+
end
|
67
|
+
|
68
|
+
if File.exist?(target)
|
69
|
+
release.log(self, "Removing target #{target}")
|
70
|
+
FileUtils.rm_rf(target)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
# Move the tmp_build_dir to target
|
75
|
+
if target_type == :dir
|
76
|
+
FileUtils.mv(tmp_build_dir, target)
|
77
|
+
else
|
78
|
+
FileUtils.mv("#{tmp_build_dir}/out.js", target)
|
79
|
+
FileUtils.rm_rf(tmp_build_dir)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
# Incase both a file and bin version are availble file version is taken
|
86
|
+
#
|
87
|
+
# @return rjs_command to invoke r.js optimizer with
|
88
|
+
|
89
|
+
def rjs_check(path = @options[:rjs])
|
90
|
+
rjs_command = rjs_file(path) || rjs_bin(path)
|
91
|
+
if !(rjs_command)
|
92
|
+
raise RuntimeError, "Could not find r.js optimizer in #{path.inspect} - try updating this by npm install -g requirejs"
|
93
|
+
end
|
94
|
+
rjs_command
|
95
|
+
end
|
96
|
+
|
97
|
+
protected
|
98
|
+
|
99
|
+
# Checks if the param is the r.js lib from file system
|
100
|
+
#
|
101
|
+
# @param [String] Path r.js lib may be kept to be invoked with node
|
102
|
+
# @return [String] the cli invokement string
|
103
|
+
def rjs_file(path)
|
104
|
+
if File.exist?(path)
|
105
|
+
"#{@options[:node]} #{path}"
|
106
|
+
else
|
107
|
+
false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Checks if r.js is installed as bin
|
112
|
+
#
|
113
|
+
# @param [String] Path to r.js bin
|
114
|
+
# @return [String] the cli invokement string
|
115
|
+
def rjs_bin(path)
|
116
|
+
begin
|
117
|
+
`#{path} -v`
|
118
|
+
rescue Errno::ENOENT
|
119
|
+
false
|
120
|
+
else
|
121
|
+
"#{path}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "roger_requirejs"
|
5
|
+
s.version = "1.0.0"
|
6
|
+
|
7
|
+
s.authors = ["Flurin Egger"]
|
8
|
+
s.email = ["info@digitpaint.nl", "flurin@digitpaint.nl"]
|
9
|
+
s.homepage = "http://github.com/digitpaint/roger_requirejs"
|
10
|
+
s.summary = "Processor for using the r.js optimizer in Roger."
|
11
|
+
s.licenses = ["MIT"]
|
12
|
+
|
13
|
+
s.date = Time.now.strftime("%Y-%m-%d")
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
21
|
+
|
22
|
+
s.add_dependency("roger", ["~> 0.10.0"])
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../lib/roger_requirejs/processor"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class ProcessorTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_require_js_default_fallback
|
7
|
+
# When the user points the requirejs processer to a wrong file
|
8
|
+
# it should throw an RunTimeError
|
9
|
+
options = {:rjs => "s.js"}
|
10
|
+
requirejs_processor = RogerRequirejs::Processor.new(options)
|
11
|
+
rjs = options[:rjs]
|
12
|
+
|
13
|
+
rjs_command = ''
|
14
|
+
|
15
|
+
assert_raise RuntimeError do
|
16
|
+
# The file does is there - it's this one, so it should raise
|
17
|
+
rjs_command = requirejs_processor.rjs_check
|
18
|
+
end
|
19
|
+
|
20
|
+
# No command string is returned
|
21
|
+
assert_equal rjs_command, ""
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_require_js_bin
|
26
|
+
# When no default require.js path is given we expect it to be r.js availble in $PATH
|
27
|
+
requirejs_processor = RogerRequirejs::Processor.new
|
28
|
+
rjs = "r.js" # Default r.js by npm
|
29
|
+
|
30
|
+
begin
|
31
|
+
`#{rjs} -v`
|
32
|
+
rescue Errno::ENOENT
|
33
|
+
assert_raise RuntimeError do
|
34
|
+
requirejs_processor.rjs_check
|
35
|
+
end
|
36
|
+
else
|
37
|
+
assert_equal requirejs_processor.rjs_check, rjs
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_require_js_lib
|
43
|
+
# Just point options[:rjs] to a file to look if its there,
|
44
|
+
# the user is expected to point to a correct r.js file if he
|
45
|
+
# doesn't want to use the r.js shipped with npm
|
46
|
+
options = {:rjs => __FILE__}
|
47
|
+
requirejs_processor = RogerRequirejs::Processor.new(options)
|
48
|
+
rjs = options[:rjs]
|
49
|
+
|
50
|
+
rjs_command = ''
|
51
|
+
|
52
|
+
assert_nothing_raised RuntimeError do
|
53
|
+
# The file is there - it's this one in fact, so it shouldn't raise
|
54
|
+
rjs_command = requirejs_processor.rjs_check
|
55
|
+
end
|
56
|
+
|
57
|
+
assert_equal rjs_command, "node #{rjs}"
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roger_requirejs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Flurin Egger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: roger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.0
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- info@digitpaint.nl
|
30
|
+
- flurin@digitpaint.nl
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- .travis.yml
|
37
|
+
- CHANGELOG.md
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/roger_requirejs.rb
|
44
|
+
- lib/roger_requirejs/processor.rb
|
45
|
+
- roger_requirejs.gemspec
|
46
|
+
- test/unit/processor_test.rb
|
47
|
+
homepage: http://github.com/digitpaint/roger_requirejs
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.1.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Processor for using the r.js optimizer in Roger.
|
71
|
+
test_files:
|
72
|
+
- test/unit/processor_test.rb
|