jspreprocessor 0.0.1 → 0.0.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.
- checksums.yaml +4 -4
- data/JSPreprocessor.gemspec +1 -1
- data/README.md +3 -0
- data/example_js/lib/other.js +1 -0
- data/example_js/lib/stuff.js +3 -1
- data/lib/JSPreprocessor.rb +19 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3aabf8fb6beae130e85c9e0f529f615a470ab5b
|
4
|
+
data.tar.gz: bbebd9409414d67ebba59e0f5706f49efef7898a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2465000b728254bd82b0c2518caf981a21d2709341fedbbfe772397faf914b172721d34fb9f6f7591487af02c4798d1eb9d7e50331cbdf4f6b84a3b634bcc45a
|
7
|
+
data.tar.gz: 68c62a225f2066cf36992a2b03fd73c6024d3e6fcc7aede687af3067231051e3fedd7b57396faaba0260b9a68d001ceb4d91ae374640664a4a9bac5d417f7df9
|
data/JSPreprocessor.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "jspreprocessor"
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.2'
|
8
8
|
spec.authors = ["Caleb Albritton"]
|
9
9
|
spec.email = ["ithinkincode@gmail.com"]
|
10
10
|
spec.summary = %q{Like Browserify but the C way.}
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
Like Browserify but the C way.
|
4
4
|
Include JavaScript files directly into your source code using #include 'somefile'
|
5
|
+
Use #define FOO bar to replace every instance of FOO with bar.
|
5
6
|
|
6
7
|
## Installation
|
7
8
|
|
@@ -30,6 +31,8 @@ Or install it yourself as:
|
|
30
31
|
|
31
32
|
#include 'lib/stuff'
|
32
33
|
|
34
|
+
#define FOO bar
|
35
|
+
|
33
36
|
var s = new Stuff();
|
34
37
|
s.doStuff();
|
35
38
|
|
data/example_js/lib/other.js
CHANGED
data/example_js/lib/stuff.js
CHANGED
data/lib/JSPreprocessor.rb
CHANGED
@@ -1,17 +1,33 @@
|
|
1
1
|
class JSPreprocessor
|
2
2
|
|
3
|
+
def initialize
|
4
|
+
@defines = []
|
5
|
+
end
|
6
|
+
|
3
7
|
def process(cwd, main_file)
|
4
8
|
main = File.open(cwd + main_file).read.split "\n"
|
5
|
-
compiled_file =
|
9
|
+
compiled_file = recurse_files(cwd, main).join "\n"
|
10
|
+
replace_defines compiled_file
|
6
11
|
end
|
7
12
|
|
8
|
-
def
|
13
|
+
def recurse_files(cwd, file)
|
9
14
|
file.each_with_index do |line, index|
|
10
15
|
if line.include? '#include'
|
11
16
|
to_include = cwd + line[10..-2] + '.js'
|
12
17
|
next_wd = Pathname.new(to_include).dirname.to_s + '/'
|
13
|
-
file[index] =
|
18
|
+
file[index] = recurse_files next_wd, File.open(to_include).read.split("\n")
|
19
|
+
elsif line.include? '#define'
|
20
|
+
@defines << line[8..-1].split(' ')
|
21
|
+
file.delete_at index
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
25
|
+
|
26
|
+
def replace_defines(file)
|
27
|
+
@defines.each do |definition|
|
28
|
+
file.gsub! definition[0], definition[1]
|
29
|
+
end
|
30
|
+
|
31
|
+
file
|
32
|
+
end
|
17
33
|
end
|