haml_coffee_assets 0.5.3 → 0.6.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.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Haml Coffee Assets [![Build Status](https://secure.travis-ci.org/netzpirat/haml_coffee_assets.png)](http://travis-ci.org/netzpirat/haml_coffee_assets)
2
2
 
3
3
  Haml Coffee Assets compiles [Haml Coffee](https://github.com/9elements/haml-coffee) templates in the Rails 3.1
4
- asset pipeline, so you can use them as JavaScript templates in your JavaScript heavy Rails application.
4
+ asset pipeline, so you can use them as JavaScript templates in your JavaScript heavy Rails application. It also works as [Tilt](https://github.com/rtomayko/tilt/) template without Rails.
5
5
 
6
6
  Tested on MRI Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest version of JRuby.
7
7
 
@@ -46,78 +46,6 @@ And require the `hamlcoffee.js` in your `app/assets/javascripts/application.js.c
46
46
  This provides the default escaping and the global context functions. Read more about it in the configuration section
47
47
  below.
48
48
 
49
- ### JavaScript runtimes
50
-
51
- Haml Coffee Assets uses [ExecJS](https://github.com/sstephenson/execjs) to pick the best runtime to evaluate the
52
- CoffeeScript and generate the JavaScript template.
53
-
54
- * With CRuby you want to use a V8 JavaScript Engine or Mozilla SpiderMonkey.
55
- * With JRuby you want to use the Mozilla Rhino.
56
- * On Mac OS X you want to use Apple JavaScriptCore.
57
- * On Linux or as a node.js developer you want to use Node.js (V8).
58
- * On Windows you want to use Microsoft Windows Script Host.
59
-
60
- The following sections gives you a short overview of the available JavaScript runtimes and how to install it.
61
-
62
- ### Node.js (V8)
63
-
64
- You can install [node.js](http://nodejs.org/) and use its V8 engine. On OS X you may want to install it with
65
- [Homebrew](http://mxcl.github.com/homebrew/), on Linux with your package manager and on Windows you have to download and
66
- install the [executable](http://www.nodejs.org/#download).
67
-
68
- ### V8 JavaScript Engine
69
-
70
- To use the [V8 JavaScript Engine](http://code.google.com/p/v8/), simple add `therubyracer` to your `Gemfile`.
71
- The Ruby Racer acts as a bridge between Ruby and the V8 engine, that will be automatically installed by the Ruby Racer.
72
-
73
- ```ruby
74
- group :development do
75
- gem 'therubyracer'
76
- end
77
- ```
78
-
79
- Another alternative is [Mustang](https://github.com/nu7hatch/mustang), a Ruby proxy library for the awesome Google V8
80
- JavaScript engine. Just add `mustang` to your `Gemfile`:
81
-
82
- ```ruby
83
- group :development do
84
- gem 'mustang'
85
- end
86
- ```
87
-
88
- ### Mozilla SpiderMonkey
89
-
90
- To use [Mozilla SpiderMonkey](https://developer.mozilla.org/en/SpiderMonkey), simple add `johnson` to your `Gemfile`.
91
- Johnson embeds the Mozilla SpiderMonkey JavaScript runtime as a C extension.
92
-
93
- ```ruby
94
- group :development do
95
- gem 'johnson'
96
- end
97
- ```
98
-
99
- ### Mozilla Rhino
100
-
101
- If you're using JRuby, you can embed the [Mozilla Rhino](http://www.mozilla.org/rhino/) runtime by adding `therubyrhino`
102
- to your `Gemfile`:
103
-
104
- ```ruby
105
- group :development do
106
- gem 'therubyrhino'
107
- end
108
- ```
109
-
110
- ### Apple JavaScriptCore
111
-
112
- [JavaScriptCore](http://developer.apple.com/library/mac/#documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/index.html)
113
- is Safari's Nitro JavaScript Engine and only usable on Mac OS X. You don't have to install anything, because
114
- JavaScriptCore is already packaged with Mac OS X.
115
-
116
- ### Microsoft Windows Script Host
117
-
118
- [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) is available on any Microsoft
119
- Windows operating systems.
120
-
121
49
  ## Usage
122
50
 
123
51
  You should place all your Haml Coffee templates in the `app/assets/templates` directory and include all templates from
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- require 'rails'
6
5
  require 'tilt'
7
6
  require 'sprockets'
8
7
  require 'execjs'
@@ -10,4 +9,11 @@ require 'execjs'
10
9
  require 'haml_coffee_assets/version'
11
10
  require 'haml_coffee_assets/haml_coffee'
12
11
  require 'haml_coffee_assets/haml_coffee_template'
13
- require 'haml_coffee_assets/engine'
12
+
13
+ if defined?(Rails)
14
+ require 'rails'
15
+ require 'haml_coffee_assets/engine'
16
+ else
17
+ require 'sprockets'
18
+ Sprockets.register_engine '.hamlc', HamlCoffeeAssets::HamlCoffeeTemplate
19
+ end
@@ -5,83 +5,94 @@ module HamlCoffeeAssets
5
5
  # Handles compilation of Haml CoffeeScript templates to pure JavaScript.
6
6
  #
7
7
  module HamlCoffee
8
+
9
+ class Configuration
10
+
11
+ # Constructor with defaults
12
+ def initialize
13
+ self.namespace = 'window.JST'
14
+ self.format = 'html5'
15
+ self.uglify = false
16
+ self.basename = false
17
+ self.escapeHtml = true
18
+ self.escapeAttributes = true
19
+ self.cleanValue = true
20
+ self.customHtmlEscape = 'window.HAML.escape'
21
+ self.customCleanValue = 'window.HAML.cleanValue'
22
+ self.customPreserve = 'window.HAML.preserve'
23
+ self.customFindAndPreserve = 'window.HAML.findAndPreserve'
24
+ self.preserveTags = 'textarea,pre'
25
+ self.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base'
26
+ self.context = ''
27
+ end
28
+
29
+ # Template namespace
30
+ #
31
+ attr_accessor :namespace
32
+
33
+ # Template format, either html5, html4 or xhtml
34
+ #
35
+ attr_accessor :format
36
+
37
+ # Uglify HTML output by skip indention
38
+ #
39
+ attr_accessor :uglify
40
+
41
+ # Ignore path when generate the JST
42
+ #
43
+ attr_accessor :basename
44
+
45
+ # Escape template code output
46
+ #
47
+ attr_accessor :escapeHtml
48
+
49
+ # Escape template code output for attributes
50
+ #
51
+ attr_accessor :escapeAttributes
52
+
53
+ # Clean inline CoffeeScript values
54
+ #
55
+ attr_accessor :cleanValue
8
56
 
9
- # Template namespace
10
- #
11
- mattr_accessor :namespace
12
- self.namespace = 'window.JST'
13
-
14
- # Template format, either html5, html4 or xhtml
15
- #
16
- mattr_accessor :format
17
- self.format = 'html5'
18
-
19
- # Uglify HTML output by skip indention
20
- #
21
- mattr_accessor :uglify
22
- self.uglify = false
23
-
24
- # Ignore path when generate the JST
25
- #
26
- mattr_accessor :basename
27
- self.basename = false
28
-
29
- # Escape template code output
30
- #
31
- mattr_accessor :escapeHtml
32
- self.escapeHtml = true
33
-
34
- # Escape template code output for attributes
35
- #
36
- mattr_accessor :escapeAttributes
37
- self.escapeAttributes = true
38
-
39
- # Clean inline CoffeeScript values
40
- #
41
- mattr_accessor :cleanValue
42
- self.cleanValue = true
43
-
44
- # Custom global HTML escaping function
45
- #
46
- mattr_accessor :customHtmlEscape
47
- self.customHtmlEscape = 'window.HAML.escape'
48
-
49
- # Custom global code clean value function
50
- #
51
- mattr_accessor :customCleanValue
52
- self.customCleanValue = 'window.HAML.cleanValue'
53
-
54
- # Custom preserve function
55
- #
56
- mattr_accessor :customPreserve
57
- self.customPreserve = 'window.HAML.preserve'
58
-
59
- # Custom find and preserve function
60
- #
61
- mattr_accessor :customFindAndPreserve
62
- self.customFindAndPreserve = 'window.HAML.findAndPreserve'
63
-
64
- # List of tags to preserve
65
- #
66
- mattr_accessor :preserveTags
67
- self.preserveTags = 'textarea,pre'
68
-
69
- # List of self closing tags
70
- #
71
- mattr_accessor :selfCloseTags
72
- self.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base'
73
-
74
- # Custom global context to merge
75
- #
76
- mattr_accessor :context
77
- self.context = ''
57
+ # Custom global HTML escaping function
58
+ #
59
+ attr_accessor :customHtmlEscape
60
+
61
+ # Custom global code clean value function
62
+ #
63
+ attr_accessor :customCleanValue
64
+
65
+ # Custom preserve function
66
+ #
67
+ attr_accessor :customPreserve
68
+
69
+ # Custom find and preserve function
70
+ #
71
+ attr_accessor :customFindAndPreserve
72
+
73
+ # List of tags to preserve
74
+ #
75
+ attr_accessor :preserveTags
76
+
77
+ # List of self closing tags
78
+ #
79
+ attr_accessor :selfCloseTags
80
+
81
+ # Custom global context to merge
82
+ #
83
+ attr_accessor :context
84
+
85
+ end
78
86
 
79
87
  class << self
88
+
89
+ attr_accessor :configuration
80
90
 
81
91
  # Configure HamlCoffee
82
92
  #
83
93
  def configure
84
- yield self
94
+ self.configuration ||= Configuration.new
95
+ yield self.configuration
85
96
  end
86
97
 
87
98
  # Compile the Haml CoffeeScript template.
@@ -92,12 +103,13 @@ module HamlCoffeeAssets
92
103
  # @return [String] the compiled template in JavaScript
93
104
  #
94
105
  def compile(name, source, jst = true)
95
- runtime.call('HamlCoffeeAssets.compile', name, source, jst, HamlCoffee.namespace, HamlCoffee.format, HamlCoffee.uglify, HamlCoffee.basename,
96
- HamlCoffee.escapeHtml, HamlCoffee.escapeAttributes, HamlCoffee.cleanValue,
97
- HamlCoffee.customHtmlEscape, HamlCoffee.customCleanValue,
98
- HamlCoffee.customPreserve, HamlCoffee.customFindAndPreserve,
99
- HamlCoffee.preserveTags, HamlCoffee.selfCloseTags,
100
- HamlCoffee.context)
106
+ self.configuration ||= Configuration.new
107
+ runtime.call('HamlCoffeeAssets.compile', name, source, jst, configuration.namespace, configuration.format, configuration.uglify, configuration.basename,
108
+ configuration.escapeHtml, configuration.escapeAttributes, configuration.cleanValue,
109
+ configuration.customHtmlEscape, configuration.customCleanValue,
110
+ configuration.customPreserve, configuration.customFindAndPreserve,
111
+ configuration.preserveTags, configuration.selfCloseTags,
112
+ configuration.context)
101
113
  end
102
114
 
103
115
  private
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module HamlCoffeeAssets
4
- VERSION = '0.5.3' unless defined?(HamlCoffeeAssets::VERSION)
4
+ VERSION = '0.6.0' unless defined?(HamlCoffeeAssets::VERSION)
5
5
  end
@@ -1,3 +1,5 @@
1
+ <% configuration = HamlCoffeeAssets::HamlCoffee.configuration || HamlCoffeeAssets::HamlCoffee::Configurationi.new %>
2
+
1
3
  # HAML Coffee namespace
2
4
  #
3
5
  window.HAML ||= {}
@@ -82,7 +84,7 @@ window.HAML.preserve ||= (text) ->
82
84
  # @param text [String] the text to preserve
83
85
  # @return [String] the preserved text
84
86
  #
85
- window.HAML.findAndPreserve ||= ->
86
- tags = '<%= HamlCoffeeAssets::HamlCoffee.preserveTags %>'.split(',').join('|')
87
+ window.HAML.findAndPreserve ||= (text) ->
88
+ tags = '<%= configuration.preserveTags %>'.split(',').join('|')
87
89
  text.replace ///<(#{ tags })>([^]*?)<\/\1>///g, (str, tag, content) ->
88
- "<#{ tag }>#{ <%= HamlCoffeeAssets::HamlCoffee.customPreserve %>(content) }</#{ tag }>"
90
+ "<#{ tag }>#{ <%= configuration.customPreserve %>(content) }</#{ tag }>"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_coffee_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,45 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-16 00:00:00.000000000Z
12
+ date: 2012-01-05 00:00:00.000000000 +01:00
13
+ default_executable:
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
- name: rails
16
- requirement: &70224478216460 !ruby/object:Gem::Requirement
16
+ name: execjs
17
+ requirement: &70195561992060 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - ! '>='
20
21
  - !ruby/object:Gem::Version
21
- version: '3.1'
22
+ version: 1.2.9
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70224478216460
25
+ version_requirements: *70195561992060
25
26
  - !ruby/object:Gem::Dependency
26
- name: execjs
27
- requirement: &70224478215660 !ruby/object:Gem::Requirement
27
+ name: tilt
28
+ requirement: &70195561991480 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
- - - ~>
31
+ - - ! '>='
31
32
  - !ruby/object:Gem::Version
32
- version: 1.2.9
33
+ version: 1.3.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70195561991480
37
+ - !ruby/object:Gem::Dependency
38
+ name: sprockets
39
+ requirement: &70195561990980 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 2.0.3
33
45
  type: :runtime
34
46
  prerelease: false
35
- version_requirements: *70224478215660
47
+ version_requirements: *70195561990980
36
48
  - !ruby/object:Gem::Dependency
37
49
  name: bundler
38
- requirement: &70224478214980 !ruby/object:Gem::Requirement
50
+ requirement: &70195561990500 !ruby/object:Gem::Requirement
39
51
  none: false
40
52
  requirements:
41
53
  - - ! '>='
@@ -43,10 +55,21 @@ dependencies:
43
55
  version: '0'
44
56
  type: :development
45
57
  prerelease: false
46
- version_requirements: *70224478214980
58
+ version_requirements: *70195561990500
59
+ - !ruby/object:Gem::Dependency
60
+ name: railties
61
+ requirement: &70195561989920 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '3.1'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70195561989920
47
70
  - !ruby/object:Gem::Dependency
48
71
  name: rspec
49
- requirement: &70224478214240 !ruby/object:Gem::Requirement
72
+ requirement: &70195561989380 !ruby/object:Gem::Requirement
50
73
  none: false
51
74
  requirements:
52
75
  - - ~>
@@ -54,10 +77,10 @@ dependencies:
54
77
  version: 2.7.0
55
78
  type: :development
56
79
  prerelease: false
57
- version_requirements: *70224478214240
80
+ version_requirements: *70195561989380
58
81
  - !ruby/object:Gem::Dependency
59
82
  name: guard-rspec
60
- requirement: &70224478212900 !ruby/object:Gem::Requirement
83
+ requirement: &70195561988900 !ruby/object:Gem::Requirement
61
84
  none: false
62
85
  requirements:
63
86
  - - ~>
@@ -65,10 +88,10 @@ dependencies:
65
88
  version: 0.5.0
66
89
  type: :development
67
90
  prerelease: false
68
- version_requirements: *70224478212900
91
+ version_requirements: *70195561988900
69
92
  - !ruby/object:Gem::Dependency
70
93
  name: yard
71
- requirement: &70224478211260 !ruby/object:Gem::Requirement
94
+ requirement: &70195561988440 !ruby/object:Gem::Requirement
72
95
  none: false
73
96
  requirements:
74
97
  - - ~>
@@ -76,10 +99,10 @@ dependencies:
76
99
  version: 0.7.3
77
100
  type: :development
78
101
  prerelease: false
79
- version_requirements: *70224478211260
102
+ version_requirements: *70195561988440
80
103
  - !ruby/object:Gem::Dependency
81
104
  name: redcarpet
82
- requirement: &70224478209740 !ruby/object:Gem::Requirement
105
+ requirement: &70195561987960 !ruby/object:Gem::Requirement
83
106
  none: false
84
107
  requirements:
85
108
  - - ~>
@@ -87,10 +110,10 @@ dependencies:
87
110
  version: 1.17.2
88
111
  type: :development
89
112
  prerelease: false
90
- version_requirements: *70224478209740
113
+ version_requirements: *70195561987960
91
114
  - !ruby/object:Gem::Dependency
92
115
  name: pry
93
- requirement: &70224478208080 !ruby/object:Gem::Requirement
116
+ requirement: &70195561987460 !ruby/object:Gem::Requirement
94
117
  none: false
95
118
  requirements:
96
119
  - - ~>
@@ -98,10 +121,10 @@ dependencies:
98
121
  version: 0.9.6.2
99
122
  type: :development
100
123
  prerelease: false
101
- version_requirements: *70224478208080
124
+ version_requirements: *70195561987460
102
125
  - !ruby/object:Gem::Dependency
103
126
  name: rake
104
- requirement: &70224478206860 !ruby/object:Gem::Requirement
127
+ requirement: &70195561986980 !ruby/object:Gem::Requirement
105
128
  none: false
106
129
  requirements:
107
130
  - - ~>
@@ -109,7 +132,7 @@ dependencies:
109
132
  version: 0.9.2.2
110
133
  type: :development
111
134
  prerelease: false
112
- version_requirements: *70224478206860
135
+ version_requirements: *70195561986980
113
136
  description: Compile Haml CoffeeScript templates in the Rails asset pipeline.
114
137
  email:
115
138
  - michi@netzpiraten.ch
@@ -129,6 +152,7 @@ files:
129
152
  - vendor/assets/javascripts/hamlcoffee.js.coffee.erb
130
153
  - LICENSE
131
154
  - README.md
155
+ has_rdoc: true
132
156
  homepage: https://github.com/netzpirat/haml_coffee_assets
133
157
  licenses: []
134
158
  post_install_message:
@@ -149,9 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
173
  version: 1.3.6
150
174
  requirements: []
151
175
  rubyforge_project: haml_coffee_assets
152
- rubygems_version: 1.8.10
176
+ rubygems_version: 1.6.2
153
177
  signing_key:
154
178
  specification_version: 3
155
179
  summary: Haml CoffeeScript templates
156
180
  test_files: []
157
- has_rdoc: