skim 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +125 -0
- data/Rakefile +9 -0
- data/lib/skim/compiler.rb +36 -0
- data/lib/skim/engine.rb +24 -0
- data/lib/skim/rails.rb +4 -0
- data/lib/skim/sections.rb +32 -0
- data/lib/skim/template.rb +31 -0
- data/lib/skim/version.rb +3 -0
- data/lib/skim.rb +15 -0
- data/lib/temple/coffee_script/filters/attribute_merger.rb +33 -0
- data/lib/temple/coffee_script/filters/attribute_remover.rb +28 -0
- data/lib/temple/coffee_script/filters/control_flow.rb +37 -0
- data/lib/temple/coffee_script/filters/escapable.rb +34 -0
- data/lib/temple/coffee_script/filters.rb +4 -0
- data/lib/temple/coffee_script/generators.rb +53 -0
- data/lib/temple/coffee_script.rb +3 -0
- data/lib/temple/mixins/indent_dispatcher.rb +13 -0
- data/skim.gemspec +30 -0
- data/test/context.coffee +82 -0
- data/test/helper.rb +92 -0
- data/test/test_attribute_merger.rb +23 -0
- data/test/test_code_blocks.rb +88 -0
- data/test/test_code_escaping.rb +69 -0
- data/test/test_code_evaluation.rb +285 -0
- data/test/test_code_output.rb +143 -0
- data/test/test_code_structure.rb +84 -0
- data/test/test_html_escaping.rb +48 -0
- data/test/test_html_structure.rb +473 -0
- data/test/test_sections.rb +157 -0
- data/test/test_skim_template.rb +7 -0
- data/test/test_text_interpolation.rb +78 -0
- data/vendor/assets/javascripts/skim.js.coffee +35 -0
- metadata +195 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSkimLogicLess < TestSkim
|
4
|
+
def test_sections
|
5
|
+
source = %q{
|
6
|
+
p
|
7
|
+
- person
|
8
|
+
.name = name
|
9
|
+
}
|
10
|
+
|
11
|
+
hash = {
|
12
|
+
:person => [
|
13
|
+
{ :name => 'Joe', },
|
14
|
+
{ :name => 'Jack', }
|
15
|
+
]
|
16
|
+
}
|
17
|
+
|
18
|
+
assert_html '<p><div class="name">Joe</div><div class="name">Jack</div></p>', source, :context => hash, :sections => true
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_flag_section
|
22
|
+
source = %q{
|
23
|
+
p
|
24
|
+
- show_person
|
25
|
+
- person
|
26
|
+
.name = name
|
27
|
+
- show_person
|
28
|
+
| shown
|
29
|
+
}
|
30
|
+
|
31
|
+
hash = {
|
32
|
+
:show_person => true,
|
33
|
+
:person => [
|
34
|
+
{ :name => 'Joe', },
|
35
|
+
{ :name => 'Jack', }
|
36
|
+
]
|
37
|
+
}
|
38
|
+
|
39
|
+
assert_html '<p><div class="name">Joe</div><div class="name">Jack</div>shown</p>', source, :context => hash, :sections => true
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_inverted_section
|
43
|
+
source = %q{
|
44
|
+
p
|
45
|
+
- person
|
46
|
+
.name = name
|
47
|
+
-! person
|
48
|
+
| No person
|
49
|
+
- !person
|
50
|
+
| No person 2
|
51
|
+
}
|
52
|
+
|
53
|
+
hash = {}
|
54
|
+
|
55
|
+
assert_html '<p>No person No person 2</p>', source, :context => hash, :sections => true
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_output_with_content
|
59
|
+
source = %{
|
60
|
+
p = method_with_block do
|
61
|
+
block
|
62
|
+
}
|
63
|
+
assert_runtime_error 'Output statements with content are forbidden in sections mode', source, :sections => true
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_sections2
|
67
|
+
source = %q{
|
68
|
+
p
|
69
|
+
- person
|
70
|
+
.name = name
|
71
|
+
}
|
72
|
+
assert_html '<p><div class="name">Joe</div><div class="name">Jack</div></p>', source, :sections => true
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_with_array
|
76
|
+
source = %q{
|
77
|
+
ul
|
78
|
+
- people_with_locations
|
79
|
+
li = name
|
80
|
+
li = city
|
81
|
+
}
|
82
|
+
assert_html '<ul><li>Andy</li><li>Atlanta</li><li>Fred</li><li>Melbourne</li><li>Daniel</li><li>Karlsruhe</li></ul>', source, :sections => true
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_method
|
86
|
+
source = %q{
|
87
|
+
a href=output_number Link
|
88
|
+
}
|
89
|
+
assert_html '<a href="1337">Link</a>', source, :sections => true
|
90
|
+
end
|
91
|
+
|
92
|
+
SECTION = <<-SRC
|
93
|
+
- test
|
94
|
+
| Test
|
95
|
+
SRC
|
96
|
+
|
97
|
+
INVERTED_SECTION = <<-SRC
|
98
|
+
-! test
|
99
|
+
| Test
|
100
|
+
SRC
|
101
|
+
|
102
|
+
def test_undefined_section
|
103
|
+
assert_html "", SECTION, :context => {}, :sections => true
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_null_section
|
107
|
+
assert_html "", SECTION, :context => {:test => nil}, :sections => true
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_false_section
|
111
|
+
assert_html "", SECTION, :context => {:test => false}, :sections => true
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_empty_string_section
|
115
|
+
assert_html "Test", SECTION, :context => {:test => ""}, :sections => true
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_empty_array_section
|
119
|
+
assert_html "", SECTION, :context => {:test => []}, :sections => true
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_empty_object_section
|
123
|
+
assert_html "Test", SECTION, :context => {:test => {}}, :sections => true
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_undefined_inverted_section
|
127
|
+
assert_html "Test", INVERTED_SECTION, :context => {}, :sections => true
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_null_inverted_section
|
131
|
+
assert_html "Test", INVERTED_SECTION, :context => {:test => nil}, :sections => true
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_false_inverted_section
|
135
|
+
assert_html "Test", INVERTED_SECTION, :context => {:test => false}, :sections => true
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_empty_string_inverted_section
|
139
|
+
assert_html "", INVERTED_SECTION, :context => {:test => ""}, :sections => true
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_empty_array_inverted_section
|
143
|
+
assert_html "Test", INVERTED_SECTION, :context => {:test => []}, :sections => true
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_empty_object_inverted_section
|
147
|
+
assert_html "", INVERTED_SECTION, :context => {:test => {}}, :sections => true
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_doesnt_modify_context
|
151
|
+
source = %q{
|
152
|
+
- constant_object
|
153
|
+
= constant_object_size
|
154
|
+
}
|
155
|
+
assert_html '2', source, :sections => true
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSkimTextInterpolation < TestSkim
|
4
|
+
def test_interpolation_in_attribute
|
5
|
+
source = %q{
|
6
|
+
p id="a#{@id_helper()}b" = @hello_world()
|
7
|
+
}
|
8
|
+
|
9
|
+
assert_html '<p id="anoticeb">Hello World from @env</p>', source
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_nested_interpolation_in_attribute
|
13
|
+
source = %q{
|
14
|
+
p id="#{"abc#{1+1}" + "("}" = @hello_world()
|
15
|
+
}
|
16
|
+
|
17
|
+
assert_html '<p id="abc2(">Hello World from @env</p>', source
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_interpolation_in_text
|
21
|
+
source = %q{
|
22
|
+
p
|
23
|
+
| #{@hello_world()} with "quotes"
|
24
|
+
p
|
25
|
+
|
|
26
|
+
A message from the compiler: #{@hello_world()}
|
27
|
+
}
|
28
|
+
|
29
|
+
assert_html '<p>Hello World from @env with "quotes"</p><p>A message from the compiler: Hello World from @env</p>', source
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_interpolation_in_tag
|
33
|
+
source = %q{
|
34
|
+
p #{@hello_world()}
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_html '<p>Hello World from @env</p>', source
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_escape_interpolation
|
41
|
+
source = %q{
|
42
|
+
p \\#{@hello_world()}
|
43
|
+
}
|
44
|
+
|
45
|
+
assert_html '<p>#{@hello_world()}</p>', source
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_complex_interpolation
|
49
|
+
source = %q{
|
50
|
+
p Message: #{@message('hello', "user #{@output_number()}")}
|
51
|
+
}
|
52
|
+
|
53
|
+
assert_html '<p>Message: hello user 1337</p>', source
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_interpolation_with_escaping
|
57
|
+
source = %q{
|
58
|
+
| #{@evil_method()}
|
59
|
+
}
|
60
|
+
|
61
|
+
assert_html '<script>do_something_evil();</script>', source
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_interpolation_without_escaping
|
65
|
+
source = %q{
|
66
|
+
| #{{@evil_method()}}
|
67
|
+
}
|
68
|
+
|
69
|
+
assert_html '<script>do_something_evil();</script>', source
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_interpolation_with_escaping_and_delimiter
|
73
|
+
source = %q{
|
74
|
+
| #{(@evil_method())}
|
75
|
+
}
|
76
|
+
assert_html '<script>do_something_evil();</script>', source
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
this.Skim =
|
2
|
+
access: (name) ->
|
3
|
+
value = @[name]
|
4
|
+
value = value.call(@) if typeof value == "function"
|
5
|
+
return [@] if value == true
|
6
|
+
return false if value == false or !value?
|
7
|
+
return [value] if Object.prototype.toString.call(value) != "[object Array]"
|
8
|
+
return false if value.length == 0
|
9
|
+
return value
|
10
|
+
|
11
|
+
withContext: (context, block) ->
|
12
|
+
create = (o) ->
|
13
|
+
F = ->
|
14
|
+
F.prototype = o
|
15
|
+
new F
|
16
|
+
|
17
|
+
context = create(context)
|
18
|
+
|
19
|
+
context.safe ||= @safe || (value) ->
|
20
|
+
return value if value?.skimSafe
|
21
|
+
result = new String(value ? '')
|
22
|
+
result.skimSafe = true
|
23
|
+
result
|
24
|
+
|
25
|
+
context.escape ||= @escape || (string) ->
|
26
|
+
return '' unless string?
|
27
|
+
return string if string.skimSafe
|
28
|
+
@safe (''+string)
|
29
|
+
.replace(/&/g, '&')
|
30
|
+
.replace(/</g, '<')
|
31
|
+
.replace(/>/g, '>')
|
32
|
+
.replace(/"/g, '"')
|
33
|
+
.replace(/\//g,'/')
|
34
|
+
|
35
|
+
block.call(context)
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Firebaugh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: slim
|
16
|
+
requirement: &70156571721740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70156571721740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: temple
|
27
|
+
requirement: &70156571720500 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70156571720500
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: coffee-script
|
38
|
+
requirement: &70156571718440 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70156571718440
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: multi_json
|
49
|
+
requirement: &70156571717360 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70156571717360
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: sprockets
|
60
|
+
requirement: &70156571715140 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70156571715140
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: &70156571713420 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70156571713420
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: execjs
|
82
|
+
requirement: &70156571711700 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70156571711700
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: minitest-reporters
|
93
|
+
requirement: &70156571709720 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70156571709720
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: therubyracer
|
104
|
+
requirement: &70156571709000 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *70156571709000
|
113
|
+
description: Fat-free client-side templates with Slim and CoffeeScript
|
114
|
+
email:
|
115
|
+
- john.firebaugh@gmail.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- .gitignore
|
121
|
+
- .travis.yml
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/skim.rb
|
127
|
+
- lib/skim/compiler.rb
|
128
|
+
- lib/skim/engine.rb
|
129
|
+
- lib/skim/rails.rb
|
130
|
+
- lib/skim/sections.rb
|
131
|
+
- lib/skim/template.rb
|
132
|
+
- lib/skim/version.rb
|
133
|
+
- lib/temple/coffee_script.rb
|
134
|
+
- lib/temple/coffee_script/filters.rb
|
135
|
+
- lib/temple/coffee_script/filters/attribute_merger.rb
|
136
|
+
- lib/temple/coffee_script/filters/attribute_remover.rb
|
137
|
+
- lib/temple/coffee_script/filters/control_flow.rb
|
138
|
+
- lib/temple/coffee_script/filters/escapable.rb
|
139
|
+
- lib/temple/coffee_script/generators.rb
|
140
|
+
- lib/temple/mixins/indent_dispatcher.rb
|
141
|
+
- skim.gemspec
|
142
|
+
- test/context.coffee
|
143
|
+
- test/helper.rb
|
144
|
+
- test/test_attribute_merger.rb
|
145
|
+
- test/test_code_blocks.rb
|
146
|
+
- test/test_code_escaping.rb
|
147
|
+
- test/test_code_evaluation.rb
|
148
|
+
- test/test_code_output.rb
|
149
|
+
- test/test_code_structure.rb
|
150
|
+
- test/test_html_escaping.rb
|
151
|
+
- test/test_html_structure.rb
|
152
|
+
- test/test_sections.rb
|
153
|
+
- test/test_skim_template.rb
|
154
|
+
- test/test_text_interpolation.rb
|
155
|
+
- vendor/assets/javascripts/skim.js.coffee
|
156
|
+
homepage: ''
|
157
|
+
licenses: []
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ! '>='
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 1.8.17
|
177
|
+
signing_key:
|
178
|
+
specification_version: 3
|
179
|
+
summary: Take the fat out of your client-side templates with Skim. Skim is the Slim
|
180
|
+
templating engine with embedded CoffeeScript. It compiles to JavaScript templates
|
181
|
+
(.jst), which can then be served by Rails or any other Sprockets-based asset pipeline.
|
182
|
+
test_files:
|
183
|
+
- test/context.coffee
|
184
|
+
- test/helper.rb
|
185
|
+
- test/test_attribute_merger.rb
|
186
|
+
- test/test_code_blocks.rb
|
187
|
+
- test/test_code_escaping.rb
|
188
|
+
- test/test_code_evaluation.rb
|
189
|
+
- test/test_code_output.rb
|
190
|
+
- test/test_code_structure.rb
|
191
|
+
- test/test_html_escaping.rb
|
192
|
+
- test/test_html_structure.rb
|
193
|
+
- test/test_sections.rb
|
194
|
+
- test/test_skim_template.rb
|
195
|
+
- test/test_text_interpolation.rb
|