coffee-views 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.swp
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Yury Korolev
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ CoffeeViews
2
+ =================
3
+
4
+ Installation
5
+ ------------
6
+
7
+ gem "coffee-views"
8
+
9
+ Dependencies
10
+ ------------
11
+
12
+ This library depends on the `coffee-script` gem
13
+
14
+ Usage
15
+ -----
16
+
17
+ # in create.js.coffee
18
+ $("#item").html <%= render "user/card" %>
@@ -0,0 +1,23 @@
1
+ require 'date'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'coffee-views'
5
+ s.version = '0.1.0'
6
+ s.date = Date.today.to_s
7
+ s.authors = ['Yury Korolev']
8
+ s.email = 'yury.korolev@gmail.com'
9
+ s.homepage = "http://github.com/yury/coffee-views"
10
+ s.summary = "CoffeeScript views in rails 3"
11
+ s.description = "Allows you to create .js.coffee views"
12
+ s.extra_rdoc_files = %w(README.md)
13
+ s.rdoc_options = %w(--charset=UTF-8)
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.require_path = 'lib'
17
+
18
+ s.add_runtime_dependency('coffee-script')
19
+ s.add_runtime_dependency('actionpack')
20
+
21
+ s.add_development_dependency("rspec", ["~> 2.6"])
22
+
23
+ end
@@ -0,0 +1 @@
1
+ require 'coffee_views'
@@ -0,0 +1,32 @@
1
+ require 'action_view'
2
+ require 'coffee-script'
3
+
4
+ module CoffeeViews
5
+ module Handlers
6
+ module CoffeeScript
7
+ def self.erb_handler
8
+ @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
9
+ end
10
+
11
+ def self.prepare source
12
+ source.gsub!(/<%==(.*?)%>/, '`<%==\1%>`')
13
+ source.gsub!(/<%=([^=].*?)%>/, '`<%==(\1).to_json%>`')
14
+ source.gsub!(/<%([^=].*?)%>/, '`<%\1%>`')
15
+ source.gsub!(/#\{==(.*?)\}/, '#{`<%== \1 %>`}')
16
+ source.gsub!(/#\{=([^=].*?)\}/, '#{`<%=(\1).to_json%>`}')
17
+ source
18
+ end
19
+
20
+ def self.call(template)
21
+ source = self.prepare(template.source)
22
+ source = ::CoffeeScript.compile(source)
23
+ # TODO: find how to set source back to template without instance_variable_set
24
+ template.instance_variable_set :@source, source
25
+
26
+ erb_handler.call(template)
27
+ end
28
+ end
29
+ end
30
+
31
+ ActionView::Template.register_template_handler :coffee, CoffeeViews::Handlers::CoffeeScript
32
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coffee-views
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yury Korolev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-07-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: coffee-script
16
+ requirement: &2157017340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2157017340
25
+ - !ruby/object:Gem::Dependency
26
+ name: actionpack
27
+ requirement: &2156974080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156974080
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &2156973440 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.6'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2156973440
47
+ description: Allows you to create .js.coffee views
48
+ email: yury.korolev@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - README.md
53
+ files:
54
+ - .gitignore
55
+ - LICENSE
56
+ - README.md
57
+ - coffee-views.gemspec
58
+ - lib/coffee-views.rb
59
+ - lib/coffee_views.rb
60
+ homepage: http://github.com/yury/coffee-views
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.5
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: CoffeeScript views in rails 3
85
+ test_files: []