coffee-views 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'coffee-views'
5
- s.version = '0.1.2'
5
+ s.version = '0.1.3'
6
6
  s.date = Date.today.to_s
7
7
  s.authors = ['Yury Korolev']
8
8
  s.email = 'yury.korolev@gmail.com'
@@ -1,15 +1,17 @@
1
1
  require 'action_view'
2
+ require 'coffee-rails'
2
3
  require 'coffee-script'
3
4
 
4
5
  module CoffeeViews
5
- module Handlers
6
- module CoffeeScript
6
+ module Rails
7
+ class TemplateHandler
7
8
  def self.erb_handler
8
9
  @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
9
10
  end
10
11
 
11
12
  def self.preprocess source
12
- source ||= ""
13
+ return "" unless source
14
+
13
15
  source.gsub! /<%==(.*?)%>/, '`<%==\1%>`'
14
16
  source.gsub! /<%=([^=].*?)%>/, '`<%==(\1).to_json%>`'
15
17
  source.gsub! /<%([^=].*?)%>/, '`<%\1%>`'
@@ -19,12 +21,12 @@ module CoffeeViews
19
21
  end
20
22
 
21
23
  def self.compile_coffee(source)
22
- source = self.preprocess(source)
24
+ source = preprocess(source)
23
25
  ::CoffeeScript.compile(source)
24
26
  end
25
27
 
26
28
  def self.call(template)
27
- source = self.compile_coffee(template.source)
29
+ source = compile_coffee(template.source)
28
30
  # TODO: find how to set source back to template without instance_variable_set
29
31
  template.instance_variable_set :@source, source
30
32
 
@@ -33,15 +35,22 @@ module CoffeeViews
33
35
  end
34
36
  end
35
37
 
36
- ActionView::Template.register_template_handler :coffee, CoffeeViews::Handlers::CoffeeScript
38
+ ActiveSupport.on_load(:action_view) do
39
+ ActionView::Template.register_template_handler :coffee, CoffeeViews::Rails::TemplateHandler
40
+ end
37
41
 
38
42
  if defined?(Slim)
39
43
  class CoffeeViewEngine < Slim::EmbeddedEngine::ERBEngine
40
44
  def on_slim_embedded(engine, body)
41
- source = CoffeeViews::Handlers::CoffeeScript.compile_coffee(collect_text(body))
45
+ source = CoffeeViews::Rails::TemplateHandler.compile_coffee(collect_text(body))
42
46
  source = Temple::ERB::Parser.new.call(source)
43
47
  end
44
48
  end
45
- Slim::EmbeddedEngine.register :coffeeview, Slim::EmbeddedEngine::TagEngine, :tag => :script, :attributes => { :type => 'text/javascript' }, :engine => CoffeeViewEngine
49
+
50
+ Slim::EmbeddedEngine.register :coffeeview,
51
+ Slim::EmbeddedEngine::TagEngine,
52
+ :tag => :script,
53
+ :attributes => { :type => 'text/javascript' },
54
+ :engine => CoffeeViewEngine
46
55
  end
47
56
  end
@@ -3,7 +3,6 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require
6
- require "bla"
7
6
 
8
7
  module Dummy
9
8
  class Application < Rails::Application
@@ -1,9 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe CoffeeViews::Handlers::CoffeeScript do
3
+ describe CoffeeViews::Rails::TemplateHandler do
4
+
5
+ let(:handler) { subject.class }
4
6
 
5
7
  def preprocess source
6
- subject.preprocess(source)
8
+ handler.preprocess(source)
7
9
  end
8
10
 
9
11
  describe "Without substitutions" do
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.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-03 00:00:00.000000000 Z
12
+ date: 2011-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70251446553800 !ruby/object:Gem::Requirement
16
+ requirement: &70220576761560 !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: *70251446553800
24
+ version_requirements: *70220576761560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: coffee-rails
27
- requirement: &70251446551400 !ruby/object:Gem::Requirement
27
+ requirement: &70220576761160 !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: *70251446551400
35
+ version_requirements: *70220576761160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70251446549520 !ruby/object:Gem::Requirement
38
+ requirement: &70220576760560 !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: *70251446549520
46
+ version_requirements: *70220576760560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-rails
49
- requirement: &70251446547000 !ruby/object:Gem::Requirement
49
+ requirement: &70220576759840 !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: *70251446547000
57
+ version_requirements: *70220576759840
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sass-rails
60
- requirement: &70251450674600 !ruby/object:Gem::Requirement
60
+ requirement: &70220576759220 !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: *70251450674600
68
+ version_requirements: *70220576759220
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: coffee-rails
71
- requirement: &70251450673020 !ruby/object:Gem::Requirement
71
+ requirement: &70220576758500 !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: *70251450673020
79
+ version_requirements: *70220576758500
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: uglifier
82
- requirement: &70251450672260 !ruby/object:Gem::Requirement
82
+ requirement: &70220576757880 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70251450672260
90
+ version_requirements: *70220576757880
91
91
  description: Allows you to create .js.coffee views
92
92
  email: yury.korolev@gmail.com
93
93
  executables: []