midge 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. data/README.md +9 -9
  2. data/lib/midge/config.rb +5 -9
  3. data/lib/midge/version.rb +1 -1
  4. data/test/dummy/app/assets/javascripts/test1.midge.js +1 -0
  5. data/test/dummy/app/assets/javascripts/test2.midge_template.js +1 -0
  6. data/test/dummy/config/initializers/midge.rb +4 -0
  7. data/test/dummy/log/test.log +82 -0
  8. data/test/dummy/tmp/cache/assets/C66/BF0/sprockets%2Fce82f153407553739387c7480469c6ee +0 -0
  9. data/test/dummy/tmp/cache/assets/CDD/510/sprockets%2Fd1c26bd44050457d13eb787a34735f8d +0 -0
  10. data/test/dummy/tmp/cache/assets/D18/0A0/sprockets%2Fe1a8d90cf0855c9d0272d55f49016df8 +0 -0
  11. data/test/dummy/tmp/cache/assets/D22/2F0/sprockets%2F7939087f299a606efc861187ec2f2caa +0 -0
  12. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  13. data/test/dummy/tmp/cache/assets/D52/DC0/sprockets%2Fa7e27a78617a439a89e89a8c76dc5bb0 +0 -0
  14. data/test/dummy/tmp/cache/assets/D63/250/sprockets%2F5a0149de7a41e6b22d2e2e9098ab5b1e +0 -0
  15. data/test/dummy/tmp/cache/assets/D6E/AA0/sprockets%2Fcd512fd7b12c80284a970f9c4a0fc7e7 +0 -0
  16. data/test/dummy/tmp/cache/assets/D78/9D0/sprockets%2F4726aed29cb88570538a396b3faffb0f +0 -0
  17. data/test/dummy/tmp/cache/assets/DCF/C80/sprockets%2F03a5fae1c73f37f19df29cc6fb3b62d6 +0 -0
  18. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  19. data/test/dummy/tmp/cache/assets/E00/2D0/sprockets%2Ffdde40486ffac2993a2aa928ca9bae61 +0 -0
  20. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  21. data/test/midge_test.rb +17 -3
  22. data/test/test_helper.rb +3 -0
  23. metadata +88 -5
data/README.md CHANGED
@@ -42,16 +42,20 @@ Midge.setup do |config|
42
42
  end
43
43
  ```
44
44
 
45
- With this setup you create a file called "/app/assets/javascripts/person.midge.js". In this
46
- file attach public functionality onto the `exports` object.
45
+ With this setup you can create a file with the extension of ".midge.js" or
46
+ ".midge.coffee" and it will be module enabled. In the file attach public
47
+ functionality onto the `exports` object. For example:
47
48
 
48
49
  ``` javascript
50
+ # /app/assets/javascripts/person.midge.js
51
+
49
52
  exports.Person = function() {
50
53
  this.name = "A guy";
51
54
  };
52
55
  ```
53
56
 
54
- The output for this after running through the asset pipeline is:
57
+ The output for this after running through the asset pipeline would be something
58
+ like:
55
59
 
56
60
  ``` javascript
57
61
  (function(exports) {
@@ -61,7 +65,8 @@ The output for this after running through the asset pipeline is:
61
65
  }).call(this, (this.Midge || (this.Midge = {})));
62
66
  ```
63
67
 
64
- So with this in place you can access the `Person` object on the `Midge` namespace.
68
+ So with this in place you can access the `Person` object on the `Midge`
69
+ namespace.
65
70
 
66
71
  ``` javascript
67
72
  var guy = new Midge.Person;
@@ -69,11 +74,6 @@ var guy = new Midge.Person;
69
74
 
70
75
  Voila! Simple albeit limited javascript modules.
71
76
 
72
- ## TODO
73
-
74
- - Tests
75
- - Documentation
76
-
77
77
  ## Contributing
78
78
 
79
79
  1. Fork it
@@ -6,17 +6,16 @@ module Midge
6
6
  attr_reader :js_null_processor_enabled
7
7
 
8
8
  def initialize
9
- @jst_processors = []
10
- @js_processors = []
9
+ @processors = []
11
10
  set_js_null_processor_enabled(true)
12
11
  end
13
12
 
14
13
  def jst_processor(extension, namespace=Rails.application.class.parent_name)
15
- @jst_processors << [extension, namespace]
14
+ @processors << [::Midge::JstProcessor, extension, namespace]
16
15
  end
17
16
 
18
17
  def js_processor(extension, namespace=Rails.application.class.parent_name)
19
- @js_processors << [extension, namespace]
18
+ @processors << [::Midge::JavascriptProcessor, extension, namespace]
20
19
  end
21
20
 
22
21
  def set_js_null_processor_enabled(value)
@@ -24,11 +23,8 @@ module Midge
24
23
  end
25
24
 
26
25
  def configure!(sprockets=Sprockets)
27
- @js_processors.each do |extension, namespace|
28
- sprockets.register_engine extension, create_processer(::Midge::JavascriptProcessor, namespace)
29
- end
30
- @jst_processors.each do |extension, namespace|
31
- sprockets.register_engine extension, create_processer(::Midge::JstProcessor, namespace)
26
+ @processors.each do |base_klass, extension, namespace|
27
+ sprockets.register_engine extension, create_processer(base_klass, namespace)
32
28
  end
33
29
  end
34
30
 
@@ -1,3 +1,3 @@
1
1
  module Midge
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1 @@
1
+ exports.name = "Test1";
@@ -0,0 +1,4 @@
1
+ Midge.setup do |config|
2
+ config.jst_processor ".midge_template", "MidgeTest"
3
+ config.js_processor ".midge", "MidgeTest"
4
+ end
@@ -1,3 +1,85 @@
1
1
  Connecting to database specified by database.yml
2
2
   (3.6ms) begin transaction
3
3
   (0.1ms) rollback transaction
4
+ Connecting to database specified by database.yml
5
+  (4.5ms) begin transaction
6
+  (0.1ms) rollback transaction
7
+ Connecting to database specified by database.yml
8
+  (0.4ms) begin transaction
9
+ Connecting to database specified by database.yml
10
+  (0.4ms) begin transaction
11
+ Compiled jquery.js (4ms) (pid 72309)
12
+ Compiled jquery_ujs.js (0ms) (pid 72309)
13
+ Compiled application.js (76ms) (pid 72309)
14
+ Connecting to database specified by database.yml
15
+  (0.4ms) begin transaction
16
+ Compiled test1.js (0ms) (pid 72510)
17
+ Connecting to database specified by database.yml
18
+  (0.4ms) begin transaction
19
+ Compiled test1.js (1ms) (pid 72727)
20
+  (0.3ms) rollback transaction
21
+ Connecting to database specified by database.yml
22
+  (0.4ms) begin transaction
23
+  (0.2ms) rollback transaction
24
+ Connecting to database specified by database.yml
25
+  (0.3ms) begin transaction
26
+  (0.2ms) rollback transaction
27
+ Connecting to database specified by database.yml
28
+  (0.4ms) begin transaction
29
+  (0.2ms) rollback transaction
30
+ Connecting to database specified by database.yml
31
+  (0.4ms) begin transaction
32
+  (0.2ms) rollback transaction
33
+ Connecting to database specified by database.yml
34
+  (0.4ms) begin transaction
35
+  (0.1ms) rollback transaction
36
+ Connecting to database specified by database.yml
37
+  (0.3ms) begin transaction
38
+ Compiled test1.js (0ms) (pid 73040)
39
+  (0.1ms) rollback transaction
40
+ Connecting to database specified by database.yml
41
+  (0.4ms) begin transaction
42
+  (0.3ms) rollback transaction
43
+ Connecting to database specified by database.yml
44
+  (0.4ms) begin transaction
45
+ Connecting to database specified by database.yml
46
+  (0.7ms) begin transaction
47
+ Compiled test1.js (1ms) (pid 73584)
48
+  (0.2ms) rollback transaction
49
+ Connecting to database specified by database.yml
50
+  (0.4ms) begin transaction
51
+ Connecting to database specified by database.yml
52
+  (0.5ms) begin transaction
53
+  (0.1ms) rollback transaction
54
+ Connecting to database specified by database.yml
55
+  (0.4ms) begin transaction
56
+  (0.2ms) rollback transaction
57
+ Connecting to database specified by database.yml
58
+  (0.5ms) begin transaction
59
+  (0.2ms) rollback transaction
60
+ Connecting to database specified by database.yml
61
+  (0.4ms) begin transaction
62
+  (0.2ms) rollback transaction
63
+  (0.1ms) begin transaction
64
+ Compiled test2.js (0ms) (pid 74375)
65
+  (0.1ms) rollback transaction
66
+ Connecting to database specified by database.yml
67
+  (0.3ms) begin transaction
68
+  (0.2ms) rollback transaction
69
+  (0.1ms) begin transaction
70
+  (0.1ms) rollback transaction
71
+ Connecting to database specified by database.yml
72
+  (0.4ms) begin transaction
73
+  (0.2ms) rollback transaction
74
+  (0.1ms) begin transaction
75
+  (0.1ms) rollback transaction
76
+ Connecting to database specified by database.yml
77
+  (0.3ms) begin transaction
78
+  (0.1ms) rollback transaction
79
+  (0.1ms) begin transaction
80
+  (0.2ms) rollback transaction
81
+ Connecting to database specified by database.yml
82
+  (0.3ms) begin transaction
83
+  (0.2ms) rollback transaction
84
+  (0.1ms) begin transaction
85
+  (0.1ms) rollback transaction
@@ -1,7 +1,21 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
+ require "execjs"
2
3
 
3
4
  class MidgeTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, Midge
5
+ def get_script(name)
6
+ Rails.application.assets.find_asset(name).to_s
7
+ end
8
+
9
+ def eval_script(name, script_text)
10
+ context = ExecJS.compile get_script(name)
11
+ context.eval script_text
12
+ end
13
+
14
+ test "Wraps normal script in a closure with an exports object" do
15
+ assert_equal eval_script("test1", "MidgeTest.name"), "Test1"
16
+ end
17
+
18
+ test "Wraps template in a namespaced JST" do
19
+ assert_equal eval_script("test2", "MidgeTest.JST['test2']"), "Test2"
6
20
  end
7
21
  end
@@ -1,6 +1,9 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
+ # Use Node.js since it has an explicit this already.
5
+ ENV["EXECJS_RUNTIME"] = "Node"
6
+
4
7
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
8
  require "rails/test_help"
6
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -43,7 +43,58 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description:
46
+ - !ruby/object:Gem::Dependency
47
+ name: execjs
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! "# Midge\n\nMidge is a quick and cheap [javascript module](http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth)\nsystem
79
+ for the rails asset pipeline.\n\n## Installation\n\nAdd this line to your application's
80
+ Gemfile:\n\n``` ruby\ngem 'midge'\n```\n\nAnd then execute:\n\n``` console\n$ bundle\n```\n\nOr
81
+ install it yourself as:\n\n``` console\n$ gem install midge\n```\n\n## Usage\n\nFirst
82
+ run the install.\n\n``` console\n$ rails generate midge:install\n```\n\nIn the initializer
83
+ you setup what file extensions will go to what \"module\".\n\n``` ruby\n# /config/initializers/midge.rb\n\nMidge.setup
84
+ do |config|\n config.jst_processor \".midge_template\", \"Midge\"\n config.js_processor
85
+ \".midge\", \"Midge\"\nend\n```\n\nWith this setup you can create a file with the
86
+ extension of \".midge.js\" or\n\".midge.coffee\" and it will be module enabled.
87
+ In the file attach public\nfunctionality onto the `exports` object. For example:\n\n```
88
+ javascript\n# /app/assets/javascripts/person.midge.js\n\nexports.Person = function()
89
+ {\n this.name = \"A guy\";\n};\n```\n\nThe output for this after running through
90
+ the asset pipeline would be something\nlike:\n\n``` javascript\n(function(exports)
91
+ {\n exports.Person = function() {\n this.name = \"A guy\";\n };\n}).call(this,
92
+ (this.Midge || (this.Midge = {})));\n```\n\nSo with this in place you can access
93
+ the `Person` object on the `Midge`\nnamespace.\n\n``` javascript\nvar guy = new
94
+ Midge.Person;\n```\n\nVoila! Simple albeit limited javascript modules.\n\n## Contributing\n\n1.
95
+ Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit
96
+ your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git
97
+ push origin my-new-feature`)\n5. Create new Pull Request\n"
47
98
  email:
48
99
  - bigjasonwebb@gmail.com
49
100
  executables: []
@@ -65,6 +116,8 @@ files:
65
116
  - Rakefile
66
117
  - README.md
67
118
  - test/dummy/app/assets/javascripts/application.js
119
+ - test/dummy/app/assets/javascripts/test1.midge.js
120
+ - test/dummy/app/assets/javascripts/test2.midge_template.js
68
121
  - test/dummy/app/assets/stylesheets/application.css
69
122
  - test/dummy/app/controllers/application_controller.rb
70
123
  - test/dummy/app/helpers/application_helper.rb
@@ -78,6 +131,7 @@ files:
78
131
  - test/dummy/config/environments/test.rb
79
132
  - test/dummy/config/initializers/backtrace_silencers.rb
80
133
  - test/dummy/config/initializers/inflections.rb
134
+ - test/dummy/config/initializers/midge.rb
81
135
  - test/dummy/config/initializers/mime_types.rb
82
136
  - test/dummy/config/initializers/secret_token.rb
83
137
  - test/dummy/config/initializers/session_store.rb
@@ -95,6 +149,19 @@ files:
95
149
  - test/dummy/Rakefile
96
150
  - test/dummy/README.rdoc
97
151
  - test/dummy/script/rails
152
+ - test/dummy/tmp/cache/assets/C66/BF0/sprockets%2Fce82f153407553739387c7480469c6ee
153
+ - test/dummy/tmp/cache/assets/CDD/510/sprockets%2Fd1c26bd44050457d13eb787a34735f8d
154
+ - test/dummy/tmp/cache/assets/D18/0A0/sprockets%2Fe1a8d90cf0855c9d0272d55f49016df8
155
+ - test/dummy/tmp/cache/assets/D22/2F0/sprockets%2F7939087f299a606efc861187ec2f2caa
156
+ - test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
157
+ - test/dummy/tmp/cache/assets/D52/DC0/sprockets%2Fa7e27a78617a439a89e89a8c76dc5bb0
158
+ - test/dummy/tmp/cache/assets/D63/250/sprockets%2F5a0149de7a41e6b22d2e2e9098ab5b1e
159
+ - test/dummy/tmp/cache/assets/D6E/AA0/sprockets%2Fcd512fd7b12c80284a970f9c4a0fc7e7
160
+ - test/dummy/tmp/cache/assets/D78/9D0/sprockets%2F4726aed29cb88570538a396b3faffb0f
161
+ - test/dummy/tmp/cache/assets/DCF/C80/sprockets%2F03a5fae1c73f37f19df29cc6fb3b62d6
162
+ - test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
163
+ - test/dummy/tmp/cache/assets/E00/2D0/sprockets%2Ffdde40486ffac2993a2aa928ca9bae61
164
+ - test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
98
165
  - test/midge_test.rb
99
166
  - test/test_helper.rb
100
167
  homepage: https://github.com/bigjason/midge
@@ -111,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
178
  version: '0'
112
179
  segments:
113
180
  - 0
114
- hash: 1856805139089412848
181
+ hash: 3093381583402112603
115
182
  required_rubygems_version: !ruby/object:Gem::Requirement
116
183
  none: false
117
184
  requirements:
@@ -120,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
187
  version: '0'
121
188
  segments:
122
189
  - 0
123
- hash: 1856805139089412848
190
+ hash: 3093381583402112603
124
191
  requirements: []
125
192
  rubyforge_project:
126
193
  rubygems_version: 1.8.24
@@ -129,6 +196,8 @@ specification_version: 3
129
196
  summary: Quick and cheap javascript modules for the rails asset pipeline.
130
197
  test_files:
131
198
  - test/dummy/app/assets/javascripts/application.js
199
+ - test/dummy/app/assets/javascripts/test1.midge.js
200
+ - test/dummy/app/assets/javascripts/test2.midge_template.js
132
201
  - test/dummy/app/assets/stylesheets/application.css
133
202
  - test/dummy/app/controllers/application_controller.rb
134
203
  - test/dummy/app/helpers/application_helper.rb
@@ -142,6 +211,7 @@ test_files:
142
211
  - test/dummy/config/environments/test.rb
143
212
  - test/dummy/config/initializers/backtrace_silencers.rb
144
213
  - test/dummy/config/initializers/inflections.rb
214
+ - test/dummy/config/initializers/midge.rb
145
215
  - test/dummy/config/initializers/mime_types.rb
146
216
  - test/dummy/config/initializers/secret_token.rb
147
217
  - test/dummy/config/initializers/session_store.rb
@@ -159,5 +229,18 @@ test_files:
159
229
  - test/dummy/Rakefile
160
230
  - test/dummy/README.rdoc
161
231
  - test/dummy/script/rails
232
+ - test/dummy/tmp/cache/assets/C66/BF0/sprockets%2Fce82f153407553739387c7480469c6ee
233
+ - test/dummy/tmp/cache/assets/CDD/510/sprockets%2Fd1c26bd44050457d13eb787a34735f8d
234
+ - test/dummy/tmp/cache/assets/D18/0A0/sprockets%2Fe1a8d90cf0855c9d0272d55f49016df8
235
+ - test/dummy/tmp/cache/assets/D22/2F0/sprockets%2F7939087f299a606efc861187ec2f2caa
236
+ - test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
237
+ - test/dummy/tmp/cache/assets/D52/DC0/sprockets%2Fa7e27a78617a439a89e89a8c76dc5bb0
238
+ - test/dummy/tmp/cache/assets/D63/250/sprockets%2F5a0149de7a41e6b22d2e2e9098ab5b1e
239
+ - test/dummy/tmp/cache/assets/D6E/AA0/sprockets%2Fcd512fd7b12c80284a970f9c4a0fc7e7
240
+ - test/dummy/tmp/cache/assets/D78/9D0/sprockets%2F4726aed29cb88570538a396b3faffb0f
241
+ - test/dummy/tmp/cache/assets/DCF/C80/sprockets%2F03a5fae1c73f37f19df29cc6fb3b62d6
242
+ - test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
243
+ - test/dummy/tmp/cache/assets/E00/2D0/sprockets%2Ffdde40486ffac2993a2aa928ca9bae61
244
+ - test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
162
245
  - test/midge_test.rb
163
246
  - test/test_helper.rb