isola 0.1.2 → 0.1.3
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/lib/isola/context.rb +5 -5
- data/lib/isola/file_handler.rb +5 -4
- data/lib/isola/site.rb +67 -18
- data/lib/isola/source.rb +3 -12
- data/lib/isola/static_file.rb +8 -0
- data/lib/isola/version.rb +1 -1
- data/lib/isola.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bb22047ab87f7c563e5970881ccb38fc9efd2a2f6330dacdb6d59f7d8b45692
|
|
4
|
+
data.tar.gz: 361457eac4fe0368b586258f36b02a9a7748e64be5f31f6cc83acb4ed7bf6ee1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4bc2dada021f9fddda63594d32fccbe2d9d25040340344632c1efedf9319fd13113049b95e04f29d1c1f81dee39489bbd2ea4221119af2e7f28414cb4d724a0
|
|
7
|
+
data.tar.gz: b19a681a05704dd1223e6914cdede398229e6f4b6e727169557a19ecea77f49aff0e7ea59f12718a7954e8013ec02410eb5ad8dbea0b59d5bad30d8879aef6ce
|
data/lib/isola/context.rb
CHANGED
|
@@ -3,9 +3,9 @@ require "tilt"
|
|
|
3
3
|
module Isola
|
|
4
4
|
class Context
|
|
5
5
|
attr_reader :site, :content, :layout
|
|
6
|
-
def initialize(
|
|
7
|
-
@
|
|
8
|
-
@meta = {lang: site[:lang]}.merge(
|
|
6
|
+
def initialize(source, site)
|
|
7
|
+
@source = source
|
|
8
|
+
@meta = {lang: site[:lang]}.merge(source.meta).freeze
|
|
9
9
|
@site = site
|
|
10
10
|
@content = ""
|
|
11
11
|
@layout = {}
|
|
@@ -22,8 +22,8 @@ module Isola
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def render
|
|
25
|
-
@current = @
|
|
26
|
-
@content, path = @
|
|
25
|
+
@current = @source
|
|
26
|
+
@content, path = @source.render(self, @site)
|
|
27
27
|
while @current.meta[:layout]
|
|
28
28
|
layout = site.layout(@current.meta[:layout])
|
|
29
29
|
raise "#{@current.meta[:layout]} not found for #{@current.filepath}" unless layout
|
data/lib/isola/file_handler.rb
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
module Isola
|
|
2
2
|
class FileHandler
|
|
3
|
-
attr_reader :
|
|
3
|
+
attr_reader :entries, :layouts, :includes, :root_dir
|
|
4
4
|
DEFAULT_EXCLUDES = [
|
|
5
5
|
".sass-cache", "gemfiles",
|
|
6
6
|
"Gemfile", "Gemfile.lock", "node_modules",
|
|
7
7
|
"vendor/bundle/", "vendor/cache/",
|
|
8
8
|
"vendor/gems/", "vendor/ruby/"
|
|
9
9
|
]
|
|
10
|
-
def initialize(root_dir, excludes: [])
|
|
10
|
+
def initialize(root_dir, output_path_func: nil, excludes: [])
|
|
11
11
|
@excludes = DEFAULT_EXCLUDES.union(excludes)
|
|
12
12
|
@rejects = Regexp.union(%r{(?:^|/)[._]}, %r{~$})
|
|
13
13
|
@root_dir = File.absolute_path(root_dir)
|
|
14
|
-
@
|
|
14
|
+
@entries = {}
|
|
15
15
|
@layouts = {}
|
|
16
16
|
@includes = {}
|
|
17
|
+
@output_path_func = output_path_func || method(:remove_exts)
|
|
17
18
|
collect(@root_dir)
|
|
18
19
|
end
|
|
19
20
|
|
|
@@ -36,7 +37,7 @@ module Isola
|
|
|
36
37
|
elsif path.start_with?("_includes/")
|
|
37
38
|
@includes[remove_exts(path).delete_prefix("_includes/")] = path
|
|
38
39
|
else
|
|
39
|
-
@
|
|
40
|
+
@entries[@output_path_func.call(path)] = path
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
end
|
data/lib/isola/site.rb
CHANGED
|
@@ -9,8 +9,8 @@ module Isola
|
|
|
9
9
|
default_language: "en",
|
|
10
10
|
host: "127.0.0.1",
|
|
11
11
|
port: 4444}.freeze
|
|
12
|
-
SUPPORTED_TILT_EXT = [".erb", ".md", ".markdown", ".mkd"]
|
|
13
|
-
EXT_MAP = {".md" => ".html", ".mkd" => ".html", ".markdown" => ".html", "" => ".html"}
|
|
12
|
+
SUPPORTED_TILT_EXT = [".erb", ".md", ".markdown", ".mkd", ".html"]
|
|
13
|
+
EXT_MAP = {".md" => ".html", ".mkd" => ".html", ".markdown" => ".html", ".html" => ".html", "" => ".html"}
|
|
14
14
|
def initialize(config)
|
|
15
15
|
@config = DEFAULT_CONFIG.merge(YAML.safe_load(config, symbolize_names: true) || {})
|
|
16
16
|
@config[:root_dir] ||= Dir.pwd
|
|
@@ -25,24 +25,30 @@ module Isola
|
|
|
25
25
|
@config[key]
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def
|
|
28
|
+
def ext_to_process_with_tilt? ext
|
|
29
29
|
SUPPORTED_TILT_EXT.include? ext
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def
|
|
33
|
-
|
|
32
|
+
def process_extensions(path)
|
|
33
|
+
path = path.dup
|
|
34
|
+
last_ext = nil
|
|
35
|
+
while ext_to_process_with_tilt?(ext = File.extname(path))
|
|
36
|
+
yield(path, ext) if block_given?
|
|
37
|
+
path.delete_suffix!(ext)
|
|
38
|
+
last_ext = ext
|
|
39
|
+
end
|
|
40
|
+
ext.empty? ? path + result_ext_for(last_ext) : path
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def output_path_for path
|
|
44
|
+
process_extensions path
|
|
34
45
|
end
|
|
35
46
|
|
|
36
47
|
def build
|
|
37
|
-
dest_dir = File.join(@file_handler.root_dir, @config[:destination])
|
|
38
48
|
FileUtils.rm_rf(dest_dir)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
rendered, path = Context.new(page, self).render
|
|
43
|
-
dest_path = File.join(dest_dir, path)
|
|
44
|
-
FileUtils.mkdir_p(File.dirname(dest_path))
|
|
45
|
-
File.write(dest_path, rendered)
|
|
49
|
+
entries.each do |name, entry|
|
|
50
|
+
puts "building #{name}..."
|
|
51
|
+
render_to_dest entry
|
|
46
52
|
end
|
|
47
53
|
puts "done."
|
|
48
54
|
end
|
|
@@ -57,27 +63,70 @@ module Isola
|
|
|
57
63
|
end
|
|
58
64
|
|
|
59
65
|
def layout name
|
|
60
|
-
|
|
66
|
+
find_entry(name, @parsed_layouts, @file_handler.layouts)
|
|
61
67
|
end
|
|
62
68
|
|
|
63
69
|
def include name
|
|
64
|
-
|
|
70
|
+
find_entry(name, @parsed_includes, @file_handler.includes)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def entry name
|
|
74
|
+
find_entry(name, @parsed_entries, @file_handler.entries)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def entries
|
|
78
|
+
Enumerator.new do |yielder|
|
|
79
|
+
@file_handler.entries.each_key do |name|
|
|
80
|
+
yielder.yield name, entry(name)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
65
83
|
end
|
|
66
84
|
|
|
67
85
|
private
|
|
68
86
|
|
|
87
|
+
def dest_dir
|
|
88
|
+
File.join(@file_handler.root_dir, @config[:destination])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def render_to_dest entry
|
|
92
|
+
if entry.instance_of? Source
|
|
93
|
+
rendered, path = Context.new(entry, self).render
|
|
94
|
+
dest_path = File.join(dest_dir, path)
|
|
95
|
+
FileUtils.mkdir_p(File.dirname(dest_path))
|
|
96
|
+
File.write(dest_path, rendered)
|
|
97
|
+
elsif entry.instance_of? StaticFile
|
|
98
|
+
path = entry.path
|
|
99
|
+
src_path = File.join(config[:root_dir], path)
|
|
100
|
+
dest_path = File.join(dest_dir, path)
|
|
101
|
+
FileUtils.mkdir_p(File.dirname(dest_path))
|
|
102
|
+
FileUtils.copy(src_path, dest_path)
|
|
103
|
+
else
|
|
104
|
+
raise "can't render class #{entry.class}"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def result_ext_for ext
|
|
109
|
+
return "" if ext.nil?
|
|
110
|
+
EXT_MAP[ext]
|
|
111
|
+
end
|
|
112
|
+
|
|
69
113
|
def collect_files
|
|
70
|
-
@file_handler = FileHandler.new(config[:root_dir], excludes: @config[:excludes])
|
|
114
|
+
@file_handler = FileHandler.new(config[:root_dir], output_path_func: method(:output_path_for), excludes: @config[:excludes])
|
|
71
115
|
@parsed_layouts = {}
|
|
72
116
|
@parsed_includes = {}
|
|
117
|
+
@parsed_entries = {}
|
|
73
118
|
end
|
|
74
119
|
|
|
75
|
-
def
|
|
120
|
+
def find_entry(name, cache, store)
|
|
76
121
|
cache[name] ||=
|
|
77
122
|
begin
|
|
78
123
|
p = store[name]
|
|
79
124
|
return nil unless p
|
|
80
|
-
|
|
125
|
+
if ext_to_process_with_tilt?(File.extname(p))
|
|
126
|
+
Source.new(p, read_in_site(p))
|
|
127
|
+
else
|
|
128
|
+
StaticFile.new(p)
|
|
129
|
+
end
|
|
81
130
|
end
|
|
82
131
|
end
|
|
83
132
|
|
data/lib/isola/source.rb
CHANGED
|
@@ -17,20 +17,11 @@ module Isola
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def render(context, site, params = {})
|
|
20
|
-
path = @filepath.dup
|
|
21
20
|
rendered = @content.dup
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
rendered = Tilt.new(path) { rendered }.render(context, params)
|
|
25
|
-
path.delete_suffix! ext
|
|
26
|
-
last_ext = ext
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
if ext.empty?
|
|
30
|
-
[rendered, path + site.result_ext_for(last_ext)]
|
|
31
|
-
else
|
|
32
|
-
[rendered, path]
|
|
21
|
+
output_path = site.process_extensions(@filepath) do |current_path, _ext|
|
|
22
|
+
rendered = Tilt.new(current_path) { rendered }.render(context, params)
|
|
33
23
|
end
|
|
24
|
+
[rendered, output_path]
|
|
34
25
|
end
|
|
35
26
|
end
|
|
36
27
|
end
|
data/lib/isola/version.rb
CHANGED
data/lib/isola.rb
CHANGED
|
@@ -4,6 +4,7 @@ require_relative "isola/version"
|
|
|
4
4
|
require_relative "isola/site"
|
|
5
5
|
require_relative "isola/file_handler"
|
|
6
6
|
require_relative "isola/source"
|
|
7
|
+
require_relative "isola/static_file"
|
|
7
8
|
require_relative "isola/context"
|
|
8
9
|
require_relative "isola/watcher"
|
|
9
10
|
require_relative "isola/dev_server"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: isola
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Satoshi Kojima
|
|
@@ -99,6 +99,7 @@ files:
|
|
|
99
99
|
- lib/isola/file_handler.rb
|
|
100
100
|
- lib/isola/site.rb
|
|
101
101
|
- lib/isola/source.rb
|
|
102
|
+
- lib/isola/static_file.rb
|
|
102
103
|
- lib/isola/version.rb
|
|
103
104
|
- lib/isola/watcher.rb
|
|
104
105
|
homepage: https://github.com/skoji/isola
|
|
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
121
|
- !ruby/object:Gem::Version
|
|
121
122
|
version: '0'
|
|
122
123
|
requirements: []
|
|
123
|
-
rubygems_version: 4.0.
|
|
124
|
+
rubygems_version: 4.0.6
|
|
124
125
|
specification_version: 4
|
|
125
126
|
summary: very simple static site generator using ERB
|
|
126
127
|
test_files: []
|