jspp 0.1.2 → 0.1.6

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.
Files changed (2) hide show
  1. data/bin/jspp +37 -30
  2. metadata +4 -4
data/bin/jspp CHANGED
@@ -1,49 +1,56 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $dir = File.dirname ARGV.first || '.'
4
- $r_include = %r{/\*>\s*(.+?)\s*\*/}
5
- $r_include_inside_string = Regexp.new('"' << $r_include.source << '"')
3
+ HELP = <<-multiline
4
+
5
+ JavaScript Preprocessor
6
+
7
+ Usage: jspp input > output
8
+
9
+ Example: main.js: /*> script.js */
10
+
11
+ var style = "/*> style.css */";
12
+
13
+ style.css: html, body {margin:0; padding:0}
14
+ /*> http://nv.github.com/js-preprocessor/example/style-child.css */
15
+ .my-style {background: #fffacc}
16
+
17
+ style-child.css: .i-am-child {}
18
+
19
+ script.js: var my_script;
20
+
21
+ jspp example/main.js: var my_script;
22
+
23
+ var style = "html, body {margin:0; padding:0}\\
24
+ .i-am-child {}\\
25
+ .my-style {background: #fffacc}"
26
+ multiline
27
+
28
+ DIR = File.dirname ARGV.first || '.'
29
+ R_INCLUDE = %r{/\*>\s*(.+?)\s*\*/}
30
+ R_INCLUDE_INSIDE_STRING = Regexp.new('"' << R_INCLUDE.source << '"')
6
31
 
7
32
 
8
33
  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
34
+ if path.index('http://') or path.index('https://')
35
+ require 'open-uri'
36
+ open(path).read
21
37
  else
22
- result = File.read File.join($dir, path)
38
+ File.read File.join(DIR, path)
23
39
  end
24
- result
25
40
  end
26
41
 
27
42
  def parse(text='')
28
- text.gsub!($r_include_inside_string) {
43
+ text.gsub!(R_INCLUDE_INSIDE_STRING) {
29
44
  '"' << parse(get_file $1).gsub(/$/, '\\').chop << '"'
30
45
  }
31
- text.gsub!($r_include) {
46
+ text.gsub!(R_INCLUDE) {
32
47
  parse(get_file $1)
33
48
  }
34
49
  text
35
50
  end
36
51
 
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
52
+ if $stdin.tty? and ARGV.empty? or ARGV.delete('-h') or ARGV.delete('--help')
53
+ puts HELP
43
54
  else
44
- puts <<-multiline
45
- /*>*/ JavaScript Preprocessor "/*>*/"
46
-
47
- Usage: jspp input > output
48
- multiline
55
+ print parse ARGF.read
49
56
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nikita Vasilyev
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-11 00:00:00 +03:00
17
+ date: 2010-03-14 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: "0"
55
55
  requirements: []
56
56
 
57
- rubyforge_project: jspp
57
+ rubyforge_project:
58
58
  rubygems_version: 1.3.6
59
59
  signing_key:
60
60
  specification_version: 3