roda-plugins 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/roda/plugins/version.rb +1 -1
- metadata +2 -3
- data/lib/roda/plugins/assets.rb +0 -178
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86697f17032dfa90d874019891226bfcf00f0b91
|
4
|
+
data.tar.gz: 47add4a2ff3573bc9c77af468e2ca3cb33c58ec3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04b19de5134fef9e061c17d0e5d21cedc9f608ccaaf2945d89bfcee1dfc20e4f3ebaee0b9e93b69d2d7a0172434bc7f4a92f34ccb8e32ee362c55f53162afdc6
|
7
|
+
data.tar.gz: a6298269a54fd913b2236b6a2c0f4097b543f92401ec852dda904726ed7875f023dfa4d055bd0a2c5b1d045b6c13fba34aab865ad03f54eaedfe6df528534921
|
data/lib/roda/plugins/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Plugins for Roda
|
14
14
|
email:
|
@@ -24,7 +24,6 @@ files:
|
|
24
24
|
- Makefile
|
25
25
|
- README.md
|
26
26
|
- lib/roda/plugins.rb
|
27
|
-
- lib/roda/plugins/assets.rb
|
28
27
|
- lib/roda/plugins/components.rb
|
29
28
|
- lib/roda/plugins/root.rb
|
30
29
|
- lib/roda/plugins/version.rb
|
data/lib/roda/plugins/assets.rb
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
require "tilt"
|
2
|
-
|
3
|
-
class Roda
|
4
|
-
module RodaPlugins
|
5
|
-
module Assets
|
6
|
-
def self.load_dependencies(app, opts={})
|
7
|
-
app.plugin :render
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.configure(app, opts={}, &block)
|
11
|
-
if app.opts[:assets]
|
12
|
-
app.opts[:assets].merge!(opts)
|
13
|
-
else
|
14
|
-
app.opts[:assets] = opts.dup
|
15
|
-
end
|
16
|
-
|
17
|
-
opts = app.opts[:assets]
|
18
|
-
opts[:css] ||= []
|
19
|
-
opts[:js] ||= []
|
20
|
-
opts[:js_folder] ||= 'js'
|
21
|
-
opts[:css_folder] ||= 'css'
|
22
|
-
opts[:path] ||= File.expand_path("assets", Dir.pwd)
|
23
|
-
opts[:route] ||= 'assets'
|
24
|
-
opts[:css_engine] ||= 'scss'
|
25
|
-
opts[:js_engine] ||= 'coffee'
|
26
|
-
opts[:headers] ||= {}
|
27
|
-
opts[:cache] = app.thread_safe_cache if opts.fetch(:cache, true)
|
28
|
-
|
29
|
-
yield opts if block
|
30
|
-
end
|
31
|
-
|
32
|
-
module ClassMethods
|
33
|
-
# Copy the assets options into the subclass, duping
|
34
|
-
# them as necessary to prevent changes in the subclass
|
35
|
-
# affecting the parent class.
|
36
|
-
def inherited(subclass)
|
37
|
-
super
|
38
|
-
opts = subclass.opts[:assets] = assets_opts.dup
|
39
|
-
opts[:cache] = thread_safe_cache if opts[:cache]
|
40
|
-
end
|
41
|
-
|
42
|
-
# Return the assets options for this class.
|
43
|
-
def assets_opts
|
44
|
-
opts[:assets]
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def asset_path file, type
|
49
|
-
file.gsub!(/\.#{type}$/, '')
|
50
|
-
assets = assets_opts[:"#{type}"]
|
51
|
-
|
52
|
-
if assets.is_a? Array
|
53
|
-
file_path = assets.select {|a| a["#{file}"]}.first
|
54
|
-
else
|
55
|
-
file = file.split('/')
|
56
|
-
sub = file.shift.to_sym
|
57
|
-
file = file.join '/'
|
58
|
-
file_path = assets[sub].select {|a| a["#{file}"]}.first
|
59
|
-
|
60
|
-
if file_path && !file_path[/^\.\//]
|
61
|
-
file_path = "#{sub}/#{file_path}"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
folder = assets_opts[:"#{type}_folder"]
|
66
|
-
|
67
|
-
if file_path
|
68
|
-
if !file_path[/^\.\//]
|
69
|
-
"#{assets_opts[:path]}/#{folder}/#{file_path}"
|
70
|
-
else
|
71
|
-
file_path
|
72
|
-
end
|
73
|
-
else
|
74
|
-
file
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
module InstanceMethods
|
80
|
-
def assets_opts
|
81
|
-
self.class.assets_opts
|
82
|
-
end
|
83
|
-
|
84
|
-
def assets type, options = {}
|
85
|
-
attrs = options.map{|k,v| "#{k}=\"#{v}\""}
|
86
|
-
tags = []
|
87
|
-
type = [type] unless type.is_a? Array
|
88
|
-
files = type.length == 1 \
|
89
|
-
? assets_opts[:"#{type[0]}"] \
|
90
|
-
: assets_opts[:"#{type[0]}"][:"#{type[1]}"]
|
91
|
-
|
92
|
-
files.each do |file|
|
93
|
-
file.gsub!(/\./, '$2E')
|
94
|
-
file = file.split('/')
|
95
|
-
file[file.length - 1] = file.last.gsub(/\$2E/, '.')
|
96
|
-
file = file.join '/'
|
97
|
-
path = assets_opts[:route] + '/' + assets_opts[:"#{type[0]}_folder"]
|
98
|
-
attr = type[0].to_s == 'js' ? 'src' : 'href'
|
99
|
-
attrs.unshift "#{attr}=\"/#{path}/#{file}\""
|
100
|
-
tags << send("#{type[0]}_assets_tag", attrs.join(' '))
|
101
|
-
end
|
102
|
-
|
103
|
-
tags.join "\n"
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
|
-
# <link rel="stylesheet" href="theme.css">
|
109
|
-
def css_assets_tag attrs
|
110
|
-
"<link rel=\"stylesheet\" #{attrs} />"
|
111
|
-
end
|
112
|
-
|
113
|
-
# <script src="scriptfile.js"></script>
|
114
|
-
def js_assets_tag attrs
|
115
|
-
"<script type=\"text/javascript\" #{attrs}></script>"
|
116
|
-
end
|
117
|
-
|
118
|
-
def render_asset *args
|
119
|
-
self.class.render_asset(*args)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
module RequestClassMethods
|
124
|
-
def assets_opts
|
125
|
-
roda_class.assets_opts
|
126
|
-
end
|
127
|
-
|
128
|
-
%w(css js).each do |type|
|
129
|
-
define_method "#{type}_assets_path" do
|
130
|
-
Regexp.new(
|
131
|
-
assets_opts[:route] + '/' + assets_opts[:"#{type}_folder"] + '/(.*)'
|
132
|
-
)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
module RequestMethods
|
138
|
-
def assets
|
139
|
-
%w(css js).each do |type|
|
140
|
-
on self.class.public_send "#{type}_assets_path" do |file|
|
141
|
-
file.gsub!(/(\$2E|%242E)/, '.')
|
142
|
-
|
143
|
-
content_type = Rack::Mime.mime_type File.extname(file)
|
144
|
-
|
145
|
-
response.headers.merge!({
|
146
|
-
"Content-Type" => content_type + '; charset=UTF-8',
|
147
|
-
}.merge(scope.assets_opts[:headers]))
|
148
|
-
|
149
|
-
engine = scope.assets_opts[:"#{type}_engine"]
|
150
|
-
|
151
|
-
if !file[/^\.\//]
|
152
|
-
path = scope.assets_opts[:route] + '/' + scope.assets_opts[:"#{type}_folder"] + "/#{file}"
|
153
|
-
else
|
154
|
-
path = file
|
155
|
-
end
|
156
|
-
|
157
|
-
if File.exists? "#{path}.#{engine}"
|
158
|
-
scope.render path: "#{path}.#{engine}"
|
159
|
-
elsif File.exists? "#{path}.#{type}"
|
160
|
-
File.read "#{path}.#{type}"
|
161
|
-
elsif File.exists?(path) && path[/\.#{type}$/]
|
162
|
-
File.read path
|
163
|
-
elsif File.exists? path
|
164
|
-
begin
|
165
|
-
scope.render path: path
|
166
|
-
rescue
|
167
|
-
File.read path
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
register_plugin(:assets, Assets)
|
177
|
-
end
|
178
|
-
end
|