ro 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +8 -8
  2. data/lib/ro.rb +1 -1
  3. data/lib/ro/node.rb +54 -31
  4. data/notes/ara.txt +2 -0
  5. data/ro.gemspec +1 -1
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTIyYzhhNmViMzU2MjVlZmVlYmI4OWIyZGMwM2Y1ZWE5N2ZiNDY3MA==
4
+ MWE0ZWVlNDk0Nzc1YzRlMTcyNGNkYmViMWI1YmExMzYzYTE0YzU0NA==
5
5
  data.tar.gz: !binary |-
6
- NGExYmE1YWE1M2FjNzJlMWViZmZlMDcxNTYwY2Y0MDk1ZTNjZmIyYw==
6
+ YWU4YjhhY2Y1ZWYyY2EwOTJjODQwOTlmNTZhZDkyZDcwZjhmZmQ0Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjIyNWExYTRjYzNmYmYxYzYyOGQxMWJmNDAxZjg4YjM5OWE3NDMyMmQyNzc1
10
- MmQ5MjQzMGY2OTYwYzRkNDhlOTM1MjM2MjE5YWM4MmIwZDAzZjdlMGEzNDZi
11
- YTEwMzEzMjJlYTI5YmRlY2NiZDMyYjg3OGJhZTljZWQxY2ZkZWI=
9
+ NDk4YzE1Yzc1NDM0MTJjY2QyOWM5NTU4NmM4OThlZjJmOGE1NDc3NTZkMmUz
10
+ Yjk1YmQyZTNhMTE4YTRjNjE4ZjQ1OTBiZTllYjYwZTY5ZDVhNTNhMzZhOTI1
11
+ YzFiOTlmNDQ3ZDVmN2I5ODNlNzEwYjU2OGE2NDZmNTdmZDQyZWU=
12
12
  data.tar.gz: !binary |-
13
- NzJjYzc0MmI1NWVlZDI4NjcxYmVlYmQ0NzUxZWE5YzU5OTgwNmFmNWJhOTlj
14
- YTdiODZiZDM1NWQzNjc4NjdjNGY1ZWM3ZTQ5MTY3NDE5MmQ0ZDVkNjgwNjU4
15
- MGQ1MjcxNTczMmI5YTc3OTlkNzJmYTYzY2NmMWEzYTA0M2YyN2M=
13
+ N2IxNjJlNjhhMWM3YjYyNTBhNDVhZWUyMTlkYTRmN2RmNzhmMmE2ODAwYmFm
14
+ NjRiMDQwYjg4YWFkNjIxM2YxMTM0MGVjMzI4YWNlYzFkYjUzMjM2NzY5ZmZm
15
+ NTZhMDFmZTdhZGZmNDdlYmRlMjk2ODQ0YjZlMzRmNzAxZDQ4NWQ=
data/lib/ro.rb CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  #
12
12
  module Ro
13
- Version = '1.4.2' unless defined?(Version)
13
+ Version = '1.4.3' unless defined?(Version)
14
14
 
15
15
  def version
16
16
  Ro::Version
@@ -101,7 +101,8 @@ module Ro
101
101
  def assets
102
102
  asset_paths.map do |path|
103
103
  name = path.sub(asset_dir + "/", "")
104
- url = url_for(name)
104
+ path_info = path.gsub(/^#{ Regexp.escape(Ro.root) }/, '')
105
+ url = File.join(Ro.route, path_info)
105
106
  Asset.new(name, :path => path, :url => url)
106
107
  end
107
108
  end
@@ -110,6 +111,45 @@ module Ro
110
111
  assets.map(&:url)
111
112
  end
112
113
 
114
+ def asset_for(*args, &block)
115
+ options = Map.options_for!(args)
116
+
117
+ path_info = Ro.relative_path_for(args)
118
+
119
+ path = File.join(@path.to_s, 'assets', path_info)
120
+
121
+ glob = path_info.gsub(/[_-]/, '[_-]')
122
+
123
+ globs =
124
+ [
125
+ File.join(@path.to_s, 'assets', "#{ glob }"),
126
+ File.join(@path.to_s, 'assets', "#{ glob }*"),
127
+ File.join(@path.to_s, 'assets', "**/#{ glob }")
128
+ ]
129
+
130
+ candidates = globs.map{|glob| Dir.glob(glob, ::File::FNM_CASEFOLD)}.flatten.compact.uniq
131
+
132
+ case candidates.size
133
+ when 0
134
+ raise ArgumentError.new("no asset matching #{ globs.inspect }")
135
+ else
136
+ path = candidates.first
137
+ name = path.sub(asset_dir + "/", "")
138
+ path_info = path.gsub(/^#{ Regexp.escape(Ro.root) }/, '')
139
+ url = File.join(Ro.route, path_info)
140
+ end
141
+
142
+ Asset.new(name, :path => path, :url => url)
143
+ end
144
+
145
+ def asset_for?(*args, &block)
146
+ begin
147
+ asset_for(*args, &block)
148
+ rescue
149
+ nil
150
+ end
151
+ end
152
+
113
153
  class Asset < ::String
114
154
  fattr(:path)
115
155
  fattr(:url)
@@ -141,44 +181,27 @@ module Ro
141
181
  def url_for(*args, &block)
142
182
  options = Map.options_for!(args)
143
183
 
144
- timestamp = options.delete('timestamp')
184
+ opts = Map.new
145
185
 
146
- path_info = Ro.relative_path_for(args)
186
+ opts[:timestamp] = options.delete(:timestamp)
147
187
 
148
- path = File.join(@path.to_s, 'assets', path_info)
188
+ args.push(options)
149
189
 
150
- glob = path_info.gsub(/[_-]/, '[_-]')
190
+ asset = asset_for(*args, &block)
151
191
 
152
- globs =
153
- [
154
- File.join(@path.to_s, 'assets', "#{ glob }"),
155
- File.join(@path.to_s, 'assets', "#{ glob }*"),
156
- File.join(@path.to_s, 'assets', "**/#{ glob }")
157
- ]
158
-
159
- candidates = globs.map{|glob| Dir.glob(glob, ::File::FNM_CASEFOLD)}.flatten.compact.uniq
160
-
161
- case candidates.size
162
- when 0
163
- raise ArgumentError.new("no asset matching #{ globs.inspect }")
192
+ if ts = opts.delete(:timestamp)
193
+ if ts == true
194
+ opts[:_] = File.stat(asset.path).mtime.utc.to_i
164
195
  else
165
- path = candidates.first
166
- path_info = path.gsub(/^#{ Regexp.escape(Ro.root) }/, '')
167
-
168
- if timestamp
169
- #options['_'] = Ro.md5(IO.binread(path))
170
- timestamp = File.stat(path).mtime.utc.to_i
171
- options['_'] = timestamp
172
- end
196
+ opts[:_] = ts
197
+ end
173
198
  end
174
199
 
175
- url = File.join(Ro.route, path_info)
176
-
177
- if options.empty?
178
- url
200
+ if opts.empty?
201
+ asset.url
179
202
  else
180
- query_string = Ro.query_string_for(options)
181
- "#{ url }?#{ query_string }"
203
+ query_string = Ro.query_string_for(opts)
204
+ "#{ asset.url }?#{ query_string }"
182
205
  end
183
206
  end
184
207
 
@@ -1,4 +1,6 @@
1
1
 
2
+ -
3
+ node.asset_for(:name)
2
4
 
3
5
  - nodes have fields
4
6
  - fields know from whence them came
data/ro.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "ro"
6
- spec.version = "1.4.2"
6
+ spec.version = "1.4.3"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "ro"
9
9
  spec.description = "description: ro kicks the ass"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ro
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-11 00:00:00.000000000 Z
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: map