ruby-haml-js 0.0.1

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 (52) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +120 -0
  4. data/HISTORY.md +2 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +39 -0
  7. data/Rakefile +37 -0
  8. data/lib/ruby-haml-js.rb +2 -0
  9. data/lib/ruby-haml-js/engine.rb +13 -0
  10. data/lib/ruby-haml-js/template.rb +61 -0
  11. data/lib/ruby-haml-js/version.rb +5 -0
  12. data/lib/tasks/pakunok_tasks.rake +4 -0
  13. data/ruby-haml-js.gemspec +25 -0
  14. data/spec/dummy/Rakefile +7 -0
  15. data/spec/dummy/app/assets/javascripts/application.js +10 -0
  16. data/spec/dummy/app/assets/javascripts/sample.jst.hamljs +3 -0
  17. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  18. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  19. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  20. data/spec/dummy/app/mailers/.gitkeep +0 -0
  21. data/spec/dummy/app/models/.gitkeep +0 -0
  22. data/spec/dummy/app/views/layouts/application.html.erb +16 -0
  23. data/spec/dummy/app/views/pages/index.html.erb +29 -0
  24. data/spec/dummy/config.ru +4 -0
  25. data/spec/dummy/config/application.rb +46 -0
  26. data/spec/dummy/config/boot.rb +10 -0
  27. data/spec/dummy/config/database.yml +25 -0
  28. data/spec/dummy/config/environment.rb +5 -0
  29. data/spec/dummy/config/environments/development.rb +27 -0
  30. data/spec/dummy/config/environments/production.rb +51 -0
  31. data/spec/dummy/config/environments/test.rb +39 -0
  32. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  33. data/spec/dummy/config/initializers/inflections.rb +10 -0
  34. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  35. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  36. data/spec/dummy/config/initializers/session_store.rb +8 -0
  37. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  38. data/spec/dummy/config/locales/en.yml +5 -0
  39. data/spec/dummy/config/routes.rb +60 -0
  40. data/spec/dummy/lib/assets/.gitkeep +0 -0
  41. data/spec/dummy/log/.gitkeep +0 -0
  42. data/spec/dummy/public/404.html +26 -0
  43. data/spec/dummy/public/422.html +26 -0
  44. data/spec/dummy/public/500.html +26 -0
  45. data/spec/dummy/public/favicon.ico +0 -0
  46. data/spec/dummy/script/rails +6 -0
  47. data/spec/spec_helper.rb +12 -0
  48. data/spec/support/global.rb +9 -0
  49. data/spec/support/matchers.rb +18 -0
  50. data/spec/template_spec.rb +43 -0
  51. data/vendor/assets/javascripts/haml.js +651 -0
  52. metadata +185 -0
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ *.swp
5
+ spec/dummy/db/*.sqlite3
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/public/assets/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ group :development, :test do
5
+ gem 'pry'
6
+ end
@@ -0,0 +1,120 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby-haml-js (0.0.1)
5
+ execjs
6
+ sprockets (>= 2.0.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.1.1)
12
+ actionpack (= 3.1.1)
13
+ mail (~> 2.3.0)
14
+ actionpack (3.1.1)
15
+ activemodel (= 3.1.1)
16
+ activesupport (= 3.1.1)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ i18n (~> 0.6)
20
+ rack (~> 1.3.2)
21
+ rack-cache (~> 1.1)
22
+ rack-mount (~> 0.8.2)
23
+ rack-test (~> 0.6.1)
24
+ sprockets (~> 2.0.2)
25
+ activemodel (3.1.1)
26
+ activesupport (= 3.1.1)
27
+ builder (~> 3.0.0)
28
+ i18n (~> 0.6)
29
+ activerecord (3.1.1)
30
+ activemodel (= 3.1.1)
31
+ activesupport (= 3.1.1)
32
+ arel (~> 2.2.1)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.1.1)
35
+ activemodel (= 3.1.1)
36
+ activesupport (= 3.1.1)
37
+ activesupport (3.1.1)
38
+ multi_json (~> 1.0)
39
+ arel (2.2.1)
40
+ builder (3.0.0)
41
+ coderay (0.9.8)
42
+ diff-lcs (1.1.2)
43
+ erubis (2.7.0)
44
+ execjs (1.2.9)
45
+ multi_json (~> 1.0)
46
+ hike (1.2.1)
47
+ i18n (0.6.0)
48
+ json (1.6.1)
49
+ mail (2.3.0)
50
+ i18n (>= 0.4.0)
51
+ mime-types (~> 1.16)
52
+ treetop (~> 1.4.8)
53
+ method_source (0.6.0)
54
+ ruby_parser (>= 2.0.5)
55
+ mime-types (1.16)
56
+ multi_json (1.0.3)
57
+ polyglot (0.3.2)
58
+ pry (0.9.3)
59
+ coderay (>= 0.9.8)
60
+ method_source (>= 0.6.0)
61
+ ruby_parser (>= 2.0.5)
62
+ slop (~> 1.9.0)
63
+ rack (1.3.5)
64
+ rack-cache (1.1)
65
+ rack (>= 0.4)
66
+ rack-mount (0.8.3)
67
+ rack (>= 1.0.0)
68
+ rack-ssl (1.3.2)
69
+ rack
70
+ rack-test (0.6.1)
71
+ rack (>= 1.0)
72
+ rails (3.1.1)
73
+ actionmailer (= 3.1.1)
74
+ actionpack (= 3.1.1)
75
+ activerecord (= 3.1.1)
76
+ activeresource (= 3.1.1)
77
+ activesupport (= 3.1.1)
78
+ bundler (~> 1.0)
79
+ railties (= 3.1.1)
80
+ railties (3.1.1)
81
+ actionpack (= 3.1.1)
82
+ activesupport (= 3.1.1)
83
+ rack-ssl (~> 1.3.2)
84
+ rake (>= 0.8.7)
85
+ rdoc (~> 3.4)
86
+ thor (~> 0.14.6)
87
+ rake (0.9.2)
88
+ rdoc (3.10)
89
+ json (~> 1.4)
90
+ rspec (2.6.0)
91
+ rspec-core (~> 2.6.0)
92
+ rspec-expectations (~> 2.6.0)
93
+ rspec-mocks (~> 2.6.0)
94
+ rspec-core (2.6.4)
95
+ rspec-expectations (2.6.0)
96
+ diff-lcs (~> 1.1.2)
97
+ rspec-mocks (2.6.0)
98
+ ruby_parser (2.1.0)
99
+ sexp_processor (~> 3.0)
100
+ sexp_processor (3.0.5)
101
+ slop (1.9.1)
102
+ sprockets (2.0.3)
103
+ hike (~> 1.2)
104
+ rack (~> 1.0)
105
+ tilt (~> 1.1, != 1.3.0)
106
+ thor (0.14.6)
107
+ tilt (1.3.3)
108
+ treetop (1.4.10)
109
+ polyglot
110
+ polyglot (>= 0.3.1)
111
+ tzinfo (0.3.30)
112
+
113
+ PLATFORMS
114
+ ruby
115
+
116
+ DEPENDENCIES
117
+ pry
118
+ rails (>= 3.1.1)
119
+ rspec
120
+ ruby-haml-js!
@@ -0,0 +1,2 @@
1
+ # 0.0.1 - 19 October 2011
2
+ Initial release. Extracted from the Pakunok gem.
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Dmytrii Nagirniak
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,39 @@
1
+ # Ruby HAML-JS
2
+
3
+ Precompiles the HAML-JS templates into a function.
4
+
5
+ This can be used as a standalone template or as part of Rails 3.1 assets pipeline.
6
+
7
+ # Installation - Rails 3.1
8
+
9
+ ```ruby
10
+ # Gemfile
11
+ gem 'ruby-haml-js'
12
+ ```
13
+
14
+ ```bash
15
+ # Then install it
16
+ bundle
17
+ ```
18
+
19
+ # Usage - with Rails 3.1 assets pipeline
20
+
21
+ 1. Put your template unders `app/assets/javascripts` (or other path where Rails can find it).
22
+ 2. Use the naming `my-template.jst.hamljs`.
23
+ 3. Serve the template to browser by `require my-template` from `application.js` or link to it as `my-template.js`
24
+ 4. Use the template from the JavaScript: `JST['my-template']({your: 'local', variables: 'go here'})`
25
+
26
+
27
+ # Development
28
+
29
+ - Source hosted at [GitHub](https://github.com/dnagir/ruby-haml-js)
30
+ - Report issues and feature requests to [GitHub Issues](https://github.com/dnagir/ruby-haml-js/issues)
31
+
32
+ Pull requests are very welcome! But please write the specs.
33
+
34
+ To start, clone the repo and then:
35
+
36
+ ```shell
37
+ bundle install
38
+ bundle exec rspec spec/
39
+ ```
@@ -0,0 +1,37 @@
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 = 'Pakunok'
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
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ require 'ruby-haml-js/template'
2
+ require 'ruby-haml-js/engine' if defined?(::Rails)
@@ -0,0 +1,13 @@
1
+ module RubyHamlJs
2
+ class Engine < Rails::Engine
3
+ initializer "ruby-hamljs.configure_rails_initialization", :before => 'sprockets.environment', :group => :all do |app|
4
+ next unless app.config.assets.enabled
5
+
6
+ require 'sprockets'
7
+ require 'sprockets/engines'
8
+ require 'ruby-haml-js/template'
9
+ #app.config.assets.register_engine '.hamljs', ::RubyHamlJs::Template
10
+ Sprockets.register_engine '.hamljs', ::RubyHamlJs::Template
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,61 @@
1
+ require 'tilt/template'
2
+
3
+ module RubyHamlJs
4
+ class Template < Tilt::Template
5
+ self.default_mime_type = 'application/javascript'
6
+
7
+ def self.engine_initialized?
8
+ defined? ::ExecJS
9
+ end
10
+
11
+ def initialize_engine
12
+ require_template_library 'execjs'
13
+ end
14
+
15
+ def prepare
16
+ end
17
+
18
+ # Compiles the template using HAML-JS
19
+ #
20
+ # Returns a JS function definition String. The result should be
21
+ # assigned to a JS variable.
22
+ #
23
+ # # => "function(data) { ... }"
24
+ def evaluate(scope, locals, &block)
25
+ compile_to_function
26
+ end
27
+
28
+
29
+
30
+ private
31
+
32
+ def compile_to_function
33
+ function = ExecJS.
34
+ compile(self.class.haml_source).
35
+ eval "Haml('#{js_string data}', {escapeHtmlByDefault: true, customEscape: #{js_custom_escape}}).toString()"
36
+ # make sure function is annonymous
37
+ function.sub /function \w+/, "function "
38
+ end
39
+
40
+ def js_string str
41
+ (str || '').
42
+ gsub("'") {|m| "\\'" }.
43
+ gsub("\n") {|m| "\\n" }
44
+ end
45
+
46
+ def js_custom_escape
47
+ # TODO: Figure out how to configure this
48
+ escape_function = nil
49
+ escape_function ? "'#{js_string escape_function}'" : 'null'
50
+ end
51
+
52
+ class << self
53
+ def haml_source
54
+ # Haml source is an asset
55
+ @haml_source ||= IO.read File.expand_path('../../../vendor/assets/javascripts/haml.js', __FILE__)
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+
@@ -0,0 +1,5 @@
1
+ module RubyHamlJs
2
+ module Version
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :pakunok do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ruby-haml-js/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ruby-haml-js"
7
+ s.version = RubyHamlJs::Version::VERSION
8
+ s.authors = ["Dmytrii Nagirniak"]
9
+ s.email = ["dnagir@gmail.com"]
10
+ s.homepage = "http://github.com/dnagir/ruby-haml-js"
11
+ s.summary = %q{Precompile HAML-JS templates with or without Rails 3.1 assets pipeline}
12
+ s.description = %q{ruby-haml-js provides a Tilt template that you can use on the server side to compile HAML-JS templates. Handy for using it wth Bakcbone.js, Spine.js etc.}
13
+
14
+ s.rubyforge_project = "ruby-haml-js"
15
+
16
+ s.add_dependency 'sprockets', '>= 2.0.0'
17
+ s.add_dependency 'execjs'
18
+ s.add_development_dependency 'rspec'
19
+ s.add_development_dependency 'rails', '>= 3.1.1'
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,10 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ // Disabled all below :)
8
+ // require jquery
9
+ // require jquery_ujs
10
+ // require_tree .
@@ -0,0 +1,3 @@
1
+ %h3 This is the sample from template that has current time dynamic time stamp
2
+ .time= time
3
+
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <!-- <%= stylesheet_link_tag "application" %> -->
6
+ <!-- <%= javascript_include_tag "application" %> -->
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ <%= include_javascripts %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,29 @@
1
+ <h1>Samples</h1>
2
+
3
+ <h2>HAML template</h2>
4
+ <button id='haml-update'>Update template</button>
5
+ <div id='haml-placeholder'> </div>
6
+
7
+ <p>
8
+ The compiled sample HAML template is <a href='<%= asset_path 'sample.js' %>'>here</a>.
9
+ </p>
10
+
11
+ <%
12
+ [
13
+ 'colorpicker.js', 'colorpicker.css',
14
+ 'jquery.js', 'jquery-ui.js' 'jquery-ui/pack/dialog.js',
15
+ 'fileuploader.js', 'fileuploader.css', 'fileuploader/loading.gif',
16
+ 'innershiv.js',
17
+ 'jquery.form.js',
18
+ 'haml/haml-foo-bar.js'
19
+ ].each do |asset|
20
+
21
+ %>
22
+ <% path = asset_path "pakunok/#{asset}"%>
23
+ <p>
24
+ <a href="<%= path %>">
25
+ <%= path %>
26
+ </a>
27
+ </p>
28
+ <% end%>
29
+