flutterby 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flutterby.rb +1 -0
- data/lib/flutterby/cli.rb +0 -11
- data/lib/flutterby/entity.rb +92 -17
- data/lib/flutterby/file.rb +5 -4
- data/lib/flutterby/folder.rb +6 -25
- data/lib/flutterby/version.rb +1 -1
- data/lib/flutterby/view.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46ebc1c85a56b410c6147dd87503c8fd59cd0d74
|
4
|
+
data.tar.gz: 5d65a75d308e436afed08be445828ab94c02396e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4a6a0aee56906711254d63a905a6c95e5cd098cbc76bb8936e522f6eaea97af49f2c8e3bc8f749857090ff40556c77e033cc5aabb86c832ef97f3aec1ce6c1f
|
7
|
+
data.tar.gz: f1918f98a08abb87bfd9e0298abb739dc76f74a3ee01bef2f926f696a8378c2b4b89f589c74b213141877e09a902c2b7f89197935956f4e8ed48208ada0641a0
|
data/lib/flutterby.rb
CHANGED
data/lib/flutterby/cli.rb
CHANGED
@@ -35,15 +35,4 @@ Commander.configure do
|
|
35
35
|
server.run!
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
39
|
-
|
40
|
-
command :test do |c|
|
41
|
-
c.syntax = 'flutterby test'
|
42
|
-
c.description = 'TEST. Yo.'
|
43
|
-
c.action do |args, options|
|
44
|
-
root = Flutterby.from("./in", name: "/")
|
45
|
-
root.list
|
46
|
-
root.export("./out/")
|
47
|
-
end
|
48
|
-
end
|
49
38
|
end
|
data/lib/flutterby/entity.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Flutterby
|
2
2
|
class Entity
|
3
|
-
|
3
|
+
attr_accessor :parent
|
4
|
+
attr_reader :name, :ext, :filters, :fs_path, :data, :children
|
4
5
|
|
5
6
|
def initialize(name, parent: nil, fs_path: nil)
|
6
|
-
@parent = parent
|
7
7
|
@data = {}
|
8
|
+
reset_children!
|
8
9
|
|
9
10
|
# Extract name, extension, and filters from given name
|
10
11
|
parts = name.split(".")
|
@@ -12,8 +13,7 @@ module Flutterby
|
|
12
13
|
@ext = parts.shift
|
13
14
|
@filters = parts.reverse
|
14
15
|
|
15
|
-
|
16
|
-
@path = parent ? ::File.join(parent.path, full_name) : full_name
|
16
|
+
self.parent = parent
|
17
17
|
|
18
18
|
# If a filesystem path was given, read the entity from disk
|
19
19
|
if fs_path
|
@@ -22,30 +22,53 @@ module Flutterby
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
#
|
26
|
+
# Children
|
27
|
+
#
|
28
|
+
|
29
|
+
def reset_children!
|
30
|
+
@children = []
|
31
|
+
me = self
|
32
|
+
|
33
|
+
# Inject some extra methods into this array because this is dirty old Ruby
|
34
|
+
@children.define_singleton_method(:<<) do |c|
|
35
|
+
c.parent = me
|
36
|
+
super(c)
|
37
|
+
end
|
38
|
+
|
39
|
+
@children.define_singleton_method(:find_by_name) do |name|
|
40
|
+
name = name.split('.').first
|
41
|
+
find { |c| c.name == name }
|
42
|
+
end
|
27
43
|
end
|
28
44
|
|
29
|
-
|
30
|
-
|
45
|
+
# Returns all children that will compile to a HTML page.
|
46
|
+
#
|
47
|
+
def pages
|
48
|
+
children.select { |c| c.ext == "html" }
|
31
49
|
end
|
32
50
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
51
|
+
#
|
52
|
+
# Path Algebra
|
53
|
+
#
|
54
|
+
|
55
|
+
def path
|
56
|
+
parent ? ::File.join(parent.path, full_name) : full_name
|
39
57
|
end
|
40
58
|
|
41
59
|
def url
|
42
60
|
@url ||= ::File.join(parent ? parent.url : "/", full_name)
|
43
61
|
end
|
44
62
|
|
45
|
-
def
|
63
|
+
def full_fs_path(base:)
|
46
64
|
::File.expand_path(::File.join(base, full_name))
|
47
65
|
end
|
48
66
|
|
67
|
+
|
68
|
+
#
|
69
|
+
# Tree Walking
|
70
|
+
#
|
71
|
+
|
49
72
|
def root
|
50
73
|
parent ? parent.root : self
|
51
74
|
end
|
@@ -54,13 +77,51 @@ module Flutterby
|
|
54
77
|
parent && parent.find(name)
|
55
78
|
end
|
56
79
|
|
57
|
-
def
|
58
|
-
|
80
|
+
def find(path)
|
81
|
+
return self if path.nil? || path.empty?
|
82
|
+
|
83
|
+
# remove duplicate slashes
|
84
|
+
path.gsub!(%r{//}, "/")
|
85
|
+
|
86
|
+
case path
|
87
|
+
when %r{^\.\./?} then
|
88
|
+
parent ? parent.find($') : nil
|
89
|
+
when %r{^\.} then
|
90
|
+
self
|
91
|
+
when %r{^/} then
|
92
|
+
root.find($')
|
93
|
+
when %r{^([^/]+)/?} then
|
94
|
+
child = @children.find_by_name($1)
|
95
|
+
$'.empty? ? child : child.find($')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
#
|
101
|
+
# Reading from filesystem
|
102
|
+
#
|
103
|
+
|
104
|
+
def reload!
|
105
|
+
reset_children!
|
106
|
+
read
|
59
107
|
end
|
60
108
|
|
61
109
|
def read
|
62
110
|
end
|
63
111
|
|
112
|
+
|
113
|
+
#
|
114
|
+
# Exporting
|
115
|
+
#
|
116
|
+
|
117
|
+
def export(out_path)
|
118
|
+
if should_publish?
|
119
|
+
out_path = full_fs_path(base: out_path)
|
120
|
+
puts "* #{@name}: #{out_path}"
|
121
|
+
write_static(out_path)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
64
125
|
def write_static(path)
|
65
126
|
end
|
66
127
|
|
@@ -68,6 +129,20 @@ module Flutterby
|
|
68
129
|
!name.start_with?("_")
|
69
130
|
end
|
70
131
|
|
132
|
+
|
133
|
+
|
134
|
+
#
|
135
|
+
# Misc
|
136
|
+
#
|
137
|
+
|
138
|
+
def to_s
|
139
|
+
"<#{self.class} #{self.path}>"
|
140
|
+
end
|
141
|
+
|
142
|
+
def full_name
|
143
|
+
@full_name ||= [name, ext].compact.join(".")
|
144
|
+
end
|
145
|
+
|
71
146
|
def page?
|
72
147
|
false
|
73
148
|
end
|
data/lib/flutterby/file.rb
CHANGED
@@ -29,14 +29,15 @@ module Flutterby
|
|
29
29
|
|
30
30
|
def parse_frontmatter
|
31
31
|
data = {}
|
32
|
-
|
32
|
+
|
33
|
+
# YAML Front Matter
|
34
|
+
if @contents.sub!(/\A\-\-\-\n(.+)\n\-\-\-\n/m, "")
|
33
35
|
data.merge! YAML.load($1)
|
34
|
-
""
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
+
# TOML Front Matter
|
39
|
+
if @contents.sub!(/\A\+\+\+\n(.+)\n\+\+\+\n/m, "")
|
38
40
|
data.merge! TOML.parse($1)
|
39
|
-
""
|
40
41
|
end
|
41
42
|
|
42
43
|
data
|
data/lib/flutterby/folder.rb
CHANGED
@@ -1,38 +1,19 @@
|
|
1
1
|
module Flutterby
|
2
2
|
class Folder < Entity
|
3
|
-
attr_reader :children
|
4
|
-
|
5
|
-
def list(indent: 0)
|
6
|
-
super
|
7
|
-
children.each { |c| c.list(indent: indent + 1) }
|
8
|
-
end
|
9
|
-
|
10
3
|
def read
|
11
|
-
|
12
|
-
Flutterby.from(entry
|
13
|
-
|
4
|
+
Dir[::File.join(fs_path, "*")].each do |entry|
|
5
|
+
if entity = Flutterby.from(entry)
|
6
|
+
children << entity
|
7
|
+
end
|
8
|
+
end
|
14
9
|
end
|
15
10
|
|
16
11
|
def write_static(path)
|
17
12
|
Dir.mkdir(path) unless ::File.exists?(path)
|
18
13
|
|
19
|
-
|
14
|
+
children.each do |child|
|
20
15
|
child.export(path)
|
21
16
|
end
|
22
17
|
end
|
23
|
-
|
24
|
-
def find(path)
|
25
|
-
(name, slash, rest) = path.partition("/")
|
26
|
-
|
27
|
-
name = name.split('.').first
|
28
|
-
child = @children.find { |c| c.name == name }
|
29
|
-
rest.empty? ? child : child.find(rest)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns all children that will compile to a HTML page.
|
33
|
-
#
|
34
|
-
def pages
|
35
|
-
children.select { |c| c.ext == "html" }
|
36
|
-
end
|
37
18
|
end
|
38
19
|
end
|
data/lib/flutterby/version.rb
CHANGED
data/lib/flutterby/view.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Flutterby
|
2
2
|
class View
|
3
3
|
attr_reader :entity
|
4
|
+
alias_method :page, :entity
|
4
5
|
|
5
6
|
def initialize(entity)
|
6
7
|
@entity = entity
|
@@ -9,5 +10,13 @@ module Flutterby
|
|
9
10
|
def date_format(date, fmt)
|
10
11
|
date.strftime(fmt)
|
11
12
|
end
|
13
|
+
|
14
|
+
def render(expr, *args)
|
15
|
+
find(expr).render(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find(expr)
|
19
|
+
entity.find(expr) or raise "No entity found for #{expr}"
|
20
|
+
end
|
12
21
|
end
|
13
22
|
end
|