coffee-views 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
+ require File.dirname(__FILE__) + '/lib/coffee_views/version'
1
2
  require 'date'
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = 'coffee-views'
5
- s.version = '0.1.3'
6
+ s.version = CoffeeViews::VERSION
6
7
  s.date = Date.today.to_s
7
8
  s.authors = ['Yury Korolev']
8
9
  s.email = 'yury.korolev@gmail.com'
@@ -22,5 +23,6 @@ Gem::Specification.new do |s|
22
23
  s.add_development_dependency "sass-rails"
23
24
  s.add_development_dependency "coffee-rails"
24
25
  s.add_development_dependency "uglifier"
26
+ s.add_development_dependency "slim"
25
27
 
26
28
  end
@@ -1,56 +1,3 @@
1
- require 'action_view'
2
- require 'coffee-rails'
3
- require 'coffee-script'
4
-
5
- module CoffeeViews
6
- module Rails
7
- class TemplateHandler
8
- def self.erb_handler
9
- @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
10
- end
11
-
12
- def self.preprocess source
13
- return "" unless source
14
-
15
- source.gsub! /<%==(.*?)%>/, '`<%==\1%>`'
16
- source.gsub! /<%=([^=].*?)%>/, '`<%==(\1).to_json%>`'
17
- source.gsub! /<%([^=].*?)%>/, '`<%\1%>`'
18
- source.gsub! /#\{==(.*?)\}/, '#{`<%==\1%>`}'
19
- source.gsub! /#\{=([^=].*?)\}/, '#{`<%==(\1).to_json%>`}'
20
- source
21
- end
22
-
23
- def self.compile_coffee(source)
24
- source = preprocess(source)
25
- ::CoffeeScript.compile(source)
26
- end
27
-
28
- def self.call(template)
29
- source = compile_coffee(template.source)
30
- # TODO: find how to set source back to template without instance_variable_set
31
- template.instance_variable_set :@source, source
32
-
33
- erb_handler.call(template)
34
- end
35
- end
36
- end
37
-
38
- ActiveSupport.on_load(:action_view) do
39
- ActionView::Template.register_template_handler :coffee, CoffeeViews::Rails::TemplateHandler
40
- end
41
-
42
- if defined?(Slim)
43
- class CoffeeViewEngine < Slim::EmbeddedEngine::ERBEngine
44
- def on_slim_embedded(engine, body)
45
- source = CoffeeViews::Rails::TemplateHandler.compile_coffee(collect_text(body))
46
- source = Temple::ERB::Parser.new.call(source)
47
- end
48
- end
49
-
50
- Slim::EmbeddedEngine.register :coffeeview,
51
- Slim::EmbeddedEngine::TagEngine,
52
- :tag => :script,
53
- :attributes => { :type => 'text/javascript' },
54
- :engine => CoffeeViewEngine
55
- end
56
- end
1
+ require 'coffee_views/rails'
2
+ require 'coffee_views/slim'
3
+ require 'coffee_views/version'
@@ -0,0 +1,41 @@
1
+ require 'action_view'
2
+ require 'coffee-rails'
3
+ require 'coffee-script'
4
+
5
+ module CoffeeViews
6
+ module Rails
7
+ class TemplateHandler
8
+ def self.erb_handler
9
+ @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
10
+ end
11
+
12
+ def self.preprocess source
13
+ return "" unless source
14
+
15
+ source.gsub! /<%==(.*?)%>/, '`<%==\1%>`'
16
+ source.gsub! /<%=([^=].*?)%>/, '`<%==(\1).to_json%>`'
17
+ source.gsub! /<%([^=].*?)%>/, '`<%\1%>`'
18
+ source.gsub! /#\{==(.*?)\}/, '#{`<%==\1%>`}'
19
+ source.gsub! /#\{=([^=].*?)\}/, '#{`<%==(\1).to_json%>`}'
20
+ source
21
+ end
22
+
23
+ def self.compile_coffee(source)
24
+ source = preprocess(source)
25
+ ::CoffeeScript.compile(source)
26
+ end
27
+
28
+ def self.call(template)
29
+ source = compile_coffee(template.source)
30
+ # TODO: find how to set source back to template without instance_variable_set
31
+ template.instance_variable_set :@source, source
32
+
33
+ erb_handler.call(template)
34
+ end
35
+ end
36
+ end
37
+
38
+ ActiveSupport.on_load(:action_view) do
39
+ ActionView::Template.register_template_handler :coffee, CoffeeViews::Rails::TemplateHandler
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ require 'action_view'
2
+ ActiveSupport.on_load(:action_view) do
3
+ if Object.const_defined?(:Slim)
4
+
5
+ module CoffeeViews
6
+ class CoffeeViewEngine < Slim::EmbeddedEngine::ERBEngine
7
+ def on_slim_embedded(engine, body)
8
+ source = CoffeeViews::Rails::TemplateHandler.compile_coffee(Slim::CollectText.new.call(body))
9
+ source = Temple::ERB::Parser.new.call(source)
10
+ end
11
+ end
12
+
13
+ Slim::EmbeddedEngine.register :coffeeview,
14
+ ::Slim::EmbeddedEngine::TagEngine,
15
+ :tag => :script,
16
+ :attributes => { :type => 'text/javascript' },
17
+ :engine => CoffeeViewEngine
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module CoffeeViews
2
+ VERSION = "0.1.4"
3
+ end
@@ -1,3 +1,5 @@
1
+ require 'slim'
2
+
1
3
  class EventsController < ApplicationController
2
4
  def index
3
5
 
@@ -0,0 +1,2 @@
1
+ coffeeview:
2
+ alert "hello, #{= @first_name} #{== @last_name}"
@@ -3,6 +3,7 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require
6
+ require 'slim'
6
7
 
7
8
  module Dummy
8
9
  class Application < Rails::Application
@@ -15,6 +15,24 @@ JAVASCRIPT
15
15
  end
16
16
  end
17
17
 
18
+ describe "events/index.html.slim" do
19
+ it "adds embeded engine for slim" do
20
+ assign :first_name, "Yury"
21
+ assign :last_name, "'Korolev'"
22
+
23
+ render
24
+
25
+ expected = <<-JAVASCRIPT
26
+ <script type="text/javascript">(function() {
27
+ alert("hello, " + "Yury" + " " + 'Korolev');
28
+ }).call(this);
29
+ </script>
30
+ JAVASCRIPT
31
+
32
+ rendered.should == expected.strip
33
+ end
34
+ end
35
+
18
36
  describe "events/show.js.coffee" do
19
37
  it "converts to json" do
20
38
  assign :event, {name: "Birth day", date: Date.new(1983, 02, 15)}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffee-views
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70220576761560 !ruby/object:Gem::Requirement
16
+ requirement: &70162754300580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70220576761560
24
+ version_requirements: *70162754300580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: coffee-rails
27
- requirement: &70220576761160 !ruby/object:Gem::Requirement
27
+ requirement: &70162754300160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70220576761160
35
+ version_requirements: *70162754300160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70220576760560 !ruby/object:Gem::Requirement
38
+ requirement: &70162754299700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70220576760560
46
+ version_requirements: *70162754299700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-rails
49
- requirement: &70220576759840 !ruby/object:Gem::Requirement
49
+ requirement: &70162754299140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.6'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70220576759840
57
+ version_requirements: *70162754299140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sass-rails
60
- requirement: &70220576759220 !ruby/object:Gem::Requirement
60
+ requirement: &70162754378700 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70220576759220
68
+ version_requirements: *70162754378700
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: coffee-rails
71
- requirement: &70220576758500 !ruby/object:Gem::Requirement
71
+ requirement: &70162754378060 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70220576758500
79
+ version_requirements: *70162754378060
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: uglifier
82
- requirement: &70220576757880 !ruby/object:Gem::Requirement
82
+ requirement: &70162754377640 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,18 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70220576757880
90
+ version_requirements: *70162754377640
91
+ - !ruby/object:Gem::Dependency
92
+ name: slim
93
+ requirement: &70162754377140 !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: *70162754377140
91
102
  description: Allows you to create .js.coffee views
92
103
  email: yury.korolev@gmail.com
93
104
  executables: []
@@ -102,6 +113,9 @@ files:
102
113
  - coffee-views.gemspec
103
114
  - lib/coffee-views.rb
104
115
  - lib/coffee_views.rb
116
+ - lib/coffee_views/rails.rb
117
+ - lib/coffee_views/slim.rb
118
+ - lib/coffee_views/version.rb
105
119
  - spec/dummy/Rakefile
106
120
  - spec/dummy/app/assets/javascripts/application.js
107
121
  - spec/dummy/app/assets/stylesheets/application.css
@@ -110,6 +124,7 @@ files:
110
124
  - spec/dummy/app/helpers/application_helper.rb
111
125
  - spec/dummy/app/mailers/.gitkeep
112
126
  - spec/dummy/app/models/.gitkeep
127
+ - spec/dummy/app/views/events/index.html.slim
113
128
  - spec/dummy/app/views/events/index.js.coffee
114
129
  - spec/dummy/app/views/events/show.js.coffee
115
130
  - spec/dummy/app/views/layouts/application.html.erb