jspp 0.1.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.
- data/bin/jspp +49 -0
- data/test/jspp_test.rb +30 -0
- metadata +63 -0
data/bin/jspp
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$dir = File.dirname ARGV.first || '.'
|
4
|
+
$r_include = %r{/\*>\s*(.+?)\s*\*/}
|
5
|
+
$r_include_inside_string = Regexp.new('"' << $r_include.source << '"')
|
6
|
+
|
7
|
+
|
8
|
+
def get_file(path='')
|
9
|
+
result = ''
|
10
|
+
if path.start_with? 'http://'
|
11
|
+
require 'net/http'
|
12
|
+
url = URI.parse path
|
13
|
+
Net::HTTP.start url.host, url.port do |http|
|
14
|
+
page = http.get url.path
|
15
|
+
if page.is_a? Net::HTTPSuccess
|
16
|
+
result = page.body
|
17
|
+
else
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
else
|
22
|
+
result = File.read File.join($dir, path)
|
23
|
+
end
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse(text='')
|
28
|
+
text.gsub!($r_include_inside_string) {
|
29
|
+
'"' << parse(get_file $1).gsub(/$/, '\\').chop << '"'
|
30
|
+
}
|
31
|
+
text.gsub!($r_include) {
|
32
|
+
parse(get_file $1)
|
33
|
+
}
|
34
|
+
text
|
35
|
+
end
|
36
|
+
|
37
|
+
if not ARGV.empty?
|
38
|
+
ARGV.each do |a|
|
39
|
+
print parse File.read a
|
40
|
+
end
|
41
|
+
elsif STDIN.stat.size > 0
|
42
|
+
print parse STDIN.read
|
43
|
+
else
|
44
|
+
puts <<-multiline
|
45
|
+
/*>*/ JavaScript Preprocessor "/*>*/"
|
46
|
+
|
47
|
+
Usage: jspp input > output
|
48
|
+
multiline
|
49
|
+
end
|
data/test/jspp_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
class JSPreprocessorTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
DIR = File.dirname __FILE__
|
6
|
+
EXAMPLE = File.join DIR, '..', 'example', ''
|
7
|
+
JSPP = File.join DIR, '..', 'bin', 'jspp'
|
8
|
+
|
9
|
+
def jspp(name='')
|
10
|
+
`#{JSPP} #{EXAMPLE}#{name}`
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_examples
|
14
|
+
assert_equal File.read("#{EXAMPLE}style-child.css"), jspp('style-child.css')
|
15
|
+
assert_equal <<-multiline, jspp('style.css')
|
16
|
+
html, body {margin:0; padding:0}
|
17
|
+
.i-am-child {}
|
18
|
+
.my-style {background: #fffacc}
|
19
|
+
multiline
|
20
|
+
assert_equal File.read("#{EXAMPLE}script.js"), jspp('script.js')
|
21
|
+
assert_equal <<-multiline, jspp('main.js')
|
22
|
+
var my_script;
|
23
|
+
|
24
|
+
var style = "html, body {margin:0; padding:0}\\
|
25
|
+
.i-am-child {}\\
|
26
|
+
.my-style {background: #fffacc}\\
|
27
|
+
";
|
28
|
+
multiline
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jspp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Nikita Vasilyev
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-11 00:00:00 +03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: JavaScript and CSS squasher. Used for building UserJS. Similar to sprockets and juicer.
|
22
|
+
email: me@elv1s.ru
|
23
|
+
executables:
|
24
|
+
- jspp
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- bin/jspp
|
31
|
+
- test/jspp_test.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/NV/js-preprocessor
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- bin
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: jspp
|
58
|
+
rubygems_version: 1.3.6
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: JavaScript preprocessor
|
62
|
+
test_files:
|
63
|
+
- test/jspp_test.rb
|