ro 1.4.6 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/Gemfile +2 -0
- data/Gemfile.lock +64 -0
- data/LICENSE +1 -0
- data/README.md +276 -105
- data/README.md.erb +159 -0
- data/Rakefile +129 -78
- data/bin/ro +241 -68
- data/lib/ro/_lib.rb +107 -0
- data/lib/ro/asset.rb +55 -0
- data/lib/ro/collection/list.rb +23 -0
- data/lib/ro/collection.rb +211 -0
- data/lib/ro/config.rb +72 -0
- data/lib/ro/error.rb +11 -0
- data/lib/ro/html.rb +23 -0
- data/lib/ro/html_safe.rb +143 -0
- data/lib/ro/klass.rb +25 -0
- data/lib/ro/methods.rb +295 -0
- data/lib/ro/model.rb +83 -114
- data/lib/ro/node.rb +209 -349
- data/lib/ro/pagination.rb +7 -4
- data/lib/ro/path.rb +229 -0
- data/lib/ro/root.rb +52 -31
- data/lib/ro/script/builder.rb +221 -0
- data/lib/ro/script/console.rb +47 -0
- data/lib/ro/script/server.rb +76 -0
- data/lib/ro/script.rb +189 -0
- data/lib/ro/slug.rb +19 -18
- data/lib/ro/template/rouge_formatter.rb +42 -0
- data/lib/ro/template.rb +145 -51
- data/lib/ro/text.rb +120 -0
- data/lib/ro.rb +89 -317
- data/public/api/ro/index-1.json +1065 -0
- data/public/api/ro/index.json +1055 -0
- data/public/api/ro/nerd/fastest-possible-embeddings/index.json +90 -0
- data/public/api/ro/nerd/ima/index.json +49 -0
- data/public/api/ro/nerd/index/index.json +74 -0
- data/public/api/ro/nerd/index-1.json +204 -0
- data/public/api/ro/nerd/index.json +194 -0
- data/public/api/ro/pages/about/index.json +60 -0
- data/public/api/ro/pages/contact/index.json +50 -0
- data/public/api/ro/pages/cv/index.json +49 -0
- data/public/api/ro/pages/disco/index.json +117 -0
- data/public/api/ro/pages/index/index.json +30 -0
- data/public/api/ro/pages/index-1.json +366 -0
- data/public/api/ro/pages/index.json +356 -0
- data/public/api/ro/pages/jess/index.json +62 -0
- data/public/api/ro/pages/now/index.json +43 -0
- data/public/api/ro/posts/almost-died-in-an-ice-cave/index.json +265 -0
- data/public/api/ro/posts/facebook-and-global-extremism/index.json +90 -0
- data/public/api/ro/posts/index-1.json +527 -0
- data/public/api/ro/posts/index.json +517 -0
- data/public/api/ro/posts/lemmings-considered-harmful/index.json +49 -0
- data/public/api/ro/posts/lost-in-the-desert/index.json +49 -0
- data/public/api/ro/posts/mission/index.json +49 -0
- data/public/api/ro/posts/return-your-laptop/index.json +61 -0
- data/public/ro/nerd/fastest-possible-embeddings/assets/giraffe.jpeg +0 -0
- data/public/ro/nerd/fastest-possible-embeddings/assets/let-me-in.jpg +0 -0
- data/public/ro/nerd/fastest-possible-embeddings/assets/src/fastembed.js +70 -0
- data/public/ro/nerd/fastest-possible-embeddings/assets/src/fastembed.rs +68 -0
- data/public/ro/nerd/fastest-possible-embeddings/assets/terminal.jpg +0 -0
- data/public/ro/nerd/fastest-possible-embeddings/attributes.yml +7 -0
- data/public/ro/nerd/fastest-possible-embeddings/body.md +266 -0
- data/public/ro/nerd/ima/assets/og.jpeg +0 -0
- data/public/ro/nerd/ima/attributes.yml +8 -0
- data/public/ro/nerd/ima/body.md +22 -0
- data/public/ro/nerd/index/assets/giraffe.jpeg +0 -0
- data/public/ro/nerd/index/assets/let-me-in.jpg +0 -0
- data/public/ro/nerd/index/assets/terminal.jpg +0 -0
- data/public/ro/nerd/index/attributes.yml +7 -0
- data/public/ro/nerd/index/body.md +130 -0
- data/public/ro/pages/about/assets/og.jpeg +0 -0
- data/public/ro/pages/about/assets/speak-english-pulp-fiction.gif +0 -0
- data/public/ro/pages/about/body.md +40 -0
- data/public/ro/pages/contact/assets/giraffe.jpeg +0 -0
- data/public/ro/pages/contact/attributes.yml +7 -0
- data/public/ro/pages/contact/body.md +9 -0
- data/public/ro/pages/cv/assets/ara.jpg +0 -0
- data/public/ro/pages/cv/attributes.yml +6 -0
- data/public/ro/pages/cv/body.md +122 -0
- data/public/ro/pages/disco/assets/disco.jpg +0 -0
- data/public/ro/pages/disco/assets/disco.png +0 -0
- data/public/ro/pages/disco/assets/speak-english-pulp-fiction.gif +0 -0
- data/public/ro/pages/disco/assets/src/environment.md +2354 -0
- data/public/ro/pages/disco/assets/src/fortune-500.md +2518 -0
- data/public/ro/pages/disco/assets/src/greed.md +2703 -0
- data/public/ro/pages/disco/assets/src/up-at-night.md +2337 -0
- data/public/ro/pages/disco/attributes.yml +9 -0
- data/public/ro/pages/disco/body.md +99 -0
- data/public/ro/pages/disco/samples/environment.md +2354 -0
- data/public/ro/pages/disco/samples/fortune-500.md +2518 -0
- data/public/ro/pages/disco/samples/greed.md +2703 -0
- data/public/ro/pages/disco/samples/up-at-night.md +2337 -0
- data/public/ro/pages/index/attributes.yml +1 -0
- data/public/ro/pages/index/body.md +15 -0
- data/public/ro/pages/jess/assets/og.jpg +0 -0
- data/public/ro/pages/jess/assets/speak-english-pulp-fiction.gif +0 -0
- data/public/ro/pages/jess/attributes.yml +7 -0
- data/public/ro/pages/jess/body.md +3 -0
- data/public/ro/pages/now/assets/speak-english-pulp-fiction.gif +0 -0
- data/public/ro/pages/now/attributes.yml +1 -0
- data/public/ro/pages/now/body.md +24 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image1.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image10.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image11.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image12.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image13.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image14.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image15.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image2.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image3.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image4.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image5.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image6.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image7.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image8.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/image9.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/josh-pointing.jpg +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/levi-rawr.png +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/og.jpg +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/assets/purple-heart.jpg +0 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/attributes.yml +6 -0
- data/public/ro/posts/almost-died-in-an-ice-cave/body.md +419 -0
- data/public/ro/posts/facebook-and-global-extremism/assets/background.html +125 -0
- data/public/ro/posts/facebook-and-global-extremism/assets/background.md +95 -0
- data/public/ro/posts/facebook-and-global-extremism/assets/og.jpg +0 -0
- data/public/ro/posts/facebook-and-global-extremism/assets/prompt.txt +122 -0
- data/public/ro/posts/facebook-and-global-extremism/assets/results.md +183 -0
- data/public/ro/posts/facebook-and-global-extremism/assets/survey.txt +190 -0
- data/public/ro/posts/facebook-and-global-extremism/attributes.yml +7 -0
- data/public/ro/posts/facebook-and-global-extremism/body.md +393 -0
- data/public/ro/posts/lemmings-considered-harmful/assets/lemming.jpeg +0 -0
- data/public/ro/posts/lemmings-considered-harmful/attributes.yml +6 -0
- data/public/ro/posts/lemmings-considered-harmful/body.md +43 -0
- data/public/ro/posts/lost-in-the-desert/assets/og.jpg +0 -0
- data/public/ro/posts/lost-in-the-desert/attributes.yml +6 -0
- data/public/ro/posts/lost-in-the-desert/body.md +7 -0
- data/public/ro/posts/mission/assets/og.jpg +0 -0
- data/public/ro/posts/mission/attributes.yml +6 -0
- data/public/ro/posts/mission/body.md +4 -0
- data/public/ro/posts/return-your-laptop/assets/og.jpg +0 -0
- data/public/ro/posts/return-your-laptop/assets/return-your-laptop.png +0 -0
- data/public/ro/posts/return-your-laptop/attributes.yml +6 -0
- data/public/ro/posts/return-your-laptop/body.md +58 -0
- data/ro.gemspec +217 -28
- data/scripts/speedtest.rb +324 -0
- data/tmp/gem-details.oe +0 -0
- metadata +214 -74
- data/TODO.md +0 -50
- data/lib/ro/blankslate.rb +0 -7
- data/lib/ro/cache.rb +0 -26
- data/lib/ro/git.rb +0 -374
- data/lib/ro/initializers/env.rb +0 -5
- data/lib/ro/initializers/tilt.rb +0 -104
- data/lib/ro/lock.rb +0 -53
- data/lib/ro/node/list.rb +0 -142
- data/notes/ara.txt +0 -215
data/lib/ro/node.rb
CHANGED
@@ -1,478 +1,338 @@
|
|
1
1
|
module Ro
|
2
2
|
class Node
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
fattr :loaded
|
7
|
-
fattr :fields
|
3
|
+
include Klass
|
4
|
+
|
5
|
+
attr_reader :path, :root
|
8
6
|
|
9
7
|
def initialize(path)
|
10
|
-
@path =
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@type = File.basename(File.dirname(@path))
|
14
|
-
@root = Ro::Root.new(File.dirname(File.dirname(@path)))
|
15
|
-
@loaded = false
|
16
|
-
@loading = false
|
17
|
-
@attributes = Map.new
|
18
|
-
@fields = Map.new
|
8
|
+
@path = Path.for(path)
|
9
|
+
@root = Root.for(@path.parent.parent)
|
10
|
+
@attributes = :lazyload
|
19
11
|
end
|
20
12
|
|
21
|
-
def
|
22
|
-
@
|
13
|
+
def name
|
14
|
+
@path.name
|
23
15
|
end
|
24
16
|
|
25
|
-
def
|
26
|
-
|
17
|
+
def id
|
18
|
+
name
|
27
19
|
end
|
28
20
|
|
29
21
|
def type
|
30
|
-
|
22
|
+
@path.parent.name
|
31
23
|
end
|
32
24
|
|
33
|
-
def
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def path
|
38
|
-
attributes[:path] || @path
|
25
|
+
def identifier
|
26
|
+
File.join(type, id)
|
39
27
|
end
|
40
28
|
|
41
|
-
def
|
42
|
-
|
29
|
+
def inspect
|
30
|
+
identifier
|
43
31
|
end
|
44
32
|
|
45
|
-
def
|
46
|
-
|
33
|
+
def collection
|
34
|
+
@root.collection_for(type)
|
47
35
|
end
|
48
36
|
|
49
|
-
def
|
50
|
-
|
37
|
+
def attributes
|
38
|
+
load_attributes
|
39
|
+
@attributes
|
51
40
|
end
|
52
41
|
|
53
|
-
def
|
54
|
-
|
42
|
+
def load_attributes
|
43
|
+
load_attributes! if @attributes == :lazyload
|
55
44
|
end
|
56
45
|
|
57
|
-
def
|
58
|
-
|
59
|
-
end
|
46
|
+
def load_attributes!
|
47
|
+
@attributes = Map.new
|
60
48
|
|
61
|
-
|
62
|
-
|
63
|
-
|
49
|
+
_load_base_attributes
|
50
|
+
_load_file_attributes
|
51
|
+
_load_asset_attributes
|
52
|
+
_load_meta_attributes
|
64
53
|
|
65
|
-
|
66
|
-
identifier
|
54
|
+
@attributes
|
67
55
|
end
|
68
56
|
|
69
|
-
def
|
70
|
-
|
71
|
-
end
|
57
|
+
def _load_base_attributes
|
58
|
+
glob = "attributes.{yml,yaml,json}"
|
72
59
|
|
73
|
-
|
74
|
-
|
60
|
+
@path.glob(glob) do |file|
|
61
|
+
attrs = _render(file)
|
62
|
+
update_attributes!(attrs, file:)
|
63
|
+
end
|
75
64
|
end
|
76
65
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
66
|
+
def _load_asset_attributes
|
67
|
+
{}.tap do |hash|
|
68
|
+
assets.each do |asset|
|
69
|
+
key = asset.name
|
70
|
+
url = asset.url
|
71
|
+
path = asset.path.relative_to(@root)
|
72
|
+
src = asset.src
|
73
|
+
img = asset.img
|
74
|
+
size = asset.size
|
80
75
|
|
81
|
-
|
82
|
-
attributes.get(*args)
|
83
|
-
end
|
84
|
-
|
85
|
-
def [](*args)
|
86
|
-
attributes.get(*args)
|
87
|
-
end
|
76
|
+
value = { url:, path:, size:, img:, src: }
|
88
77
|
|
89
|
-
|
90
|
-
|
91
|
-
end
|
78
|
+
hash[key] = value
|
79
|
+
end
|
92
80
|
|
93
|
-
|
94
|
-
|
81
|
+
@attributes.set(assets: hash)
|
82
|
+
end
|
95
83
|
end
|
96
84
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
85
|
+
def _load_meta_attributes
|
86
|
+
{}.tap do |hash|
|
87
|
+
hash.update(
|
88
|
+
identifier:,
|
89
|
+
type:,
|
90
|
+
id:,
|
91
|
+
urls:,
|
92
|
+
created_at:,
|
93
|
+
updated_at:,
|
94
|
+
)
|
100
95
|
|
101
|
-
|
102
|
-
asset_paths.map do |path|
|
103
|
-
name = path.sub(asset_dir + "/", "")
|
104
|
-
path_info = path.gsub(/^#{ Regexp.escape(Ro.root) }/, '')
|
105
|
-
url = File.join(Ro.route, path_info)
|
106
|
-
Asset.new(name, :path => path, :url => url)
|
96
|
+
@attributes.set(_meta: hash)
|
107
97
|
end
|
108
98
|
end
|
109
99
|
|
110
|
-
def
|
111
|
-
|
112
|
-
end
|
100
|
+
def _load_file_attributes
|
101
|
+
ignored = _ignored_files
|
113
102
|
|
114
|
-
|
115
|
-
|
103
|
+
@path.files.each do |file|
|
104
|
+
next if ignored.include?(file)
|
116
105
|
|
117
|
-
|
106
|
+
rel = file.relative_to(@path)
|
118
107
|
|
119
|
-
|
108
|
+
key = rel.parts
|
109
|
+
basename = key.pop
|
110
|
+
base = basename.split('.', 2).first
|
111
|
+
key.push(base)
|
120
112
|
|
121
|
-
|
113
|
+
value = _render(file)
|
122
114
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
115
|
+
if value.is_a?(HTML)
|
116
|
+
attrs = value.front_matter
|
117
|
+
update_attributes!(attrs, file:)
|
118
|
+
end
|
141
119
|
|
142
|
-
|
143
|
-
|
120
|
+
if @attributes.has?(key)
|
121
|
+
raise Error.new("path=#{ @path.inspect } masks #{ key.inspect } in #{ @attributes.inspect }!")
|
122
|
+
end
|
144
123
|
|
145
|
-
|
146
|
-
begin
|
147
|
-
asset_for(*args, &block)
|
148
|
-
rescue
|
149
|
-
nil
|
124
|
+
@attributes.set(key => value)
|
150
125
|
end
|
151
126
|
end
|
152
127
|
|
153
|
-
|
154
|
-
|
155
|
-
fattr(:url)
|
128
|
+
def update_attributes!(attrs = {}, **context)
|
129
|
+
attrs = Map.for(attrs)
|
156
130
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
131
|
+
blacklist = %w[
|
132
|
+
assets
|
133
|
+
_meta
|
134
|
+
]
|
161
135
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
send(attr, value)
|
166
|
-
end
|
136
|
+
blacklist.each do |key|
|
137
|
+
if attrs.has_key?(key)
|
138
|
+
Ro.error!("#{ key } is blacklisted!", **context)
|
167
139
|
end
|
168
140
|
end
|
169
141
|
|
170
|
-
|
171
|
-
self
|
172
|
-
end
|
173
|
-
|
174
|
-
IMAGE_RE = %r/[.](jpg|jpeg|png|gif|tif|tiff)$/i
|
175
|
-
|
176
|
-
def image?
|
177
|
-
!!(self =~ IMAGE_RE)
|
178
|
-
end
|
142
|
+
keys = @attributes.depth_first_keys
|
179
143
|
|
180
|
-
|
181
|
-
|
182
|
-
|
144
|
+
attrs.depth_first_keys.each do |key|
|
145
|
+
if keys.include?(key)
|
146
|
+
Ro.error!("#{ attrs.inspect } clobbers #{ @attributes.inspect }!", **context)
|
147
|
+
end
|
183
148
|
end
|
184
|
-
alias_method(:ext, :extension)
|
185
149
|
|
186
|
-
|
187
|
-
File.basename(path.to_s)
|
188
|
-
end
|
150
|
+
@attributes.update(attrs)
|
189
151
|
end
|
190
152
|
|
191
|
-
def
|
192
|
-
|
193
|
-
|
194
|
-
|
153
|
+
def _ignored_files
|
154
|
+
ignored_files =
|
155
|
+
%w[
|
156
|
+
attributes.yml
|
157
|
+
attributes.yaml
|
158
|
+
attributes.json
|
159
|
+
./assets/**/**
|
160
|
+
].map do |glob|
|
161
|
+
@path.glob(glob).select(&:file?)
|
162
|
+
end
|
195
163
|
|
196
|
-
|
164
|
+
ignored_files.flatten
|
165
|
+
end
|
197
166
|
|
198
|
-
|
167
|
+
def _render(file)
|
168
|
+
node = self
|
199
169
|
|
200
|
-
|
170
|
+
value = Ro.render(file, _render_context)
|
201
171
|
|
202
|
-
if
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
opts[:_] = ts
|
207
|
-
end
|
172
|
+
if value.is_a?(HTML)
|
173
|
+
front_matter = value.front_matter
|
174
|
+
html = Ro.expand_asset_urls(value, node)
|
175
|
+
value = HTML.new(html, front_matter:)
|
208
176
|
end
|
209
177
|
|
210
|
-
if
|
211
|
-
|
212
|
-
|
213
|
-
query_string = Ro.query_string_for(opts)
|
214
|
-
"#{ asset.url }?#{ query_string }"
|
178
|
+
if value.is_a?(Hash)
|
179
|
+
attributes = value
|
180
|
+
value = Ro.expand_asset_values(attributes, node)
|
215
181
|
end
|
182
|
+
|
183
|
+
value
|
216
184
|
end
|
217
185
|
|
218
|
-
def
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
nil
|
186
|
+
def _render_context
|
187
|
+
to_hash.tap do |context|
|
188
|
+
context[:ro] ||= root
|
189
|
+
context[:collection] ||= collection
|
223
190
|
end
|
224
191
|
end
|
225
192
|
|
226
|
-
def
|
227
|
-
|
228
|
-
get(key)
|
193
|
+
def fetch(*args)
|
194
|
+
attributes.fetch(*args)
|
229
195
|
end
|
230
196
|
|
231
|
-
def
|
232
|
-
|
233
|
-
[Ro.asset_host, path_info].compact.join('/')
|
197
|
+
def get(*args)
|
198
|
+
attributes.get(*args)
|
234
199
|
end
|
235
200
|
|
236
|
-
def
|
237
|
-
|
238
|
-
@path.to_s.gsub(re, '')
|
201
|
+
def [](*args)
|
202
|
+
attributes.get(*args)
|
239
203
|
end
|
240
204
|
|
241
|
-
def
|
242
|
-
|
243
|
-
|
244
|
-
Ro.log "Ro::Node(#{ identifier })#method_missing(#{ method.inspect }, #{ args.inspect })"
|
245
|
-
|
246
|
-
key = method.to_s
|
247
|
-
|
248
|
-
if @attributes.has_key?(key)
|
249
|
-
return @attributes[key]
|
250
|
-
end
|
205
|
+
def relative_path
|
206
|
+
path.relative_to(root)
|
207
|
+
end
|
251
208
|
|
252
|
-
|
253
|
-
|
254
|
-
if @attributes.has_key?(key)
|
255
|
-
@attributes[key]
|
256
|
-
else
|
257
|
-
super
|
258
|
-
end
|
259
|
-
)
|
260
|
-
end
|
209
|
+
def asset_dir
|
210
|
+
path.join('assets')
|
261
211
|
end
|
262
212
|
|
263
|
-
def
|
264
|
-
|
213
|
+
def asset_paths
|
214
|
+
asset_dir.select { |entry| entry.file? }.sort
|
265
215
|
end
|
266
216
|
|
267
|
-
def
|
268
|
-
|
217
|
+
def assets
|
218
|
+
asset_paths.map { |path| Asset.for(path, node: self) }
|
269
219
|
end
|
270
|
-
|
271
|
-
def
|
272
|
-
|
220
|
+
|
221
|
+
def asset_urls
|
222
|
+
assets.map(&:url)
|
273
223
|
end
|
274
224
|
|
275
|
-
def
|
276
|
-
|
277
|
-
related = @attributes.get(:related) || Map.new
|
278
|
-
nodes = List.new(root)
|
279
|
-
list = root.nodes
|
280
|
-
which = Coerce.list_of_strings(args)
|
225
|
+
def asset_for(*args)
|
226
|
+
options = Map.options_for!(args)
|
281
227
|
|
282
|
-
|
283
|
-
unless which.empty?
|
284
|
-
next unless which.include?(relationship.to_s)
|
285
|
-
end
|
228
|
+
path_info = Path.relative(args)
|
286
229
|
|
287
|
-
|
288
|
-
case value
|
289
|
-
when Hash
|
290
|
-
value.to_a.first
|
291
|
-
else
|
292
|
-
[relationship, value]
|
293
|
-
end
|
230
|
+
path = @path.join('assets', path_info)
|
294
231
|
|
295
|
-
|
232
|
+
glob = path_info.gsub(/[_-]/, '[_-]')
|
296
233
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
234
|
+
globs =
|
235
|
+
[
|
236
|
+
@path.call('assets', "#{glob}"),
|
237
|
+
@path.call('assets', "#{glob}*"),
|
238
|
+
@path.call('assets', "**/#{glob}*")
|
239
|
+
]
|
303
240
|
|
304
|
-
|
305
|
-
when block.nil?
|
306
|
-
nodes
|
241
|
+
candidates = globs.map { |glob| Dir.glob(glob, ::File::FNM_CASEFOLD) }.flatten.compact.uniq.sort
|
307
242
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
243
|
+
case candidates.size
|
244
|
+
when 0
|
245
|
+
raise ArgumentError, "no asset matching #{globs.inspect}"
|
246
|
+
else
|
247
|
+
path = candidates.last
|
248
|
+
end
|
313
249
|
|
314
|
-
|
315
|
-
@loaded = false
|
316
|
-
_load(&block)
|
250
|
+
Asset.for(path, node: self)
|
317
251
|
end
|
318
252
|
|
319
|
-
def
|
320
|
-
|
253
|
+
def asset_for?(*args, &block)
|
254
|
+
asset_for(*args, &block)
|
255
|
+
rescue StandardError
|
256
|
+
nil
|
321
257
|
end
|
322
258
|
|
323
|
-
def
|
324
|
-
|
259
|
+
def url_for(relative_path, options = {})
|
260
|
+
Ro.url_for(self.relative_path, relative_path, options)
|
325
261
|
end
|
326
262
|
|
327
|
-
def
|
328
|
-
|
329
|
-
if @loading
|
330
|
-
return(block ? block.call : :loading)
|
331
|
-
end
|
332
|
-
|
333
|
-
@loading = true
|
334
|
-
@loaded = _load_from_cache_or_disk
|
335
|
-
@loading = false
|
336
|
-
end
|
337
|
-
|
338
|
-
block ? block.call : @loaded
|
263
|
+
def path_for(...)
|
264
|
+
@path.join(...)
|
339
265
|
end
|
340
266
|
|
341
|
-
def
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
if cached
|
347
|
-
Ro.log "loading #{ identifier } from cache"
|
267
|
+
def src_for(*args)
|
268
|
+
key = Path.relative(:assets, :src, args).split('/')
|
269
|
+
get(key)
|
270
|
+
end
|
348
271
|
|
349
|
-
|
272
|
+
def method_missing(method, *args, &block)
|
273
|
+
key = method.to_s
|
350
274
|
|
351
|
-
|
275
|
+
if attributes.has_key?(key)
|
276
|
+
attributes[key]
|
352
277
|
else
|
353
|
-
|
354
|
-
|
355
|
-
@attributes = Map.new
|
356
|
-
|
357
|
-
_load_attributes_yml
|
358
|
-
_load_attribute_files
|
359
|
-
_load_sources
|
360
|
-
_load_assets
|
361
|
-
|
362
|
-
Ro.cache.write(cache_key, @attributes)
|
363
|
-
|
364
|
-
return :disk
|
278
|
+
super
|
365
279
|
end
|
366
280
|
end
|
367
281
|
|
368
|
-
def
|
369
|
-
|
370
|
-
buf = IO.binread(_attributes_yml)
|
371
|
-
data = YAML.load(buf)
|
372
|
-
data = data.is_a?(Hash) ? data : {'_' => data}
|
373
|
-
|
374
|
-
@attributes.update(data)
|
375
|
-
|
376
|
-
%w( assets ).each do |key|
|
377
|
-
raise ArgumentError.new("attributes.yml may not contain the key '#{ key }'") if @attributes.has_key?(key)
|
378
|
-
end
|
379
|
-
|
380
|
-
@attributes
|
381
|
-
end
|
282
|
+
def to_hash
|
283
|
+
attributes.to_hash
|
382
284
|
end
|
383
285
|
|
384
|
-
def
|
385
|
-
|
386
|
-
node = self
|
387
|
-
|
388
|
-
Dir.glob(glob) do |path|
|
389
|
-
next if test(?d, path)
|
390
|
-
|
391
|
-
basename = File.basename(path)
|
392
|
-
next if basename == 'attributes.yml'
|
393
|
-
|
394
|
-
relative_path = Ro.relative_path(path, :to => @path)
|
395
|
-
next if relative_path =~ /^assets\//
|
396
|
-
|
397
|
-
key = relative_path.split('.', 2).first.split('/')
|
398
|
-
|
399
|
-
html = Ro.render(path, node)
|
400
|
-
html = Ro.expand_asset_urls(html, node)
|
401
|
-
|
402
|
-
@attributes.set(key => html)
|
403
|
-
end
|
286
|
+
def to_s(...)
|
287
|
+
to_json(...)
|
404
288
|
end
|
405
289
|
|
406
|
-
def
|
407
|
-
|
408
|
-
node = self
|
409
|
-
|
410
|
-
Dir.glob(glob) do |path|
|
411
|
-
next if test(?d, path)
|
412
|
-
|
413
|
-
basename = File.basename(path)
|
414
|
-
key, ext = basename.split('.', 2)
|
415
|
-
|
416
|
-
next if basename == 'attributes.yml'
|
417
|
-
|
418
|
-
value = Ro.render_source(path, node)
|
419
|
-
@attributes.set([:assets, :source, basename] => value)
|
420
|
-
end
|
290
|
+
def to_str(...)
|
291
|
+
to_json(...)
|
421
292
|
end
|
422
293
|
|
423
|
-
def
|
424
|
-
|
425
|
-
node = self
|
426
|
-
|
427
|
-
Dir.glob(glob) do |path|
|
428
|
-
next if test(?d, path)
|
429
|
-
|
430
|
-
relative_path = Ro.relative_path(path, :to => "#{ @path }/assets")
|
431
|
-
|
432
|
-
url = url_for(relative_path)
|
433
|
-
key = relative_path.split('/')
|
434
|
-
|
435
|
-
key.unshift('urls')
|
436
|
-
|
437
|
-
@attributes.set(key => url)
|
438
|
-
end
|
294
|
+
def to_json(...)
|
295
|
+
JSON.pretty_generate(to_hash, ...)
|
439
296
|
end
|
440
297
|
|
441
|
-
def
|
442
|
-
|
298
|
+
def as_json(...)
|
299
|
+
to_hash.as_json(...)
|
443
300
|
end
|
444
301
|
|
445
|
-
def
|
446
|
-
|
302
|
+
def to_yaml(...)
|
303
|
+
to_hash.to_yaml(...)
|
304
|
+
end
|
447
305
|
|
448
|
-
|
306
|
+
def files
|
307
|
+
path.glob('**/**').select { |entry| entry.file? }.sort
|
308
|
+
end
|
449
309
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
File.stat(entry)
|
454
|
-
rescue
|
455
|
-
next
|
456
|
-
end
|
310
|
+
def urls
|
311
|
+
files.map { |file| url_for(file.relative_to(@path)) }.sort
|
312
|
+
end
|
457
313
|
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
end
|
314
|
+
def <=>(other)
|
315
|
+
sort_key <=> other.sort_key
|
316
|
+
end
|
462
317
|
|
463
|
-
|
318
|
+
def sort_key
|
319
|
+
default_sort_key
|
320
|
+
end
|
464
321
|
|
465
|
-
|
322
|
+
def default_sort_key
|
323
|
+
position = (attributes[:position] ? Float(attributes[:position]) : 0.0)
|
324
|
+
published_at = (attributes[:published_at] ? Time.parse(attributes[:published_at].to_s) : Time.at(0)).utc.iso8601
|
325
|
+
created_at = (attributes[:created_at] ? Time.parse(attributes[:created_at].to_s) : Time.at(0)).utc.iso8601
|
466
326
|
|
467
|
-
[
|
327
|
+
[position, published_at, created_at, name]
|
468
328
|
end
|
469
329
|
|
470
|
-
def
|
471
|
-
|
330
|
+
def created_at
|
331
|
+
files.map{|file| File.stat(file).ctime}.min
|
472
332
|
end
|
473
333
|
|
474
|
-
def
|
475
|
-
File.
|
334
|
+
def updated_at
|
335
|
+
files.map{|file| File.stat(file).mtime}.max
|
476
336
|
end
|
477
337
|
end
|
478
338
|
end
|