syntropy 0.7 → 0.8
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/syntropy/app.rb +2 -33
- data/lib/syntropy/markdown.rb +39 -0
- data/lib/syntropy/module.rb +41 -31
- data/lib/syntropy/version.rb +1 -1
- data/lib/syntropy.rb +6 -6
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df2a40954f2c157f5820138528b8c4a5589670b77b5d661a3c55a8f882231f64
|
4
|
+
data.tar.gz: e74d8ab77bf364d4ae4629057fcb0a3027e5901e258b22504f473d99327b9f8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1221b890c2bf0d28cef98e6cca53918e45101c1505d1b745022ec93545a6edbe9e67b281dcadf0f037bcced05a116106c1f27e95eedebdba8f587e03dcc13cd3
|
7
|
+
data.tar.gz: 5fa7d7da0207068c6130bc70bb4582c74bde3f9cecbe164fad2c8f93b56f2f8f30bd445bf0d015aa834c3e0e04ead49ca5bd13c3ba2ce1b872006d3fa6afe31a
|
data/CHANGELOG.md
CHANGED
data/lib/syntropy/app.rb
CHANGED
@@ -151,46 +151,15 @@ module Syntropy
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def render_markdown(fn)
|
154
|
-
atts, md = parse_markdown_file(fn)
|
154
|
+
atts, md = Syntropy.parse_markdown_file(fn, @opts)
|
155
155
|
|
156
156
|
if atts[:layout]
|
157
157
|
layout = @module_loader.load("_layout/#{atts[:layout]}")
|
158
|
-
html = layout.apply { emit_markdown(md) }.render
|
158
|
+
html = layout.apply(**atts) { emit_markdown(md) }.render
|
159
159
|
else
|
160
160
|
html = Papercraft.markdown(md)
|
161
161
|
end
|
162
162
|
html
|
163
163
|
end
|
164
|
-
|
165
|
-
DATE_REGEXP = /(\d{4}\-\d{2}\-\d{2})/
|
166
|
-
FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
167
|
-
YAML_OPTS = {
|
168
|
-
permitted_classes: [Date],
|
169
|
-
symbolize_names: true
|
170
|
-
}
|
171
|
-
|
172
|
-
# Parses the markdown file at the given path.
|
173
|
-
#
|
174
|
-
# @param path [String] file path
|
175
|
-
# @return [Array] an tuple containing properties<Hash>, contents<String>
|
176
|
-
def parse_markdown_file(path)
|
177
|
-
content = IO.read(path) || ''
|
178
|
-
atts = {}
|
179
|
-
|
180
|
-
# Parse date from file name
|
181
|
-
if (m = path.match(DATE_REGEXP))
|
182
|
-
atts[:date] ||= Date.parse(m[1])
|
183
|
-
end
|
184
|
-
|
185
|
-
if (m = content.match(FRONT_MATTER_REGEXP))
|
186
|
-
front_matter = m[1]
|
187
|
-
content = m.post_match
|
188
|
-
|
189
|
-
yaml = YAML.safe_load(front_matter, **YAML_OPTS)
|
190
|
-
atts = atts.merge(yaml)
|
191
|
-
end
|
192
|
-
|
193
|
-
[atts, content]
|
194
|
-
end
|
195
164
|
end
|
196
165
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Syntropy
|
4
|
+
DATE_REGEXP = /(\d{4}-\d{2}-\d{2})/
|
5
|
+
FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
6
|
+
YAML_OPTS = {
|
7
|
+
permitted_classes: [Date],
|
8
|
+
symbolize_names: true
|
9
|
+
}
|
10
|
+
|
11
|
+
# Parses the markdown file at the given path.
|
12
|
+
#
|
13
|
+
# @param path [String] file path
|
14
|
+
# @return [Array] an tuple containing properties<Hash>, contents<String>
|
15
|
+
def self.parse_markdown_file(path, opts)
|
16
|
+
content = IO.read(path) || ''
|
17
|
+
atts = {}
|
18
|
+
|
19
|
+
# Parse date from file name
|
20
|
+
m = path.match(DATE_REGEXP)
|
21
|
+
atts[:date] ||= Date.parse(m[1]) if m
|
22
|
+
|
23
|
+
if (m = content.match(FRONT_MATTER_REGEXP))
|
24
|
+
front_matter = m[1]
|
25
|
+
content = m.post_match
|
26
|
+
|
27
|
+
yaml = YAML.safe_load(front_matter, **YAML_OPTS)
|
28
|
+
atts = atts.merge(yaml)
|
29
|
+
end
|
30
|
+
|
31
|
+
if opts[:location]
|
32
|
+
atts[:url] = path
|
33
|
+
.gsub(/#{opts[:location]}/, '')
|
34
|
+
.gsub(/\.md$/, '')
|
35
|
+
end
|
36
|
+
|
37
|
+
[atts, content]
|
38
|
+
end
|
39
|
+
end
|
data/lib/syntropy/module.rb
CHANGED
@@ -32,8 +32,7 @@ module Syntropy
|
|
32
32
|
|
33
33
|
mod_body = IO.read(fn)
|
34
34
|
mod_ctx = Class.new(Syntropy::Module)
|
35
|
-
mod_ctx.loader
|
36
|
-
mod_ctx.env = @env
|
35
|
+
mod_ctx.prepare(loader: self, env: @env)
|
37
36
|
mod_ctx.module_eval(mod_body, fn, 1)
|
38
37
|
|
39
38
|
export_value = mod_ctx.__export_value__
|
@@ -63,45 +62,56 @@ module Syntropy
|
|
63
62
|
@env = env
|
64
63
|
end
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
class << self
|
66
|
+
def prepare(loader:, env:)
|
67
|
+
@loader = loader
|
68
|
+
@env = env
|
69
|
+
const_set(:MODULE, self)
|
70
|
+
end
|
69
71
|
|
70
|
-
|
71
|
-
@env = env
|
72
|
-
end
|
72
|
+
attr_reader :__export_value__
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
def import(ref)
|
75
|
+
@loader.load(ref)
|
76
|
+
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
def export(ref)
|
79
|
+
@__export_value__ = ref
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
def template(&block)
|
83
|
+
Papercraft.html(&block)
|
84
|
+
end
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
def route_by_host(map = nil)
|
87
|
+
root = @env[:location]
|
88
|
+
sites = Dir[File.join(root, '*')]
|
89
|
+
.select { File.directory?(it) }
|
90
|
+
.each_with_object({}) { |fn, h|
|
91
91
|
name = File.basename(fn)
|
92
92
|
opts = @env.merge(location: fn)
|
93
93
|
h[name] = Syntropy::App.new(opts[:machine], opts[:location], opts[:mount_path], opts)
|
94
|
-
h
|
95
94
|
}
|
96
|
-
->(req) {
|
97
|
-
site = sites[req.host]
|
98
|
-
site ? site.call(req) : req.respond(nil, ':status' => Status::BAD_REQUEST)
|
99
|
-
}
|
100
|
-
end
|
101
95
|
|
102
|
-
|
103
|
-
|
104
|
-
|
96
|
+
map&.each do |k, v|
|
97
|
+
sites[k] = sites[v]
|
98
|
+
end
|
99
|
+
|
100
|
+
lambda { |req|
|
101
|
+
site = sites[req.host]
|
102
|
+
site ? site.call(req) : req.respond(nil, ':status' => Status::BAD_REQUEST)
|
103
|
+
}
|
104
|
+
end
|
105
105
|
|
106
|
+
def page_list(ref)
|
107
|
+
full_path = File.join(@env[:location], ref)
|
108
|
+
raise 'Not a directory' if !File.directory?(full_path)
|
109
|
+
|
110
|
+
Dir[File.join(full_path, '*.md')].sort.map {
|
111
|
+
atts, markdown = Syntropy.parse_markdown_file(it, @env)
|
112
|
+
{ atts:, markdown: }
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
106
116
|
end
|
107
117
|
end
|
data/lib/syntropy/version.rb
CHANGED
data/lib/syntropy.rb
CHANGED
@@ -4,14 +4,15 @@ require 'qeweney'
|
|
4
4
|
require 'uringmachine'
|
5
5
|
require 'tp2'
|
6
6
|
|
7
|
-
require 'syntropy/
|
7
|
+
require 'syntropy/app'
|
8
8
|
require 'syntropy/connection_pool'
|
9
|
+
require 'syntropy/errors'
|
10
|
+
require 'syntropy/markdown'
|
9
11
|
require 'syntropy/module'
|
12
|
+
require 'syntropy/request_extensions'
|
13
|
+
require 'syntropy/router'
|
10
14
|
require 'syntropy/rpc_api'
|
11
15
|
require 'syntropy/side_run'
|
12
|
-
require 'syntropy/router'
|
13
|
-
require 'syntropy/app'
|
14
|
-
require 'syntropy/request_extensions'
|
15
16
|
|
16
17
|
module Syntropy
|
17
18
|
Status = Qeweney::Status
|
@@ -34,7 +35,7 @@ module Syntropy
|
|
34
35
|
CLEAR = "\e[0m"
|
35
36
|
YELLOW = "\e[33m"
|
36
37
|
|
37
|
-
BANNER =
|
38
|
+
BANNER =
|
38
39
|
"\n"\
|
39
40
|
" #{GREEN}\n"\
|
40
41
|
" #{GREEN} ooo\n"\
|
@@ -44,5 +45,4 @@ module Syntropy
|
|
44
45
|
" #{GREEN} #{YELLOW}|#{GREEN} vvv o #{CLEAR}https://github.com/noteflakes/syntropy\n"\
|
45
46
|
" #{GREEN} :#{YELLOW}|#{GREEN}:::#{YELLOW}|#{GREEN}::#{YELLOW}|#{GREEN}:\n"\
|
46
47
|
"#{YELLOW}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m\n\n"
|
47
|
-
)
|
48
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntropy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.8'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- lib/syntropy/connection_pool.rb
|
196
196
|
- lib/syntropy/errors.rb
|
197
197
|
- lib/syntropy/file_watch.rb
|
198
|
+
- lib/syntropy/markdown.rb
|
198
199
|
- lib/syntropy/module.rb
|
199
200
|
- lib/syntropy/request_extensions.rb
|
200
201
|
- lib/syntropy/router.rb
|