sprockets_inline 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +1 -0
- data/lib/sprockets_inline.rb +7 -0
- data/lib/sprockets_inline/processor.rb +60 -0
- data/lib/sprockets_inline/version.rb +3 -0
- metadata +121 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Euge Gimelberg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/euge/sprockets_inline.png)](http://travis-ci.org/euge/sprockets_inline)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module SprocketsInline
|
2
|
+
|
3
|
+
class Processor < Tilt::Template
|
4
|
+
|
5
|
+
# regexp for detecting a JS statement
|
6
|
+
# Examples:
|
7
|
+
# //= inline "bob"
|
8
|
+
# // =inline "bob"
|
9
|
+
# // = inline "bob"
|
10
|
+
# and all sorts of other wierd combos
|
11
|
+
JS_DIRECTIVE_PATTERN = /
|
12
|
+
^\s* \/\/ \s* = \s* (\w+.*?) $
|
13
|
+
/x
|
14
|
+
|
15
|
+
# regexp for extracting the indent
|
16
|
+
INDENT = /^(\s*)/
|
17
|
+
|
18
|
+
def prepare
|
19
|
+
end
|
20
|
+
|
21
|
+
def evaluate(context, locals, &block)
|
22
|
+
@context = context
|
23
|
+
@result = ""
|
24
|
+
|
25
|
+
data.lines.each do |line|
|
26
|
+
if directive = get_directive(line)
|
27
|
+
process_directive(directive)
|
28
|
+
else
|
29
|
+
@result << line
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
@result
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_directive(line)
|
37
|
+
if directive = line[JS_DIRECTIVE_PATTERN, 1]
|
38
|
+
name, *args = Shellwords.shellwords(directive)
|
39
|
+
if respond_to?("process_#{name}_directive", true)
|
40
|
+
return { :name => name, :args => args, :line => line }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def process_directive(directive)
|
48
|
+
send("process_#{directive[:name]}_directive", directive)
|
49
|
+
end
|
50
|
+
|
51
|
+
def process_inline_directive(directive)
|
52
|
+
content = @context.evaluate(directive[:args][0])
|
53
|
+
|
54
|
+
# preserve indenting of the directive
|
55
|
+
indent = directive[:line][INDENT, 1]
|
56
|
+
@result << content.lines.map { |c| indent + c }.join
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets_inline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Euge Gimelberg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.8.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sprockets
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: SprocketsInline provides a Sprockets directive processor for inlining
|
79
|
+
JavaScripts
|
80
|
+
email:
|
81
|
+
- eugegim@gmail.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- README.md
|
87
|
+
- LICENSE
|
88
|
+
- lib/sprockets_inline/processor.rb
|
89
|
+
- lib/sprockets_inline/version.rb
|
90
|
+
- lib/sprockets_inline.rb
|
91
|
+
homepage: https://github.com/euge/sprockets_inline
|
92
|
+
licenses: []
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: -3608294978998598851
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
hash: -3608294978998598851
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project: sprockets_inline
|
117
|
+
rubygems_version: 1.8.24
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Sprockets processor to inline JavaScripts
|
121
|
+
test_files: []
|