mr-edward 0.0.3 → 0.5.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 +4 -4
- data/bin/edward +1 -1
- data/{lib → src}/builder.rb +28 -7
- data/{lib → src}/cli.rb +4 -0
- data/src/context.rb +27 -0
- data/{lib → src}/page.rb +22 -4
- data/src/version.rb +4 -0
- metadata +9 -9
- data/lib/context.rb +0 -15
- data/lib/version.rb +0 -4
- /data/{lib → src}/edward.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7be307969fab3a27723edc33011ed4c014d156f30d5c4fdae7ef3835afcb32c4
|
|
4
|
+
data.tar.gz: 578b5c36886e86b9862a318397f9c7b33ab2db00769364c40e86cc12a7f5d061
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7cd05155e1c21850e379f6425f2995f0bc8932d54f89bd7dd48c34e9959ded031d1c154152a97a8e7020b4f34062ccad79b76bad4472039a7e8d8de95227db53
|
|
7
|
+
data.tar.gz: 41310aedffa6129e459d55b898f2ecbdd21c3afb50e57e34c8e2355140cd371b92d4d5bf8c63c6f6ada87f1dc6b0b6ff23d3482074d2621b6bfba26fc7aa45a8
|
data/bin/edward
CHANGED
data/{lib → src}/builder.rb
RENAMED
|
@@ -5,28 +5,36 @@ require "tilt"
|
|
|
5
5
|
module Edward
|
|
6
6
|
# Builds a website
|
|
7
7
|
class Builder
|
|
8
|
-
|
|
9
|
-
attr_reader :target
|
|
10
|
-
|
|
8
|
+
|
|
9
|
+
attr_reader :target, :pages
|
|
10
|
+
|
|
11
11
|
def initialize
|
|
12
12
|
@target = "_site"
|
|
13
13
|
@gitignore = File.read(".gitignore").lines rescue []
|
|
14
14
|
@edwardignore = File.read(".edwardignore").lines rescue []
|
|
15
|
+
Tilt.register_pipeline("adoc_erb", :templates => ["erb", "adoc"])
|
|
16
|
+
Tilt::AsciidoctorTemplate.include(AsciiDoctorUnsafeByDefault)
|
|
17
|
+
load("./_setup.rb") if File.exist? "_setup.rb"
|
|
15
18
|
end
|
|
16
|
-
|
|
19
|
+
|
|
17
20
|
def start
|
|
18
21
|
FileUtils.rm_r @target if File.exist? @target
|
|
19
22
|
FileUtils.mkdir_p @target
|
|
20
23
|
|
|
24
|
+
@pages = []
|
|
25
|
+
|
|
21
26
|
Dir.glob("**/*") do |path|
|
|
22
27
|
visit_file path if visit_file?(path)
|
|
23
28
|
end
|
|
29
|
+
|
|
30
|
+
write_pages
|
|
31
|
+
|
|
24
32
|
end
|
|
25
33
|
|
|
26
34
|
def visit_file? path
|
|
27
35
|
File.file?(path) &&
|
|
28
36
|
!path.start_with?("_") &&
|
|
29
|
-
!["Gemfile", "Gemfile.lock"].include?(path) &&
|
|
37
|
+
!["Gemfile", "Gemfile.lock", "Rakefile"].include?(path) &&
|
|
30
38
|
!@gitignore.include?(path) &&
|
|
31
39
|
!@edwardignore.include?(path)
|
|
32
40
|
end
|
|
@@ -34,14 +42,20 @@ module Edward
|
|
|
34
42
|
def visit_file path
|
|
35
43
|
if Page.page?(path)
|
|
36
44
|
page = Edward::Page.new(path)
|
|
37
|
-
|
|
45
|
+
@pages << page
|
|
38
46
|
FileUtils.mkdir_p "#{@target}/#{page.dirname}"
|
|
39
|
-
File.write("#{@target}/#{page.new_path}", page.render)
|
|
40
47
|
else
|
|
41
48
|
copy_plain path
|
|
42
49
|
end
|
|
43
50
|
end
|
|
44
51
|
|
|
52
|
+
def write_pages
|
|
53
|
+
for page in @pages
|
|
54
|
+
puts "converting #{page.path} => #{page.dirname}/#{page.new_name}"
|
|
55
|
+
File.write("#{@target}/#{page.new_path}", page.render(self))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
45
59
|
# simply copy the file
|
|
46
60
|
def copy_plain path
|
|
47
61
|
FileUtils.mkdir_p "#{@target}/#{File.dirname path}"
|
|
@@ -50,3 +64,10 @@ module Edward
|
|
|
50
64
|
|
|
51
65
|
end
|
|
52
66
|
end
|
|
67
|
+
|
|
68
|
+
module AsciiDoctorUnsafeByDefault
|
|
69
|
+
def prepare
|
|
70
|
+
@options[:safe] = :unsafe if @options[:safe].nil?
|
|
71
|
+
super
|
|
72
|
+
end
|
|
73
|
+
end
|
data/{lib → src}/cli.rb
RENAMED
|
@@ -22,6 +22,7 @@ module Edward
|
|
|
22
22
|
@server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => @builder.target
|
|
23
23
|
trap("INT") { @server.shutdown }
|
|
24
24
|
listen
|
|
25
|
+
@builder.start
|
|
25
26
|
puts "visit edward at http://127.0.0.1:#{@server.config[:Port]}"
|
|
26
27
|
@server.start
|
|
27
28
|
end
|
|
@@ -30,6 +31,9 @@ module Edward
|
|
|
30
31
|
require "listen"
|
|
31
32
|
Listen.to('.', ignore: /_site/) { |modified, added, removed|
|
|
32
33
|
puts "rebuilding"
|
|
34
|
+
if [modified, added, removed].flatten.map(&File.method(:basename)).include? "_setup.rb"
|
|
35
|
+
puts "WARNING: restart to apply changes to _setup.rb"
|
|
36
|
+
end
|
|
33
37
|
@builder.start
|
|
34
38
|
}.start
|
|
35
39
|
end
|
data/src/context.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Edward
|
|
2
|
+
# Context for a template to run in.
|
|
3
|
+
# It has a reference to its page and the builder.
|
|
4
|
+
class RenderContext
|
|
5
|
+
def initialize page, builder
|
|
6
|
+
@page = page
|
|
7
|
+
@pages = builder.pages
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def pages_with_tag tag
|
|
11
|
+
@pages.filter { it.tag? tag }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Include a partial file.
|
|
15
|
+
# The file is searched for in _include,
|
|
16
|
+
# rendered and returned.
|
|
17
|
+
#
|
|
18
|
+
# If you need to include a file plainly consider
|
|
19
|
+
# just using File.read or use an ERB template.
|
|
20
|
+
def include file, locals = {}, &block
|
|
21
|
+
include_path = "_include/" + file
|
|
22
|
+
yaml, content = Page.extract_front_matter(File.read(include_path))
|
|
23
|
+
options = (yaml&.dig(:options) || {}).merge(fixed_locals: "(local:)")
|
|
24
|
+
Tilt[include_path].new(options) { content }.render(self, { local: locals }, &block)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/{lib → src}/page.rb
RENAMED
|
@@ -13,17 +13,24 @@ module Edward
|
|
|
13
13
|
content = File.read(path)
|
|
14
14
|
@yaml, @content = Page.extract_front_matter(content)
|
|
15
15
|
@block = nil
|
|
16
|
+
transform_option_keys(self[:options])
|
|
16
17
|
@template = Tilt[path].new(self[:options]) { @content }
|
|
17
18
|
add_layout(self[:layout]) if self[:layout]
|
|
18
19
|
end
|
|
19
20
|
|
|
21
|
+
# transform extensions from options to strings (for use in pipeline)
|
|
22
|
+
def transform_option_keys options
|
|
23
|
+
options&.transform_keys! { |k| Tilt.default_mapping.registered?(k.to_s) ? k.to_s : k }
|
|
24
|
+
end
|
|
25
|
+
|
|
20
26
|
# check if a file starts with yaml doc and can be mapped by tilt
|
|
21
27
|
def self.page? path
|
|
22
28
|
!Tilt.templates_for(path).empty? && YAML_FRONT_MATTER_REGEXP.match(File.read(path))
|
|
23
29
|
end
|
|
24
30
|
|
|
25
|
-
def render
|
|
26
|
-
|
|
31
|
+
def render builder
|
|
32
|
+
ctx = Edward::RenderContext.new(self, builder)
|
|
33
|
+
@template.render(ctx, nil, &proc { @block.call(ctx) })
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
def self.extract_front_matter content
|
|
@@ -38,12 +45,13 @@ module Edward
|
|
|
38
45
|
|
|
39
46
|
# wrap this page in a layout
|
|
40
47
|
def add_layout name
|
|
41
|
-
layout_path = "_layouts/#{name}
|
|
48
|
+
layout_path = "_layouts/#{name}"
|
|
42
49
|
yaml, content = Page.extract_front_matter(File.read(layout_path))
|
|
43
50
|
@yaml = yaml.deep_merge!(@yaml, knockout_prefix: "--") if yaml
|
|
51
|
+
transform_option_keys(self[:options])
|
|
44
52
|
inner_template = @template
|
|
45
53
|
inner_block = @block
|
|
46
|
-
@block = proc { inner_template.render(
|
|
54
|
+
@block = proc { |ctx| inner_template.render(ctx, nil, &inner_block) }
|
|
47
55
|
@template = Tilt[layout_path].new(self[:options]) { content }
|
|
48
56
|
end
|
|
49
57
|
|
|
@@ -64,6 +72,16 @@ module Edward
|
|
|
64
72
|
"#{dirname}/#{new_name}"
|
|
65
73
|
end
|
|
66
74
|
|
|
75
|
+
# The directory name if new_name is index.html.
|
|
76
|
+
# Otherwise the full new path.
|
|
77
|
+
def href
|
|
78
|
+
if new_name == "index.html"
|
|
79
|
+
dirname
|
|
80
|
+
else
|
|
81
|
+
"#{dirname}/#{new_name}"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
67
85
|
def tag? tag
|
|
68
86
|
@yaml&.dig(:tags)&.include? tag
|
|
69
87
|
end
|
data/src/version.rb
ADDED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mr-edward
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rein Fernhout
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '2.
|
|
18
|
+
version: '2.7'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '2.
|
|
25
|
+
version: '2.7'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: webrick
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -71,12 +71,12 @@ extensions: []
|
|
|
71
71
|
extra_rdoc_files: []
|
|
72
72
|
files:
|
|
73
73
|
- bin/edward
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
78
|
-
-
|
|
79
|
-
-
|
|
74
|
+
- src/builder.rb
|
|
75
|
+
- src/cli.rb
|
|
76
|
+
- src/context.rb
|
|
77
|
+
- src/edward.rb
|
|
78
|
+
- src/page.rb
|
|
79
|
+
- src/version.rb
|
|
80
80
|
homepage: https://github.com/LevitatingBusinessMan/edward
|
|
81
81
|
licenses:
|
|
82
82
|
- MIT
|
data/lib/context.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module Edward
|
|
2
|
-
# Context for a template to run in
|
|
3
|
-
class RenderContext
|
|
4
|
-
def initialize page
|
|
5
|
-
@page = page
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def include file, locals = {}, &block
|
|
9
|
-
include_path = "_include/" + file
|
|
10
|
-
# yaml in includes is currently ignored
|
|
11
|
-
_yaml, content = Page.extract_front_matter(File.read(include_path))
|
|
12
|
-
Tilt[include_path].new(@page[:options]&.merge(fixed_locals: "(locals:)")){ content }.render(self, { local: locals }, &block)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
data/lib/version.rb
DELETED
/data/{lib → src}/edward.rb
RENAMED
|
File without changes
|