flutterby 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flutterby/cli.rb +1 -1
- data/lib/flutterby/{entity.rb → node.rb} +112 -13
- data/lib/flutterby/server.rb +2 -3
- data/lib/flutterby/version.rb +1 -1
- data/lib/flutterby/view.rb +1 -1
- data/lib/flutterby.rb +11 -7
- metadata +2 -4
- data/lib/flutterby/file.rb +0 -95
- data/lib/flutterby/folder.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa91b42f64b52a8f3a568cd3a95ac7d366d997ea
|
4
|
+
data.tar.gz: 6ee2175701e8b15dae84f1a8665f0473678851fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4b993b640531755f04c6115ee949c26d7cb1d0f4ff2adaac173397cf1b94b688ef3e051369880f369ab9dd9e779ac4d11dabb9924d843ad71bb5be0277eb912
|
7
|
+
data.tar.gz: ca707746919b8e08c0563506d67ecc9a32fa9d32c8c373164b9f2ae18102abfef51680c3506fd3e7a1c3106325f0a342e6a8caa4e93701ddfafb4d522c7d86dd
|
data/lib/flutterby/cli.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
module Flutterby
|
2
|
-
class
|
3
|
-
attr_accessor :parent, :ext
|
2
|
+
class Node
|
3
|
+
attr_accessor :parent, :ext, :source, :body
|
4
4
|
attr_reader :name, :filters, :fs_path, :data, :children
|
5
|
-
alias_method :folder, :parent
|
6
5
|
|
7
6
|
def initialize(name, parent: nil, fs_path: nil)
|
8
7
|
@parent = parent
|
9
8
|
@data = {}
|
10
|
-
reset_children!
|
11
9
|
|
12
10
|
# Extract name, extension, and filters from given name
|
13
11
|
parts = name.split(".")
|
@@ -23,8 +21,9 @@ module Flutterby
|
|
23
21
|
# If a filesystem path was given, read the entity from disk
|
24
22
|
if fs_path
|
25
23
|
@fs_path = ::File.expand_path(fs_path)
|
26
|
-
read
|
27
24
|
end
|
25
|
+
|
26
|
+
reload!
|
28
27
|
end
|
29
28
|
|
30
29
|
#
|
@@ -127,27 +126,95 @@ module Flutterby
|
|
127
126
|
#
|
128
127
|
|
129
128
|
def reload!
|
129
|
+
@body = nil
|
130
130
|
reset_children!
|
131
|
-
|
131
|
+
|
132
|
+
if @fs_path
|
133
|
+
if ::File.directory?(fs_path)
|
134
|
+
Dir[::File.join(fs_path, "*")].each do |entry|
|
135
|
+
if entity = Flutterby.from(entry)
|
136
|
+
children << entity
|
137
|
+
end
|
138
|
+
end
|
139
|
+
else
|
140
|
+
@source = ::File.read(fs_path)
|
141
|
+
|
142
|
+
# Extract date from name
|
143
|
+
if name =~ %r{^(\d\d\d\d\-\d\d?\-\d\d?)\-}
|
144
|
+
@data['date'] = Time.parse($1)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Read remaining data from frontmatter. Data in frontmatter
|
148
|
+
# will always have precedence!
|
149
|
+
@data.merge! parse_frontmatter
|
150
|
+
|
151
|
+
# Do some extra processing depending on extension
|
152
|
+
meth = "read_#{ext}"
|
153
|
+
send(meth) if respond_to?(meth)
|
154
|
+
end
|
155
|
+
end
|
132
156
|
end
|
133
157
|
|
134
|
-
|
158
|
+
|
159
|
+
#
|
160
|
+
# Rendering
|
161
|
+
#
|
162
|
+
|
163
|
+
def view
|
164
|
+
@view ||= View.for(self)
|
165
|
+
end
|
166
|
+
|
167
|
+
def body
|
168
|
+
Filters.apply!(self) if @body.nil?
|
169
|
+
@body
|
135
170
|
end
|
136
171
|
|
172
|
+
def render(layout: true)
|
173
|
+
(layout && apply_layout?) ? apply_layout(body) : body
|
174
|
+
end
|
175
|
+
|
176
|
+
def apply_layout(input)
|
177
|
+
walk_up(input) do |e, current|
|
178
|
+
if layout = e.sibling("_layout")
|
179
|
+
tilt = Tilt[layout.ext].new { layout.source }
|
180
|
+
tilt.render(view) { current }
|
181
|
+
else
|
182
|
+
current
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def apply_layout?
|
188
|
+
page?
|
189
|
+
end
|
190
|
+
|
191
|
+
|
137
192
|
|
138
193
|
#
|
139
194
|
# Exporting
|
140
195
|
#
|
141
196
|
|
142
|
-
def export(
|
197
|
+
def export(into:)
|
143
198
|
if should_publish?
|
144
|
-
|
145
|
-
|
146
|
-
write_static(out_path)
|
199
|
+
puts "* #{url}"
|
200
|
+
write_static(into: into)
|
147
201
|
end
|
148
202
|
end
|
149
203
|
|
150
|
-
def write_static(
|
204
|
+
def write_static(into:)
|
205
|
+
if folder?
|
206
|
+
# write children, acting as a directory
|
207
|
+
|
208
|
+
path = full_fs_path(base: into)
|
209
|
+
Dir.mkdir(path) unless ::File.exists?(path)
|
210
|
+
|
211
|
+
children.each do |child|
|
212
|
+
child.export(into: path)
|
213
|
+
end
|
214
|
+
else
|
215
|
+
# write a file
|
216
|
+
::File.write(full_fs_path(base: into), render)
|
217
|
+
end
|
151
218
|
end
|
152
219
|
|
153
220
|
def should_publish?
|
@@ -155,6 +222,34 @@ module Flutterby
|
|
155
222
|
end
|
156
223
|
|
157
224
|
|
225
|
+
#
|
226
|
+
# Front Matter Parsing
|
227
|
+
#
|
228
|
+
|
229
|
+
def parse_frontmatter
|
230
|
+
data = {}
|
231
|
+
|
232
|
+
# YAML Front Matter
|
233
|
+
if @source.sub!(/\A\-\-\-\n(.+)\n\-\-\-\n/m, "")
|
234
|
+
data.merge! YAML.load($1)
|
235
|
+
end
|
236
|
+
|
237
|
+
# TOML Front Matter
|
238
|
+
if @source.sub!(/\A\+\+\+\n(.+)\n\+\+\+\n/m, "")
|
239
|
+
data.merge! TOML.parse($1)
|
240
|
+
end
|
241
|
+
|
242
|
+
data
|
243
|
+
end
|
244
|
+
|
245
|
+
def read_json
|
246
|
+
data.merge!(JSON.parse(@source))
|
247
|
+
end
|
248
|
+
|
249
|
+
def read_yaml
|
250
|
+
data.merge!(YAML.load(@source))
|
251
|
+
end
|
252
|
+
|
158
253
|
|
159
254
|
#
|
160
255
|
# Misc
|
@@ -168,8 +263,12 @@ module Flutterby
|
|
168
263
|
[name, ext].compact.join(".")
|
169
264
|
end
|
170
265
|
|
266
|
+
def folder?
|
267
|
+
children.any?
|
268
|
+
end
|
269
|
+
|
171
270
|
def page?
|
172
|
-
|
271
|
+
!folder? && ext == "html"
|
173
272
|
end
|
174
273
|
end
|
175
274
|
end
|
data/lib/flutterby/server.rb
CHANGED
@@ -46,8 +46,7 @@ module Flutterby
|
|
46
46
|
# halt if we're not supposed to serve current entity
|
47
47
|
throw :halt, :error_404 unless current.should_publish?
|
48
48
|
|
49
|
-
|
50
|
-
when Flutterby::Folder then
|
49
|
+
if current.folder? then
|
51
50
|
# If no further parts are requested, let's look for an index
|
52
51
|
# document and serve that instead.
|
53
52
|
if child = current.find(parts.empty? ? "index" : parts.shift)
|
@@ -55,7 +54,7 @@ module Flutterby
|
|
55
54
|
else
|
56
55
|
throw :halt, :error_404
|
57
56
|
end
|
58
|
-
|
57
|
+
else
|
59
58
|
# Determine MIME type
|
60
59
|
mime_type = MIME::Types.type_for(current.ext) || "text/plain"
|
61
60
|
|
data/lib/flutterby/version.rb
CHANGED
data/lib/flutterby/view.rb
CHANGED
data/lib/flutterby.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
require 'slodown'
|
2
|
+
require 'sass'
|
3
|
+
require 'tilt'
|
4
|
+
require 'slim'
|
5
|
+
require 'toml'
|
6
|
+
require 'mime-types'
|
7
|
+
require 'json'
|
8
|
+
|
1
9
|
require "flutterby/version"
|
2
|
-
require "flutterby/
|
3
|
-
require "flutterby/file"
|
4
|
-
require "flutterby/folder"
|
10
|
+
require "flutterby/node"
|
5
11
|
require "flutterby/filters"
|
6
12
|
require "flutterby/view"
|
7
13
|
require "flutterby/server"
|
@@ -11,10 +17,8 @@ module Flutterby
|
|
11
17
|
def Flutterby.from(fs_path, name: nil, parent: nil)
|
12
18
|
name ||= ::File.basename(fs_path)
|
13
19
|
|
14
|
-
if ::File.
|
15
|
-
|
16
|
-
elsif ::File.file?(fs_path)
|
17
|
-
File.new(name, fs_path: fs_path, parent: parent)
|
20
|
+
if ::File.exist?(fs_path)
|
21
|
+
Node.new(name, fs_path: fs_path, parent: parent)
|
18
22
|
else
|
19
23
|
raise "Path #{fs_path} could not be found."
|
20
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flutterby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hendrik Mans
|
@@ -243,10 +243,8 @@ files:
|
|
243
243
|
- flutterby.gemspec
|
244
244
|
- lib/flutterby.rb
|
245
245
|
- lib/flutterby/cli.rb
|
246
|
-
- lib/flutterby/entity.rb
|
247
|
-
- lib/flutterby/file.rb
|
248
246
|
- lib/flutterby/filters.rb
|
249
|
-
- lib/flutterby/
|
247
|
+
- lib/flutterby/node.rb
|
250
248
|
- lib/flutterby/server.rb
|
251
249
|
- lib/flutterby/version.rb
|
252
250
|
- lib/flutterby/view.rb
|
data/lib/flutterby/file.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'slodown'
|
2
|
-
require 'sass'
|
3
|
-
require 'tilt'
|
4
|
-
require 'slim'
|
5
|
-
require 'toml'
|
6
|
-
require 'mime-types'
|
7
|
-
require 'json'
|
8
|
-
|
9
|
-
module Flutterby
|
10
|
-
class File < Entity
|
11
|
-
attr_accessor :source, :body
|
12
|
-
|
13
|
-
def reload!
|
14
|
-
@body = nil
|
15
|
-
super
|
16
|
-
end
|
17
|
-
|
18
|
-
def read
|
19
|
-
@source = ::File.read(fs_path)
|
20
|
-
|
21
|
-
# Extract date from name
|
22
|
-
if name =~ %r{^(\d\d\d\d\-\d\d?\-\d\d?)\-}
|
23
|
-
@data['date'] = Time.parse($1)
|
24
|
-
end
|
25
|
-
|
26
|
-
# Read remaining data from frontmatter. Data in frontmatter
|
27
|
-
# will always have precedence!
|
28
|
-
@data.merge! parse_frontmatter
|
29
|
-
|
30
|
-
# Do some extra processing depending on extension
|
31
|
-
meth = "read_#{ext}"
|
32
|
-
send(meth) if respond_to?(meth)
|
33
|
-
end
|
34
|
-
|
35
|
-
def parse_frontmatter
|
36
|
-
data = {}
|
37
|
-
|
38
|
-
# YAML Front Matter
|
39
|
-
if @source.sub!(/\A\-\-\-\n(.+)\n\-\-\-\n/m, "")
|
40
|
-
data.merge! YAML.load($1)
|
41
|
-
end
|
42
|
-
|
43
|
-
# TOML Front Matter
|
44
|
-
if @source.sub!(/\A\+\+\+\n(.+)\n\+\+\+\n/m, "")
|
45
|
-
data.merge! TOML.parse($1)
|
46
|
-
end
|
47
|
-
|
48
|
-
data
|
49
|
-
end
|
50
|
-
|
51
|
-
def body
|
52
|
-
Filters.apply!(self) if @body.nil?
|
53
|
-
@body
|
54
|
-
end
|
55
|
-
|
56
|
-
def page?
|
57
|
-
ext == "html"
|
58
|
-
end
|
59
|
-
|
60
|
-
def view
|
61
|
-
@view ||= View.for(self)
|
62
|
-
end
|
63
|
-
|
64
|
-
def read_json
|
65
|
-
data.merge!(JSON.parse(@source))
|
66
|
-
end
|
67
|
-
|
68
|
-
def read_yaml
|
69
|
-
data.merge!(YAML.load(@source))
|
70
|
-
end
|
71
|
-
|
72
|
-
def apply_layout(input)
|
73
|
-
walk_up(input) do |e, current|
|
74
|
-
if layout = e.sibling("_layout")
|
75
|
-
tilt = Tilt[layout.ext].new { layout.source }
|
76
|
-
tilt.render(view) { current }
|
77
|
-
else
|
78
|
-
current
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def apply_layout?
|
84
|
-
page?
|
85
|
-
end
|
86
|
-
|
87
|
-
def render(layout: true)
|
88
|
-
(layout && apply_layout?) ? apply_layout(body) : body
|
89
|
-
end
|
90
|
-
|
91
|
-
def write_static(path)
|
92
|
-
::File.write(path, render)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
data/lib/flutterby/folder.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Flutterby
|
2
|
-
class Folder < Entity
|
3
|
-
def read
|
4
|
-
Dir[::File.join(fs_path, "*")].each do |entry|
|
5
|
-
if entity = Flutterby.from(entry)
|
6
|
-
children << entity
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def write_static(path)
|
12
|
-
Dir.mkdir(path) unless ::File.exists?(path)
|
13
|
-
|
14
|
-
children.each do |child|
|
15
|
-
child.export(path)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|