neptune_coffee 0.1.0 → 0.2.0
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/README.md +8 -5
- data/examples/after/geometry/box.js +12 -4
- data/examples/after/geometry/circle.js +12 -4
- data/examples/after/geometry/namespace.js +1 -1
- data/examples/after/geometry/solids/cone.js +12 -4
- data/examples/after/geometry/solids/namespace.js +1 -1
- data/examples/after/geometry/solids.js +3 -2
- data/examples/after/geometry.js +4 -2
- data/examples/after/namespace.js +1 -1
- data/examples/before/geometry/box.js +12 -4
- data/examples/before/geometry/circle.js +12 -4
- data/examples/before/geometry/solids/cone.js +12 -4
- data/lib/neptune_coffee/generator.rb +3 -2
- data/lib/neptune_coffee/javascript_generator.rb +10 -4
- data/lib/neptune_coffee/version.rb +1 -1
- data/spec/javascript_generator_spec.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66c47955d9f4f7c61196d9ebfd93b28685cb5245
|
4
|
+
data.tar.gz: a349b48feed11d4ff8b57ef448e39942f987bcea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec430a0759d0b17964bdc57b0cc810a65036048d0a6a4aff2c62d0691997739dd76e05c61be071b5ea487492e08f4a62c9dd29ea4f9f557859e8b9ccbff7efae
|
7
|
+
data.tar.gz: b147d1d105f107af09d10be2fb743dec82c1464396bee603c7eab5910188a84fbf4c657e07fe474bd15ab12cfedac2cc88d80b153d775183c5460471e839518a
|
data/README.md
CHANGED
@@ -23,6 +23,7 @@ NeptuneCoffee has an opinion about how you should organize your javascript for A
|
|
23
23
|
* Directories are AMD modules
|
24
24
|
* Directory's name defines the AMD module's name
|
25
25
|
* Directory names should be snake_case
|
26
|
+
* module js files return classes to be attached to their directory's namespace
|
26
27
|
* generated AMD module names will be CamelCase
|
27
28
|
* require "foo/bar" includes all files in the module defined by the directory "foo/bar"
|
28
29
|
* Defines a hierachical namespace based on module names and directory structure nesting
|
@@ -71,13 +72,15 @@ NeptuneCoffee generates:
|
|
71
72
|
|
72
73
|
geometry.js might look like:
|
73
74
|
|
74
|
-
// Generated by NeptuneCoffee 0.0
|
75
|
+
// Generated by NeptuneCoffee 0.2.0
|
75
76
|
define([
|
76
|
-
'./geometry/namespace'
|
77
|
-
'./geometry/box'
|
78
|
-
'./geometry/circle'
|
77
|
+
'./geometry/namespace',
|
78
|
+
'./geometry/box',
|
79
|
+
'./geometry/circle',
|
79
80
|
'./geometry/solids'
|
80
|
-
], function(Geometry) {
|
81
|
+
], function(Geometry, Box, Circle) {
|
82
|
+
Geometry.Box = Box; Box.namespace = Geometry;
|
83
|
+
Geometry.Circle = Circle; Circle.namespace = Geometry;
|
81
84
|
return Geometry;
|
82
85
|
});
|
83
86
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
// Generated by NeptuneCoffee 0.
|
1
|
+
// Generated by NeptuneCoffee 0.2.0
|
2
2
|
define([
|
3
3
|
'./solids/namespace',
|
4
4
|
'./solids/cone'
|
5
|
-
], function(Solids) {
|
5
|
+
], function(Solids, Cone) {
|
6
|
+
if (typeof Cone == 'function') {Solids.Cone = Cone; Cone.namespace = Solids;}
|
6
7
|
return Solids;
|
7
8
|
});
|
data/examples/after/geometry.js
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
// Generated by NeptuneCoffee 0.
|
1
|
+
// Generated by NeptuneCoffee 0.2.0
|
2
2
|
define([
|
3
3
|
'./geometry/namespace',
|
4
4
|
'./geometry/box',
|
5
5
|
'./geometry/circle',
|
6
6
|
'./geometry/solids'
|
7
|
-
], function(Geometry) {
|
7
|
+
], function(Geometry, Box, Circle) {
|
8
|
+
if (typeof Box == 'function') {Geometry.Box = Box; Box.namespace = Geometry;}
|
9
|
+
if (typeof Circle == 'function') {Geometry.Circle = Circle; Circle.namespace = Geometry;}
|
8
10
|
return Geometry;
|
9
11
|
});
|
data/examples/after/namespace.js
CHANGED
@@ -86,8 +86,9 @@ module NeptuneCoffee
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def generate_module dir
|
89
|
-
|
90
|
-
|
89
|
+
subdirs = @dirs.subdirs(dir)
|
90
|
+
files = dir.children.select {|f| f.extname.downcase == ".js" && !subdirs.index(f.sub_ext(""))}
|
91
|
+
safe_generate(dir.sub_ext(".js")) {JavascriptGenerator.new(root, dir).module(@dirs.subdirs(dir), files)}
|
91
92
|
end
|
92
93
|
|
93
94
|
def generate_namespace dir
|
@@ -11,13 +11,19 @@ module NeptuneCoffee
|
|
11
11
|
"define([#{files_js}], function"
|
12
12
|
end
|
13
13
|
|
14
|
-
def module
|
14
|
+
def module sub_modules, class_files
|
15
15
|
# subfiles ||= dir.children.select{|c| !c.directory? && c.extname == ".js"}
|
16
|
-
|
17
|
-
files = [dir + "namespace"] +
|
16
|
+
class_files = class_files.map{|f|f.sub_ext("")}.select {|c|c.basename.to_s!="namespace"}.sort.uniq
|
17
|
+
files = [dir + "namespace"] + class_files + sub_modules.sort.uniq
|
18
|
+
|
19
|
+
file_class_names = class_files.map {|files| files.basename.to_s.camel_case}
|
18
20
|
|
19
21
|
<<-ENDJS
|
20
|
-
#{define_js files, dir.dirname}(#{namespace_name}) {
|
22
|
+
#{define_js files, dir.dirname}(#{([namespace_name]+file_class_names).join ', '}) {#{
|
23
|
+
file_class_names.map do |fcn|
|
24
|
+
"\n if (typeof #{fcn} == 'function') {#{namespace_name}.#{fcn} = #{fcn}; #{fcn}.namespace = #{namespace_name};}"
|
25
|
+
end.join
|
26
|
+
}
|
21
27
|
return #{namespace_name};
|
22
28
|
});
|
23
29
|
ENDJS
|
@@ -14,8 +14,9 @@ describe JavascriptGenerator do
|
|
14
14
|
|
15
15
|
it "module_js" do
|
16
16
|
module_js = JavascriptGenerator.new(Pathname["foo"], Pathname["foo/bar"]).module [
|
17
|
-
Pathname["foo/bar/subdir1
|
18
|
-
Pathname["foo/bar/subdir2
|
17
|
+
Pathname["foo/bar/subdir1"],
|
18
|
+
Pathname["foo/bar/subdir2"]
|
19
|
+
], [
|
19
20
|
Pathname["foo/bar/file1"],
|
20
21
|
Pathname["foo/bar/file2"]
|
21
22
|
]
|
@@ -27,7 +28,9 @@ define([
|
|
27
28
|
'./bar/file2',
|
28
29
|
'./bar/subdir1',
|
29
30
|
'./bar/subdir2'
|
30
|
-
], function(Bar) {
|
31
|
+
], function(Bar, File1, File2) {
|
32
|
+
if (typeof File1 == 'function') {Bar.File1 = File1; File1.namespace = Bar;}
|
33
|
+
if (typeof File2 == 'function') {Bar.File2 = File2; File2.namespace = Bar;}
|
31
34
|
return Bar;
|
32
35
|
});
|
33
36
|
ENDJS
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neptune_coffee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Brinkman-Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|