haml_coffee_assets 0.9.1 → 0.9.2

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.
@@ -1,176 +0,0 @@
1
- # coding: UTF-8
2
-
3
- module HamlCoffeeAssets
4
-
5
- # Handles compilation of Haml CoffeeScript templates to pure JavaScript.
6
- #
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.customSurround = 'window.HAML.surround'
25
- self.customSucceed = 'window.HAML.succeed'
26
- self.customPrecede = 'window.HAML.precede'
27
- self.preserveTags = 'textarea,pre'
28
- self.selfCloseTags = 'meta,img,link,br,hr,input,area,param,col,base'
29
- self.context = ''
30
- end
31
-
32
- # Template namespace
33
- #
34
- attr_accessor :namespace
35
-
36
- # Template format, either html5, html4 or xhtml
37
- #
38
- attr_accessor :format
39
-
40
- # Uglify HTML output by skip indention
41
- #
42
- attr_accessor :uglify
43
-
44
- # Ignore path when generate the JST
45
- #
46
- attr_accessor :basename
47
-
48
- # Escape template code output
49
- #
50
- attr_accessor :escapeHtml
51
-
52
- # Escape template code output for attributes
53
- #
54
- attr_accessor :escapeAttributes
55
-
56
- # Clean inline CoffeeScript values
57
- #
58
- attr_accessor :cleanValue
59
-
60
- # Custom global HTML escaping function
61
- #
62
- attr_accessor :customHtmlEscape
63
-
64
- # Custom global code clean value function
65
- #
66
- attr_accessor :customCleanValue
67
-
68
- # Custom global surround function
69
- #
70
- attr_accessor :customSurround
71
-
72
- # Custom global succeed function
73
- #
74
- attr_accessor :customSucceed
75
-
76
- # Custom global precede function
77
- #
78
- attr_accessor :customPrecede
79
-
80
- # Custom preserve function
81
- #
82
- attr_accessor :customPreserve
83
-
84
- # Custom find and preserve function
85
- #
86
- attr_accessor :customFindAndPreserve
87
-
88
- # List of tags to preserve
89
- #
90
- attr_accessor :preserveTags
91
-
92
- # List of self closing tags
93
- #
94
- attr_accessor :selfCloseTags
95
-
96
- # Custom global context to merge
97
- #
98
- attr_accessor :context
99
-
100
- end
101
-
102
- class << self
103
-
104
- attr_accessor :configuration
105
-
106
- # Configure HamlCoffee
107
- #
108
- def configure
109
- self.configuration ||= Configuration.new
110
- yield self.configuration
111
- end
112
-
113
- # Compile the Haml CoffeeScript template.
114
- #
115
- # @param [String] name the template name
116
- # @param [String] source the template source code
117
- # @param [Boolean] jst if a JST template should be generated
118
- # @return [String] the compiled template in JavaScript
119
- #
120
- def compile(name, source, jst = true)
121
- self.configuration ||= Configuration.new
122
- runtime.call('HamlCoffeeAssets.compile', name, source, jst,
123
- configuration.namespace, configuration.format, configuration.uglify, configuration.basename,
124
- configuration.escapeHtml, configuration.escapeAttributes, configuration.cleanValue,
125
- configuration.customHtmlEscape, configuration.customCleanValue,
126
- configuration.customPreserve, configuration.customFindAndPreserve,
127
- configuration.customSurround, configuration.customSucceed, configuration.customPrecede,
128
- configuration.preserveTags, configuration.selfCloseTags,
129
- configuration.context)
130
- end
131
-
132
- private
133
-
134
- # Get the context to compile Haml CoffeeScript templates.
135
- #
136
- # @return [Runtime] the JS runtime
137
- #
138
- def runtime
139
- @runtime ||= ExecJS.compile(source)
140
- end
141
-
142
- # Get the combined source of haml-coffee and CoffeeScript.
143
- #
144
- # @return [String] the source code
145
- #
146
- def source
147
- coffeescript + ';' + haml_coffee + ';' + haml_coffee_assets
148
- end
149
-
150
- # Get the Haml CoffeeScript Assets source code.
151
- #
152
- # @return [String] the source
153
- #
154
- def haml_coffee_assets
155
- Pathname.new(__FILE__).dirname.join('haml_coffee_assets.js').read
156
- end
157
-
158
- # Get the Haml CoffeeScript source code.
159
- #
160
- # @return [String] the source
161
- #
162
- def haml_coffee
163
- Pathname.new(__FILE__).dirname.join('..', 'js', 'haml-coffee.js').read
164
- end
165
-
166
- # Get the CoffeeScript source code.
167
- #
168
- # @return [String] the source
169
- #
170
- def coffeescript
171
- Pathname.new(__FILE__).dirname.join('..', 'js', 'coffee-script.js').read
172
- end
173
-
174
- end
175
- end
176
- end
@@ -1,52 +0,0 @@
1
- # coding: UTF-8
2
-
3
- require 'tilt'
4
-
5
- module HamlCoffeeAssets
6
-
7
- # Haml CoffeeScript template implementation for Tilt.
8
- #
9
- class HamlCoffeeTemplate < Tilt::Template
10
-
11
- class << self
12
- # A proc that is called to modify the template name used as the
13
- # JST key. The proc is passed the name as an argument and should
14
- # return the modified name (or unmodified) name.
15
- attr_accessor :name_filter
16
- end
17
-
18
- # By default, remove any leading templates/ in the name
19
- self.name_filter = lambda { |n| n.sub /^templates\//, '' }
20
- self.default_mime_type = 'application/javascript'
21
-
22
- # Test if the compiler is initialized.
23
- #
24
- # @return [Boolean] the initialization status
25
- #
26
- def self.engine_initialized?
27
- defined? HamlCoffee
28
- end
29
-
30
- # Initialize the template engine.
31
- #
32
- def initialize_engine
33
- require_template_library 'haml_coffee'
34
- end
35
-
36
- # Prepare the template
37
- #
38
- def prepare
39
- end
40
-
41
- # Compile the template.
42
- #
43
- def evaluate(scope, locals = { }, &block)
44
- jst = scope.pathname.to_s =~ /\.jst\.hamlc(?:\.|$)/ ? false : true
45
- name = scope.logical_path
46
- name = self.class.name_filter.call(name) if self.class.name_filter && jst
47
- @output ||= HamlCoffee.compile(name, data, jst)
48
- end
49
-
50
- end
51
- end
52
-
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :haml-coffee-rails do
3
- # # Task goes here
4
- # end