dart-rails 0.3.2.pre.p1

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 (49) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +176 -0
  4. data/Rakefile +38 -0
  5. data/lib/assets/javascripts/dart.js +22 -0
  6. data/lib/dart-rails.rb +1 -0
  7. data/lib/dart/rails/dart_asset_helper.rb +34 -0
  8. data/lib/dart/rails/dart_engine.rb +14 -0
  9. data/lib/dart/rails/generators/assets/generator.rb +18 -0
  10. data/lib/dart/rails/generators/assets/templates/dart/dart_app.dart +7 -0
  11. data/lib/dart/rails/generators/assets/templates/dart/dart_app.js +2 -0
  12. data/lib/dart/rails/generators/assets/templates/dart/pubspec.yaml +4 -0
  13. data/lib/dart/rails/js_compat_engine.rb +33 -0
  14. data/lib/dart/rails/template_handler.rb +22 -0
  15. data/lib/dart/rails/version.rb +5 -0
  16. data/lib/dart/railtie.rb +38 -0
  17. data/lib/dart/sprockets/directive_processor_dart2js.rb +63 -0
  18. data/lib/tasks/dart-rails_tasks.rake +15 -0
  19. data/test/dart-rails_test.rb +7 -0
  20. data/test/dummy/README.rdoc +261 -0
  21. data/test/dummy/Rakefile +7 -0
  22. data/test/dummy/app/assets/javascripts/application.js +15 -0
  23. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  24. data/test/dummy/app/controllers/application_controller.rb +3 -0
  25. data/test/dummy/app/helpers/application_helper.rb +2 -0
  26. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/test/dummy/config.ru +4 -0
  28. data/test/dummy/config/application.rb +59 -0
  29. data/test/dummy/config/boot.rb +10 -0
  30. data/test/dummy/config/database.yml +25 -0
  31. data/test/dummy/config/environment.rb +5 -0
  32. data/test/dummy/config/environments/development.rb +37 -0
  33. data/test/dummy/config/environments/production.rb +67 -0
  34. data/test/dummy/config/environments/test.rb +37 -0
  35. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/dummy/config/initializers/inflections.rb +15 -0
  37. data/test/dummy/config/initializers/mime_types.rb +5 -0
  38. data/test/dummy/config/initializers/secret_token.rb +7 -0
  39. data/test/dummy/config/initializers/session_store.rb +8 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +5 -0
  42. data/test/dummy/config/routes.rb +58 -0
  43. data/test/dummy/public/404.html +26 -0
  44. data/test/dummy/public/422.html +26 -0
  45. data/test/dummy/public/500.html +25 -0
  46. data/test/dummy/public/favicon.ico +0 -0
  47. data/test/dummy/script/rails +6 -0
  48. data/test/test_helper.rb +15 -0
  49. metadata +164 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e49471ffcb2c67b6a640073efcb54e7cbdc61da
4
+ data.tar.gz: deeba9f94a167824fcc7ed65fd34f5aa87764e02
5
+ SHA512:
6
+ metadata.gz: cef071f90eb7a0efd96c1e8b0d8b62737fa1342682d3e4e61323cd071aa9c3bf3d4dd88fabf7dfe7f821e71dc7adde021ac1814ecc3345d51c86c28636fc0be1
7
+ data.tar.gz: 22f3fe694ff4ac91032c14ef460ab4d6bb0e88e8428187a8abbcfcc11e95a46d561eab0ae56efd2977ce2ab31153bd41fa3a6da66a673a635104769c458adb91
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,176 @@
1
+ dart-rails
2
+ ==========
3
+
4
+ ### Idea ###
5
+
6
+ Handle [dart](https://www.dartlang.org/ 'dartlang.org') scripts so they get transcoded to js for browsers
7
+ without dart support. Currently there's only the `Dartium` browser from the development-kit that supports
8
+ dart directly.
9
+
10
+ For now this is a rather stupid attempt, although it works.
11
+
12
+ For a working sample check [m0gg/dart-rails-sample](https://github.com/m0gg/dart-rails-sample 'm0gg/dart-rails-sample').
13
+
14
+ ### Setup ###
15
+
16
+ 1. `Gemfile`
17
+
18
+ ```ruby
19
+ gem 'ruby-dart2js'
20
+ gem 'dart-rails'
21
+ ```
22
+
23
+ 2. run `rails generate dart:assets` this will bring you:
24
+
25
+ ```sh
26
+ rails g dart:assets
27
+ create app/assets/dart
28
+ create app/assets/dart/dart_app.dart
29
+ create app/assets/dart/dart_app.js
30
+ create app/assets/dart/pubspec.yaml
31
+ ```
32
+
33
+ 3. Currently you still need to add following to the bottom of your body in the layout:
34
+
35
+ `layout.html.erb` (for instance)
36
+
37
+ ```
38
+ <%= dart_include_tag 'dart_app' %>
39
+ <%= javascript_include_tag 'dart' %>
40
+ ```
41
+
42
+ 4. *Optional:* run `rake pub:get` to respect the dependencies in your `pubspec.yaml`.
43
+ Initially the pubspec contains `rails_ujs` as dependency, this is just basic for now,
44
+ so you probably want to omit it if you're still using JQuery.
45
+
46
+ *Note:* you'll need to point `DART_SDK_HOME` to the root of your dart-sdk unless your `pub` executable is in the `PATH`
47
+
48
+ ### Compatibility ###
49
+
50
+ ###### UglifyJs ######
51
+
52
+ Don't worry if you're experiencing a
53
+
54
+ ```
55
+ ExecJS::ProgramError: RangeError: Maximum call stack size exceeded
56
+ ```
57
+
58
+ This is exactly what it means, a stackoverflow of UglifyJs. According to
59
+ [RangeError: Maximum call stack size exceeded #414](https://github.com/mishoo/UglifyJS2/issues/414) UglifyJs is
60
+ massivly recursive and your dart2js file might have blown it. This happened to me with an AngluarDart application.
61
+ You may simply disable UglifyJs in the environment file.
62
+
63
+ ```
64
+ ...
65
+ # Compress JavaScripts and CSS.
66
+ # config.assets.js_compressor = :uglifier
67
+ ...
68
+ ```
69
+
70
+ ###### assets:precompile + native .dart files ######
71
+
72
+ As of rails 4 we are facing a problem for the productive environments.
73
+ See [Inability to compile nondigest and digest assets breaks compatibility with bad gems #49](https://github.com/rails/sprockets-rails/issues/49)
74
+
75
+ You may optionally add this to your Gemfile
76
+
77
+ ```
78
+ gem 'non-stupid-digest-assets', '>= 1.1', github: 'm0gg/non-stupid-digest-assets'
79
+ ```
80
+
81
+ this will enable a workaround for digesting the assets while precompiling dart files as
82
+ seen in [non-stupid-digest-assets](https://github.com/alexspeller/non-stupid-digest-assets) and
83
+ additionally rewrite the manifests to use the non-digest files.
84
+
85
+ ###### ruby-dart2js ######
86
+
87
+ This gem is needed for the `dart2js` compiler compatibility.
88
+
89
+ See [ruby-dart2js](https://github.com/m0gg/ruby-dart2js) on github for setup.
90
+
91
+ ```
92
+ <%= javascript_include_tag 'dart' %>
93
+ ```
94
+ in the layout needs to stay as it is unless you want to drop
95
+ compatibility for browsers without dart support.
96
+ It includes the bundled `javascripts/dart.js` from this gem.
97
+
98
+ This will parse all script-tags with `type="application/dart"` and replace them with tags that request
99
+ the appropriate js file.
100
+ ```html
101
+ <script type="application/dart" src="/assets/dart_app.dart"></script>
102
+ ```
103
+ would get
104
+ ```html
105
+ <script type="application/javascript" src="/assets/dart_app.js"></script>
106
+ ```
107
+ To provide the transcompiled version of you dart-file you'll need a js template
108
+ with a directive which could look like this
109
+ ```javascript
110
+ //
111
+ //= dart dart_app
112
+ ```
113
+
114
+ ###### Sprockets ######
115
+
116
+ `Dart::SprocketsDirectiveDart2js` extends Sprockets base `DirectiveProcessor` and thus each dart-file
117
+ included (via `dart` directive) in `.js` templates get compiled and inserted.
118
+
119
+
120
+ ### Changelog ###
121
+ v0.3.0 - 21. Jan. 2015:
122
+ * with v0.2.0 of ruby-dart2js, minifying is supported and will bump the feature version of dart-rails with updated dependencies
123
+
124
+ v0.2.5 - 14. Jan. 2015:
125
+ * fixed a misplaced initializer for non-stupid-digest-assets that caused every asset to be non-digested
126
+
127
+ v0.2.4 - 13. Dec. 2014 - update:
128
+ * corrected `pubspec.yml` to assign valid `dart_app` as name
129
+
130
+ v0.2.3 - 13. Dec. 2014:
131
+ * fix 2 issues documented as [Fix the generated pubspec.yml #13](https://github.com/m0gg/dart-rails/issues/13)
132
+ and [Generators run each time rails g runs #12](https://github.com/m0gg/dart-rails/issues/12)
133
+ * generators no longer try to run `rails g dart:assets` as javascript_engine
134
+ * generated `pubspec.yml` now staticly assigns `dart-app` as name
135
+ * railtie restructured and split into two engines
136
+
137
+ v0.2.2 - 12. Dec. 2014 - update:
138
+ * dart-rails is now available via rubygems, it's first published with version 0.2.2
139
+
140
+ v0.2.2 - 04. Dec. 2014:
141
+ * due to sprockets digest method, we are forced to use a workaround to allow
142
+ "precompilation" of .dart files, see [non-stupid-digest-assets](https://github.com/alexspeller/non-stupid-digest-assets)
143
+ and [Inability to compile nondigest and digest assets breaks compatibility with bad gems #49](https://github.com/rails/sprockets-rails/issues/49)
144
+ it is optionally (and automatically) available by adding `gem 'non-stupid-digest-assets', '>= 1.1', github: 'm0gg/non-stupid-digest-assets'
145
+ ` to your Gemfile
146
+ * added dart_app.js to precompile list
147
+ * faced an issue with UglifyJs stackoverflowing with too large dart2js files
148
+
149
+ v0.2.1 - 18. Oct. 2014:
150
+ * dart2js compilation no longer recurses to infinity and further, this problem came uo to me while working with angularDart, which now compiles fine (takes some time though)
151
+ * sorry for dev-gap, been quite busy in university
152
+
153
+ v0.2.0 - 08. Oct. 2014:
154
+ * dart-rails can now detect changes in dart code and its dependencies
155
+ * RailsUjs call is now in the initial dart_app.dart template
156
+ * fixed pathname to touch for change recognition
157
+ * renamed relevant constants to Dart2Js
158
+ * bumped ruby-dart2js version to 0.1.0
159
+
160
+ v0.1.2 - 27. Sep. 2014:
161
+ * slightly different dart2js output directory-tree, now based on md5-hashed timestamps
162
+
163
+ v0.1.1 - 29. Aug. 2014:
164
+ * dart-rails will no longer break assets:precompile
165
+
166
+ v0.1.0 - 29. Aug. 2014:
167
+ * Note that `.dart2js` templates are no longer needed. Sprockets
168
+ DirectiveProcessor for Javascript ist now capable of including
169
+ dart2js-compiled scripts via a `//= dart dart_app` directive. See
170
+ updated sample application on github.
171
+ * Errors during dart2js compilation will now be handled by Sprockets
172
+ and thus the exception message will be thrown in the created js file.
173
+ For now there will be also an output on the console.
174
+ * As for newest SprocketsRails there is no longer the need of manually
175
+ adding `dart.js` to the precompilation list.
176
+ * Compiled scripts will reside in the `#{Rails.root}/tmp/cache/` directory.
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'DartRails'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,22 @@
1
+ // Remap scripts for browsers that are not "Dartium"
2
+ (function() {
3
+ if(navigator.userAgent.indexOf('(Dart)') === -1) {
4
+ var scripts = document.getElementsByTagName("script");
5
+ var length = scripts.length;
6
+ // run through all script tags and find the ones with type="application/dart"
7
+ for(var i = 0; i < length; ++i) {
8
+ if(scripts[i].type == "application/dart") {
9
+ if(scripts[i].src && scripts[i].src != '') {
10
+ var script = document.createElement('script');
11
+ // rewrite file extension to .js
12
+ script.src = scripts[i].src.replace(/\.dart(?=\?|$)/, '.js');
13
+ script.type = "application/javascript";
14
+ var parent = scripts[i].parentNode;
15
+ document.currentScript = script;
16
+ // finally replace script tag
17
+ parent.replaceChild(script, scripts[i]);
18
+ }
19
+ }
20
+ }
21
+ }
22
+ })();
@@ -0,0 +1 @@
1
+ require 'dart/railtie'
@@ -0,0 +1,34 @@
1
+ require 'action_view'
2
+
3
+ module Dart #:nodoc:
4
+ module Rails #:nodoc:
5
+
6
+ # ActionView helper mixin for dart
7
+ module DartAssetHelper
8
+
9
+ # Returns html_safe dart/application script tag.
10
+ # Example:
11
+ #
12
+ # '<script src="/assets/dart_app.dart" type="application/dart"></script>'
13
+ #
14
+ # Remember: only one dart script-tag is allowed!
15
+ def dart_include_tag(*sources)
16
+ options = sources.extract_options!.stringify_keys
17
+ sources.uniq.map { |source|
18
+ tag_options = {
19
+ 'src' => dart_path(source, options),
20
+ 'type' => 'application/dart'
21
+ }.merge(options)
22
+ content_tag(:script, '', tag_options)
23
+ }.join('\n').html_safe
24
+ end
25
+
26
+ # Returns path to dart script, similar to javascript_path
27
+ def dart_path(source, options = {})
28
+ path_to_asset(source, { :extname => '.dart' }.merge!(options))
29
+ end
30
+
31
+ alias_method :path_to_dart, :dart_path
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/engine'
2
+
3
+ module Dart #:nodoc:
4
+ module Rails #:nodoc:
5
+ class DartEngine < ::Rails::Engine
6
+
7
+ initializer :assets do |app|
8
+
9
+ # Register mime-types
10
+ app.assets.register_mime_type 'application/dart', '.dart'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails/generators'
2
+
3
+ module Dart
4
+ module Generators
5
+ class AssetsGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ # Copies contents of template/dart to assets
9
+ # invoke with:
10
+ #
11
+ # $# rails g dart:assets
12
+ #
13
+ def generate_dart
14
+ directory 'dart', 'app/assets/dart/'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ import 'package:rails_ujs/rails_ujs.dart';
2
+
3
+ RailsUjs ujsHelper;
4
+
5
+ void main() {
6
+ ujsHelper = new RailsUjs();
7
+ }
@@ -0,0 +1,2 @@
1
+ // dart directive issues dart2js-compilation
2
+ //= dart dart_app
@@ -0,0 +1,4 @@
1
+ name: dart_app
2
+ description:
3
+ dependencies:
4
+ rails_ujs: any
@@ -0,0 +1,33 @@
1
+ require 'rails/engine'
2
+
3
+ module Dart #:nodoc:
4
+ module Rails #:nodoc:
5
+ class JsCompatEngine < ::Rails::Engine
6
+
7
+ # Handle gem provided javascripts
8
+ initializer :assets do |app|
9
+
10
+ #initialize dart2js dir
11
+ hash = (Digest::MD5.new << Time.now.to_s).to_s
12
+ DART2JS_OUT_DIR = app.root.join('tmp', 'cache', 'assets', 'development', 'dart', hash)
13
+ FileUtils.mkdir_p DART2JS_OUT_DIR unless File.directory?(DART2JS_OUT_DIR)
14
+
15
+ # make dart.js compatibility-script accessible for sprockets
16
+ app.assets.append_path(File.join(root, 'lib', 'assets', 'javascripts'))
17
+
18
+ # make dart2js results accessible for sprockets
19
+ app.assets.append_path(Dart::Rails::JsCompatEngine::DART2JS_OUT_DIR)
20
+
21
+ # precompile compatibility-script(s)
22
+ # TODO: does not work with `app.assets.precompile += ...`
23
+ ::Rails.application.config.assets.precompile += %w(dart_app.js dart.js)
24
+
25
+
26
+ # Mixin process_dart_directive in standard DirectiveProcessor for JS
27
+ Sprockets::DirectiveProcessor.instance_eval do
28
+ include Dart::DirectiveProcessorDart2js
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ module Dart #:nodoc:
2
+ module Rails #:nodoc:
3
+
4
+ # TemplateHandler for dart scripts
5
+ class TemplateHandler
6
+ def self.erb_handler
7
+ debugger
8
+ @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
9
+ end
10
+
11
+ def self.call(template)
12
+ debugger
13
+ erb_handler.call(template)
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ # Finally register TemplateHandler in ActionView
20
+ ActiveSupport.on_load(:action_view) do
21
+ ActionView::Template.register_template_handler :dart, Dart::Rails::TemplateHandler
22
+ end
@@ -0,0 +1,5 @@
1
+ module Dart #:nodoc:
2
+ module Rails #:nodoc:
3
+ VERSION = '0.3.2-p1'
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ require 'rails'
2
+ require 'rails/railtie'
3
+ require 'dart/sprockets/directive_processor_dart2js'
4
+ require 'dart/rails/version'
5
+ require 'dart/rails/js_compat_engine'
6
+ require 'dart/rails/dart_asset_helper'
7
+ require 'dart/rails/generators/assets/generator'
8
+ require 'dart/rails/template_handler'
9
+
10
+
11
+ module Dart #:nodoc:
12
+ class Railtie < ::Rails::Railtie
13
+
14
+ # [Optionally via: https://github.com/m0gg/non-stupid-digest-assets]
15
+ # do not digest .dart files
16
+ # digest during compilation breaks darts 'import' functionality
17
+ # currently sprockets-rails does not allow mixed procompilation of digest and non-digest assets
18
+ # see https://github.com/rails/sprockets-rails/issues/49
19
+ # workaround is a 51-liner gem 'non-stupid-digest-assets'
20
+ # https://github.com/alexspeller/non-stupid-digest-assets
21
+ #
22
+ begin
23
+ require 'non-stupid-digest-assets'
24
+ if defined? NonStupidDigestAssets
25
+ NonStupidDigestAssets.whitelist += [ /.*\.dart/, 'dart_app.js', 'dart_app' ]
26
+ end
27
+ rescue Exception => e
28
+ ::Rails.logger.info 'No non-stupid-digest-assets support. You may face issues with native dart-support!'
29
+ end
30
+
31
+ config.after_initialize do |app|
32
+ # Mixin helper-module in ActionView
33
+ ActionView::Base.instance_eval do
34
+ include Dart::Rails::DartAssetHelper
35
+ end
36
+ end
37
+ end
38
+ end