yass 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d92f535716945017dd1fc1871e65902172c2ca4b4fa40836bb802767e7be8c77
4
- data.tar.gz: 3123fbeb9e5b3ff90e51c0f3900e6634b656d95a3040239dcdf888901b6a2ab6
3
+ metadata.gz: 664e04a8abbd128da8902e65d83a0ed305010982f18e30d24c08571ee70cd9d0
4
+ data.tar.gz: 3c1f2151246b638cdc23bb340abef6ae3136adc677fa4abd1f0a3e374fcfbd78
5
5
  SHA512:
6
- metadata.gz: 19e3c50da3cc3a30894e8fe954a4de5aaf1b215d8991d05ffb4df0a120a1530b5d5db21de69e16cd5febb6cdf2eeae6750813f7313fc305e6781e95d37881919
7
- data.tar.gz: 57d632fb56ff222d1e9629c4df77e2f27749680d161992092ea8266f80d554aaca62254e5bc47bd230c7930cdf458cdc3b3b3bce2dbce8fa3f9fd3ff0fb130fc
6
+ metadata.gz: 07c5522d3aa8e206d3fb49681378ec00e41b7009583ab245d905658927111a8f09f424a4915564967ee9a93bab225ed0ef78100b695bb23c7432b053d4117a3e
7
+ data.tar.gz: 0ba17529c477f1755e9e11a2976c44bd2155e8639ed205062b4a78e0057c30efe82f254f1af29efe9d5a546826953712653f641c35c2d84ba590055304b21860
@@ -33,7 +33,7 @@ module Yass
33
33
  def self.option_parser(config)
34
34
  OptionParser.new { |opts|
35
35
  opts.banner = %(
36
- Yet Another Static Site (generator)
36
+ Yet Another Static Site (generator) v#{VERSION}
37
37
 
38
38
  yass <command> [options] [path/to/dir]
39
39
 
@@ -50,8 +50,9 @@ yass <command> [options] [path/to/dir]
50
50
 
51
51
  Options:
52
52
  ).strip
53
- opts.on("--local", "Build in local mode (with links to /index.html's)") { |l| config.local = true }
54
- opts.on("--debug", "Print stack traces") { |l| config.debug = true }
53
+ opts.on("--clean", "Remove unknown files from dist/ when bulding") { config.clean = true }
54
+ opts.on("--local", "Build in local mode (with links to /index.html's)") { config.local = true }
55
+ opts.on("--debug", "Print stack traces") { config.debug = true }
55
56
  opts.on("-h", "--help", "Prints this help") { config.stdout.puts opts; exit }
56
57
  }
57
58
  end
@@ -63,6 +64,7 @@ yass <command> [options] [path/to/dir]
63
64
  layouts: "layouts",
64
65
  templates: "templates",
65
66
  dest: "dist",
67
+ clean: false,
66
68
  local: false,
67
69
  stdin: $stdin,
68
70
  stdout: $stdout,
data/lib/yass/config.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Yass
2
- Config = Struct.new(:root, :src, :dest, :layouts, :templates, :local, :stdin, :stdout, :stderr, :debug, keyword_init: true) do
2
+ Config = Struct.new(:root, :src, :dest, :layouts, :templates, :clean, :local, :stdin, :stdout, :stderr, :debug, keyword_init: true) do
3
3
  def src_dir = root.join src
4
4
  def dest_dir = root.join dest
5
5
  def template_dir = root.join templates
@@ -19,6 +19,7 @@ module Yass
19
19
  FileUtils.cp(source.path, outfile)
20
20
  end
21
21
  end
22
+ clean if config.clean
22
23
  end
23
24
 
24
25
  private
@@ -36,10 +37,16 @@ module Yass
36
37
  return outfile, content if source.layout.nil?
37
38
 
38
39
  page = source.layout.render(source) { content }
39
- return outfile.dirname.join(source.rendered_filename), page
40
+ return outfile.dirname.join(source.dest_path.basename), page
40
41
  end
41
42
  end
42
43
 
44
+ def clean
45
+ expected_files = config.sources.map { |s| config.dest_dir.join(s.dest_path).to_s }
46
+ actual_files = Dir[config.dest_dir.join("**/*")].reject { |p| Dir.exist? p }
47
+ (actual_files - expected_files).each { |f| FileUtils.rm f }
48
+ end
49
+
43
50
  def dest_dirs
44
51
  config.sources.map { |s| config.dest_dir.join(s.relative_path).dirname }.uniq
45
52
  end
@@ -29,11 +29,11 @@ module Yass
29
29
  {
30
30
  "title" => source.title,
31
31
  "url" => source.url.to_s,
32
- "path" => source.relative_path.dirname.join(source.rendered_filename).to_s,
32
+ "path" => source.dest_path.to_s,
33
33
  "src_path" => source.relative_path.to_s,
34
34
  "dirname" => source.relative_path.dirname.to_s,
35
- "filename" => source.rendered_filename,
36
- "extname" => source.rendered_filename[/\.[^.]+$/],
35
+ "filename" => source.dest_path.basename.to_s,
36
+ "extname" => source.dest_path.basename.extname,
37
37
  }
38
38
  end
39
39
 
data/lib/yass/source.rb CHANGED
@@ -1,22 +1,20 @@
1
1
  module Yass
2
2
  class Source
3
3
  EXT_CONVERSIONS = {"md" => "html"}.freeze
4
- attr_reader :config, :path, :layout, :relative_path, :rendered_filename
4
+ attr_reader :config, :path, :layout, :relative_path, :dest_path
5
5
 
6
6
  def initialize(config, path)
7
7
  @config = config
8
8
  @path = path
9
9
  @relative_path = path.relative_path_from config.src_dir
10
- @layout, @rendered_filename = parse_name
10
+ dest_filename, @layout= parse_name
11
+ @dest_path = relative_path.dirname.join(dest_filename)
11
12
  end
12
13
 
13
- def url
14
- url = relative_path.dirname.join(rendered_filename)
15
- index? && !config.local ? url.dirname : url
16
- end
14
+ def url = index? && !config.local ? dest_path.dirname : dest_path
17
15
 
18
16
  def title
19
- fname = rendered_filename.sub(/\..+$/, "").to_s
17
+ fname = dest_path.basename.sub(/\..+$/, "").to_s
20
18
  fname = relative_path.dirname.basename.to_s if fname == "index"
21
19
  fname = "Home" if fname == "."
22
20
  fname.sub(/[_-]+/, " ").split(/ +/).map(&:capitalize).join(" ")
@@ -24,21 +22,21 @@ module Yass
24
22
 
25
23
  def dynamic? = !!(/\.(liquid|md)(\..+)?$/ =~ path.basename.to_s || layout)
26
24
 
27
- def index? = rendered_filename == "index.html"
25
+ def index? = dest_path.basename.to_s == "index.html"
28
26
 
29
27
  private
30
28
 
31
29
  def parse_name
32
30
  name, exts = path.basename.to_s.split(".", 2)
33
- return nil, name if exts.nil?
31
+ return name, nil if exts.nil?
34
32
 
35
33
  exts = exts.split(".").map { |x| EXT_CONVERSIONS[x] || x } - %w[liquid]
36
- return nil, "#{name}.#{exts.join "."}" if exts.size < 2
34
+ return "#{name}.#{exts.join "."}", nil if exts.size < 2
37
35
 
38
36
  layout = config.layout_cache["#{exts[-2..].join(".")}"]
39
37
  exts.delete_at(-2) if layout
40
38
 
41
- return layout, "#{name}.#{exts.join "."}"
39
+ return "#{name}.#{exts.join "."}", layout
42
40
  end
43
41
  end
44
42
  end
data/lib/yass/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yass
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-08 00:00:00.000000000 Z
11
+ date: 2025-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filewatcher