isola 0.1.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/Rakefile +10 -0
- data/exe/isola +23 -0
- data/lib/isola/context.rb +36 -0
- data/lib/isola/file_handler.rb +70 -0
- data/lib/isola/site.rb +79 -0
- data/lib/isola/source.rb +32 -0
- data/lib/isola/version.rb +5 -0
- data/lib/isola.rb +11 -0
- data/sig/isola.rbs +3 -0
- metadata +95 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d66e9eb2d33f8ab15d77fc1d71ed2c962d977b004c3eb340cd09c932a513a65e
|
|
4
|
+
data.tar.gz: b6d134d39802939a0728b9ab59300968286da39f36b9eb13e79ebac380192efd
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ebeba2d27bb183e2a1ebe19b1dc899d3686bfb918d5d9cbebb6fa5cd1354c81ba85dfa950051fe192cfec00c7c132712b765b566385312dad15be79cf7f333cb
|
|
7
|
+
data.tar.gz: 568589f57d81020434011aa145c01c33452bb04b4f8fee604b0b9e5a89447ba4dc3172168746afb5827f77e526961dbbf559e70db883d45a945e0c5a2f888b8a
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Satoshi Kojima
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# isola
|
|
2
|
+
|
|
3
|
+
Super simple static site generator using erb.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bundle add isola
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
gem install isola
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
1. place markdown files in your directory
|
|
20
|
+
2. `isola build`
|
|
21
|
+
|
|
22
|
+
## Development Policy
|
|
23
|
+
|
|
24
|
+
This project does not use Agentic Coding at all. AI assistance in code reviews is not avoided.
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
See [LICENSE](LICENSE)
|
data/Rakefile
ADDED
data/exe/isola
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "isola"
|
|
5
|
+
require "thor"
|
|
6
|
+
|
|
7
|
+
class IsolaCLI < Thor
|
|
8
|
+
package_name "Isola"
|
|
9
|
+
desc "build site", "build site on current directory"
|
|
10
|
+
def build
|
|
11
|
+
config =
|
|
12
|
+
if File.exist? "_config.yaml"
|
|
13
|
+
File.read("_config.yaml")
|
|
14
|
+
else
|
|
15
|
+
""
|
|
16
|
+
end
|
|
17
|
+
site = Isola::Site.new(config)
|
|
18
|
+
site.collect_files
|
|
19
|
+
site.process
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
IsolaCLI.start(ARGV)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "tilt"
|
|
2
|
+
|
|
3
|
+
module Isola
|
|
4
|
+
class Context
|
|
5
|
+
attr_reader :site, :content, :layout
|
|
6
|
+
def initialize(page, site)
|
|
7
|
+
@page_source = page
|
|
8
|
+
@page_meta = Data.define(*page.meta.keys).new(**page.meta)
|
|
9
|
+
@site = site
|
|
10
|
+
@content = ""
|
|
11
|
+
@layout = {}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def page
|
|
15
|
+
@page_meta
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def include name, params = {}
|
|
19
|
+
i = @site.include name
|
|
20
|
+
raise "include #{name} not found in #{@current.filepath}" unless i
|
|
21
|
+
i.render(self, @site, params)[0]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def render
|
|
25
|
+
@current = @page_source
|
|
26
|
+
@content, path = @page_source.render(self, @site)
|
|
27
|
+
while @current.meta[:layout]
|
|
28
|
+
layout = site.layout(@current.meta[:layout])
|
|
29
|
+
raise "#{@current.meta[:layout]} not found for #{@current.filepath}" unless layout
|
|
30
|
+
@current = layout
|
|
31
|
+
@content, _ = @current.render(self, @site)
|
|
32
|
+
end
|
|
33
|
+
[@content, path]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Isola
|
|
2
|
+
class FileHandler
|
|
3
|
+
attr_reader :pages, :layouts, :includes, :root_dir
|
|
4
|
+
DEFAULT_EXCLUDES = [
|
|
5
|
+
".sass-cache", "gemfiles",
|
|
6
|
+
"Gemfile", "Gemfile.lock", "node_modules",
|
|
7
|
+
"vendor/bundle/", "vendor/cache/",
|
|
8
|
+
"vendor/gems/", "vendor/ruby/"
|
|
9
|
+
]
|
|
10
|
+
def initialize(root_dir, excludes: [])
|
|
11
|
+
@excludes = DEFAULT_EXCLUDES.union(excludes)
|
|
12
|
+
@rejects = Regexp.union(%r{(?:^|/)[._]}, %r{~$})
|
|
13
|
+
@root_dir = File.absolute_path(root_dir)
|
|
14
|
+
@pages = {}
|
|
15
|
+
@layouts = {}
|
|
16
|
+
@includes = {}
|
|
17
|
+
collect(@root_dir)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def collect dir
|
|
23
|
+
Dir.each_child(dir) do |entry|
|
|
24
|
+
absolute_path = File.absolute_path(File.join(dir, entry))
|
|
25
|
+
path = absolute_path.delete_prefix("#{@root_dir}/")
|
|
26
|
+
path += "/" if File.directory? absolute_path
|
|
27
|
+
if process_path? path
|
|
28
|
+
if File.directory? absolute_path
|
|
29
|
+
collect(absolute_path)
|
|
30
|
+
elsif path.start_with?("_layouts/")
|
|
31
|
+
@layouts[remove_exts(path).delete_prefix("_layouts/")] = path
|
|
32
|
+
elsif path.start_with?("_includes/")
|
|
33
|
+
@includes[remove_exts(path).delete_prefix("_includes/")] = path
|
|
34
|
+
else
|
|
35
|
+
@pages[remove_exts(path)] = path
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def process_path? path
|
|
42
|
+
p =
|
|
43
|
+
if /^(_includes|_layouts)\//.match?(path)
|
|
44
|
+
path.sub(/^(_includes|_layouts)\//, "")
|
|
45
|
+
else
|
|
46
|
+
path
|
|
47
|
+
end
|
|
48
|
+
!@rejects.match?(p) &&
|
|
49
|
+
!excluded?(path)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def excluded? relative_path
|
|
53
|
+
is_directory = File.directory?(File.join(@root_dir, relative_path))
|
|
54
|
+
@excludes.any? do |exclude|
|
|
55
|
+
case exclude
|
|
56
|
+
when String
|
|
57
|
+
File.fnmatch?(exclude, relative_path) ||
|
|
58
|
+
relative_path.start_with?(exclude) ||
|
|
59
|
+
(exclude == "#{relative_path}/" if is_directory)
|
|
60
|
+
when Regexp
|
|
61
|
+
exclude.match?(relative_path)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def remove_exts(filepath)
|
|
67
|
+
filepath.sub(%r{\.[^/]*\z}, "")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
data/lib/isola/site.rb
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
require "fileutils"
|
|
3
|
+
module Isola
|
|
4
|
+
class Site
|
|
5
|
+
attr_accessor :config
|
|
6
|
+
DEFAULT_CONFIG = {url: "http://example.com", title: "my awesome site", destination: "_site", default_language: "en"}.freeze
|
|
7
|
+
SUPPORTED_TILT_EXT = [".erb", ".md", ".markdown", ".mkd"]
|
|
8
|
+
EXT_MAP = {".md" => ".html", ".mkd" => ".html", ".markdown" => ".html", "" => ".html"}
|
|
9
|
+
def initialize(config)
|
|
10
|
+
@config = DEFAULT_CONFIG.merge(YAML.safe_load(config, symbolize_names: true) || {})
|
|
11
|
+
@config[:root_dir] ||= Dir.pwd
|
|
12
|
+
@config[:excludes] ||= []
|
|
13
|
+
@parsed_layouts = {}
|
|
14
|
+
@parsed_includes = {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def title
|
|
18
|
+
@config[:title]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def url
|
|
22
|
+
@config[:url]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def lang
|
|
26
|
+
@config[:default_language]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def root_dir
|
|
30
|
+
@config[:root_dir]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def supported_ext? ext
|
|
34
|
+
SUPPORTED_TILT_EXT.include? ext
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def result_ext_for ext
|
|
38
|
+
EXT_MAP[ext]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def collect_files
|
|
42
|
+
@file_handler = FileHandler.new(root_dir, excludes: @config[:excludes])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def process
|
|
46
|
+
@file_handler.pages.each do |name, path|
|
|
47
|
+
page = Source.new(path, read_in_site(path))
|
|
48
|
+
puts "processing #{path}..."
|
|
49
|
+
rendered, path = Context.new(page, self).render
|
|
50
|
+
dest_path = File.join(@file_handler.root_dir, @config[:destination], path)
|
|
51
|
+
FileUtils.mkdir_p(File.dirname(dest_path))
|
|
52
|
+
File.write(dest_path, rendered)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def layout name
|
|
57
|
+
find_source(name, @parsed_layouts, @file_handler.layouts)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def include name
|
|
61
|
+
find_source(name, @parsed_includes, @file_handler.includes)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def find_source(name, cache, store)
|
|
67
|
+
cache[name] ||=
|
|
68
|
+
begin
|
|
69
|
+
p = store[name]
|
|
70
|
+
return nil unless p
|
|
71
|
+
Source.new(p, read_in_site(p))
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def read_in_site(p)
|
|
76
|
+
File.read(File.join(root_dir, p))
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/lib/isola/source.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
3
|
+
module Isola
|
|
4
|
+
class Source
|
|
5
|
+
attr_reader :filepath, :meta, :content
|
|
6
|
+
def initialize filepath, text
|
|
7
|
+
@filepath = filepath
|
|
8
|
+
@meta, @content = if (m = text.match(/\A---\s*\n(.+?)^---\s*\n(.*)\z/m))
|
|
9
|
+
[YAML.safe_load(m[1], symbolize_names: true), m[2]]
|
|
10
|
+
else
|
|
11
|
+
[{}, text]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def render(context, site, params = {})
|
|
16
|
+
path = @filepath.dup
|
|
17
|
+
rendered = @content.dup
|
|
18
|
+
last_ext = ""
|
|
19
|
+
while !(ext = File.extname(path)).empty? && site.supported_ext?(ext)
|
|
20
|
+
rendered = Tilt.new(path) { rendered }.render(context, params)
|
|
21
|
+
path.delete_suffix! ext
|
|
22
|
+
last_ext = ext
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if ext.empty?
|
|
26
|
+
[rendered, path + site.result_ext_for(last_ext)]
|
|
27
|
+
else
|
|
28
|
+
[rendered, path]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/isola.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "isola/version"
|
|
4
|
+
require_relative "isola/site"
|
|
5
|
+
require_relative "isola/file_handler"
|
|
6
|
+
require_relative "isola/source"
|
|
7
|
+
require_relative "isola/context"
|
|
8
|
+
|
|
9
|
+
module Isola
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
end
|
data/sig/isola.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: isola
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Satoshi Kojima
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: tilt
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.7'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.7'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: kramdown
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2.5'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.5'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: thor
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.5'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.5'
|
|
54
|
+
description: ''
|
|
55
|
+
email:
|
|
56
|
+
- skoji@skoji.jp
|
|
57
|
+
executables:
|
|
58
|
+
- isola
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- LICENSE
|
|
63
|
+
- README.md
|
|
64
|
+
- Rakefile
|
|
65
|
+
- exe/isola
|
|
66
|
+
- lib/isola.rb
|
|
67
|
+
- lib/isola/context.rb
|
|
68
|
+
- lib/isola/file_handler.rb
|
|
69
|
+
- lib/isola/site.rb
|
|
70
|
+
- lib/isola/source.rb
|
|
71
|
+
- lib/isola/version.rb
|
|
72
|
+
- sig/isola.rbs
|
|
73
|
+
homepage: https://github.com/skoji/isola
|
|
74
|
+
licenses: []
|
|
75
|
+
metadata:
|
|
76
|
+
homepage_uri: https://github.com/skoji/isola
|
|
77
|
+
source_code_uri: https://github.com/skoji/isola
|
|
78
|
+
rdoc_options: []
|
|
79
|
+
require_paths:
|
|
80
|
+
- lib
|
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: 4.0.0
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
requirements: []
|
|
92
|
+
rubygems_version: 4.0.3
|
|
93
|
+
specification_version: 4
|
|
94
|
+
summary: very simple static site generator using ERB
|
|
95
|
+
test_files: []
|