coffee-views 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Rakefile +1 -0
- data/coffee-views.gemspec +1 -1
- data/lib/coffee_views.rb +9 -1
- data/lib/coffee_views/rails.rb +7 -5
- data/lib/coffee_views/version.rb +1 -1
- data/spec/dummy/app/controllers/events_controller.rb +2 -2
- data/spec/dummy/config/application.rb +1 -0
- data/spec/preprocess_spec.rb +2 -2
- data/spec/views/events_spec.rb +3 -3
- metadata +43 -37
data/Gemfile
CHANGED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/coffee-views.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.require_path = 'lib'
|
18
18
|
|
19
|
-
s.add_dependency "rails", ">= 3.
|
19
|
+
s.add_dependency "rails", ">= 3.2.0"
|
20
20
|
s.add_dependency "coffee-rails"
|
21
21
|
s.add_development_dependency "sqlite3"
|
22
22
|
s.add_development_dependency "rspec-rails", "~> 2.6"
|
data/lib/coffee_views.rb
CHANGED
@@ -1,3 +1,11 @@
|
|
1
1
|
require 'coffee_views/rails'
|
2
2
|
require 'coffee_views/slim'
|
3
|
-
require 'coffee_views/version'
|
3
|
+
require 'coffee_views/version'
|
4
|
+
|
5
|
+
module CoffeeViews
|
6
|
+
# http://jfire.io/blog/2012/04/30/how-to-securely-bootstrap-json-in-a-rails-view/
|
7
|
+
def self.j s
|
8
|
+
result = s.to_s.gsub('/', '\/')
|
9
|
+
s.html_safe? ? result.html_safe : result
|
10
|
+
end
|
11
|
+
end
|
data/lib/coffee_views/rails.rb
CHANGED
@@ -5,18 +5,19 @@ require 'coffee-script'
|
|
5
5
|
module CoffeeViews
|
6
6
|
module Rails
|
7
7
|
class TemplateHandler
|
8
|
+
|
8
9
|
def self.erb_handler
|
9
10
|
@@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.preprocess source
|
13
|
-
return "" unless source
|
14
|
+
return "".html_safe unless source
|
14
15
|
|
15
16
|
source.gsub! /<%==(.*?)%>/, '`<%==\1%>`'
|
16
|
-
source.gsub! /<%=([^=].*?)%>/, '`<%==(\1).to_json%>`'
|
17
|
+
source.gsub! /<%=([^=].*?)%>/, '`<%==CoffeeViews.j((\1).to_json.html_safe)%>`'
|
17
18
|
source.gsub! /<%([^=].*?)%>/, '`<%\1%>`'
|
18
19
|
source.gsub! /#\{==(.*?)\}/, '#{`<%==\1%>`}'
|
19
|
-
source.gsub! /#\{=([^=].*?)\}/, '#{`<%==(\1).to_json%>`}'
|
20
|
+
source.gsub! /#\{=([^=].*?)\}/, '#{`<%==CoffeeViews.j((\1).to_json.html_safe)%>`}'
|
20
21
|
source
|
21
22
|
end
|
22
23
|
|
@@ -36,6 +37,7 @@ module CoffeeViews
|
|
36
37
|
end
|
37
38
|
|
38
39
|
ActiveSupport.on_load(:action_view) do
|
39
|
-
ActionView::Template.register_template_handler :coffee, CoffeeViews::Rails::TemplateHandler
|
40
|
+
ActionView::Template.register_template_handler :coffee, CoffeeViews::Rails::TemplateHandler
|
40
41
|
end
|
41
|
-
end
|
42
|
+
end
|
43
|
+
|
data/lib/coffee_views/version.rb
CHANGED
data/spec/preprocess_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe CoffeeViews::Rails::TemplateHandler do
|
|
21
21
|
|
22
22
|
describe "<%= code %>" do
|
23
23
|
it "should wrap with `` and call #to_json on code" do
|
24
|
-
preprocess("<%=x%>").should == "`<%==(x).to_json%>`"
|
24
|
+
preprocess("<%=x%>").should == "`<%==CoffeeViews.j((x).to_json.html_safe)%>`"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -39,7 +39,7 @@ describe CoffeeViews::Rails::TemplateHandler do
|
|
39
39
|
|
40
40
|
describe '#{= code}' do
|
41
41
|
it "should wrap with `<%== %>` and call #to_json on code" do
|
42
|
-
preprocess('alert "#{=code}"').should == 'alert "#{`<%==(code).to_json%>`}"'
|
42
|
+
preprocess('alert "#{=code}"').should == 'alert "#{`<%==CoffeeViews.j((code).to_json.html_safe)%>`}"'
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/spec/views/events_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "events/index.js" do
|
3
|
+
describe "events/index.js.coffee" do
|
4
4
|
it "interpolates strings" do
|
5
5
|
assign :first_name, "Yury"
|
6
6
|
assign :last_name, "'Korolev'"
|
@@ -17,7 +17,7 @@ JAVASCRIPT
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe "events/index.html" do
|
20
|
+
describe "events/index.html.slim" do
|
21
21
|
it "adds embeded engine for slim" do
|
22
22
|
assign :first_name, "Yury"
|
23
23
|
assign :last_name, "'Korolev'"
|
@@ -37,7 +37,7 @@ JAVASCRIPT
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe "events/show.js" do
|
40
|
+
describe "events/show.js.coffee" do
|
41
41
|
it "converts to json" do
|
42
42
|
assign :event, {name: "Birth day", date: Date.new(1983, 02, 15)}
|
43
43
|
|
metadata
CHANGED
@@ -1,144 +1,144 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee-views
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.6
|
5
4
|
prerelease:
|
5
|
+
version: 0.1.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Yury Korolev
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
version: 3.2.0
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
27
25
|
- - ! '>='
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
version: 3.
|
27
|
+
version: 3.2.0
|
28
|
+
prerelease: false
|
29
|
+
type: :runtime
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: coffee-rails
|
32
|
-
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
|
-
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
43
41
|
- - ! '>='
|
44
42
|
- !ruby/object:Gem::Version
|
45
43
|
version: '0'
|
44
|
+
prerelease: false
|
45
|
+
type: :runtime
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: sqlite3
|
48
|
-
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
-
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
57
55
|
none: false
|
58
56
|
requirements:
|
59
57
|
- - ! '>='
|
60
58
|
- !ruby/object:Gem::Version
|
61
59
|
version: '0'
|
60
|
+
prerelease: false
|
61
|
+
type: :development
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rspec-rails
|
64
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '2.6'
|
70
|
-
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
73
71
|
none: false
|
74
72
|
requirements:
|
75
73
|
- - ~>
|
76
74
|
- !ruby/object:Gem::Version
|
77
75
|
version: '2.6'
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: sass-rails
|
80
|
-
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
83
|
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
|
-
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
89
87
|
none: false
|
90
88
|
requirements:
|
91
89
|
- - ! '>='
|
92
90
|
- !ruby/object:Gem::Version
|
93
91
|
version: '0'
|
92
|
+
prerelease: false
|
93
|
+
type: :development
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: coffee-rails
|
96
|
-
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
|
-
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
105
103
|
none: false
|
106
104
|
requirements:
|
107
105
|
- - ! '>='
|
108
106
|
- !ruby/object:Gem::Version
|
109
107
|
version: '0'
|
108
|
+
prerelease: false
|
109
|
+
type: :development
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: uglifier
|
112
|
-
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
115
115
|
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
|
-
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
121
119
|
none: false
|
122
120
|
requirements:
|
123
121
|
- - ! '>='
|
124
122
|
- !ruby/object:Gem::Version
|
125
123
|
version: '0'
|
124
|
+
prerelease: false
|
125
|
+
type: :development
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: slim
|
128
|
-
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
131
131
|
- - ! '>='
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
|
-
|
135
|
-
prerelease: false
|
136
|
-
version_requirements: !ruby/object:Gem::Requirement
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
137
135
|
none: false
|
138
136
|
requirements:
|
139
137
|
- - ! '>='
|
140
138
|
- !ruby/object:Gem::Version
|
141
139
|
version: '0'
|
140
|
+
prerelease: false
|
141
|
+
type: :development
|
142
142
|
description: Allows you to create .js.coffee views
|
143
143
|
email: yury.korolev@gmail.com
|
144
144
|
executables: []
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- Gemfile
|
151
151
|
- LICENSE
|
152
152
|
- README.md
|
153
|
+
- Rakefile
|
153
154
|
- coffee-views.gemspec
|
154
155
|
- lib/coffee-views.rb
|
155
156
|
- lib/coffee_views.rb
|
@@ -207,12 +208,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
207
208
|
- - ! '>='
|
208
209
|
- !ruby/object:Gem::Version
|
209
210
|
version: '0'
|
211
|
+
hash: -4004482261167388747
|
212
|
+
segments:
|
213
|
+
- 0
|
210
214
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
215
|
none: false
|
212
216
|
requirements:
|
213
217
|
- - ! '>='
|
214
218
|
- !ruby/object:Gem::Version
|
215
219
|
version: '0'
|
220
|
+
hash: -4004482261167388747
|
221
|
+
segments:
|
222
|
+
- 0
|
216
223
|
requirements: []
|
217
224
|
rubyforge_project:
|
218
225
|
rubygems_version: 1.8.24
|
@@ -220,4 +227,3 @@ signing_key:
|
|
220
227
|
specification_version: 3
|
221
228
|
summary: CoffeeScript views in rails 3
|
222
229
|
test_files: []
|
223
|
-
has_rdoc:
|