wytch 0.2.0 → 0.4.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/lib/wytch/builder.rb +27 -0
  4. data/lib/wytch/cli.rb +35 -4
  5. data/lib/wytch/content_loader.rb +24 -0
  6. data/lib/wytch/once.rb +20 -0
  7. data/lib/wytch/page.rb +76 -1
  8. data/lib/wytch/reload_coordinator.rb +19 -0
  9. data/lib/wytch/server.rb +28 -0
  10. data/lib/wytch/site.rb +49 -0
  11. data/lib/wytch/site_code_loader_middleware.rb +19 -0
  12. data/lib/wytch/sitemap_helper.rb +35 -0
  13. data/lib/wytch/sitemap_view.rb +41 -0
  14. data/lib/wytch/templates/content/sitemap.rb.tt +2 -2
  15. data/lib/wytch/templates/src/site/layout.rb.tt +1 -0
  16. data/lib/wytch/version.rb +2 -1
  17. data/lib/wytch.rb +29 -0
  18. data/website/.gitignore +4 -0
  19. data/website/Gemfile +8 -0
  20. data/website/Gemfile.lock +63 -0
  21. data/website/assets/Main.res +2 -0
  22. data/website/assets/main.css +1 -0
  23. data/website/bin/generate_api_docs +44 -0
  24. data/website/config.rb +6 -0
  25. data/website/content/api/wytch/builder.rb +6 -0
  26. data/website/content/api/wytch/cli.rb +6 -0
  27. data/website/content/api/wytch/contentloader.rb +6 -0
  28. data/website/content/api/wytch/error.rb +6 -0
  29. data/website/content/api/wytch/once.rb +6 -0
  30. data/website/content/api/wytch/page.rb +6 -0
  31. data/website/content/api/wytch/reloadcoordinator.rb +6 -0
  32. data/website/content/api/wytch/server.rb +6 -0
  33. data/website/content/api/wytch/site.rb +6 -0
  34. data/website/content/api/wytch/sitecodeloadermiddleware.rb +6 -0
  35. data/website/content/index.rb +6 -0
  36. data/website/content/sitemap.rb +4 -0
  37. data/website/package.json +19 -0
  38. data/website/public/robots.txt +2 -0
  39. data/website/rescript.json +18 -0
  40. data/website/src/wytch_site/api_class_view.rb +90 -0
  41. data/website/src/wytch_site/home_view.rb +33 -0
  42. data/website/src/wytch_site/layout.rb +34 -0
  43. data/website/src/wytch_site/page.rb +18 -0
  44. data/{lib/wytch/templates/src/site/sitemap_helper.rb.tt → website/src/wytch_site/sitemap_helper.rb} +1 -1
  45. data/{lib/wytch/templates/src/site/sitemap_view.rb.tt → website/src/wytch_site/sitemap_view.rb} +1 -1
  46. data/website/vite.config.js +26 -0
  47. metadata +32 -3
data/lib/wytch/version.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wytch
4
- VERSION = "0.2.0"
4
+ # The current version of Wytch.
5
+ VERSION = "0.4.0"
5
6
  end
data/lib/wytch.rb CHANGED
@@ -7,19 +7,48 @@ loader = Zeitwerk::Loader.for_gem
7
7
  loader.inflector.inflect("cli" => "CLI")
8
8
  loader.setup
9
9
 
10
+ # Wytch is a minimal static site generator that uses Ruby for content
11
+ # and Phlex for views.
12
+ #
13
+ # @example Basic configuration in config.rb
14
+ # Wytch.configure do |site|
15
+ # site.page_class = "MySite::Page"
16
+ # site.base_url = "https://example.com"
17
+ # end
18
+ #
19
+ # @see Wytch::Site
20
+ # @see Wytch::Page
10
21
  module Wytch
22
+ # Base error class for all Wytch errors.
11
23
  class Error < StandardError; end
12
24
 
13
25
  class << self
26
+ # Returns the global site instance.
27
+ #
28
+ # @return [Wytch::Site] the current site configuration
14
29
  def site
15
30
  @site ||= Site.new
16
31
  end
17
32
 
33
+ # Configures the global site instance.
34
+ #
35
+ # @yield [site] Configuration block
36
+ # @yieldparam site [Wytch::Site] the site instance to configure
37
+ # @return [Wytch::Site] the configured site
38
+ #
39
+ # @example
40
+ # Wytch.configure do |site|
41
+ # site.page_class = "MySite::Page"
42
+ # site.content_dir = "pages"
43
+ # end
18
44
  def configure
19
45
  yield(site) if block_given?
20
46
  site
21
47
  end
22
48
 
49
+ # Resets the global site instance. Primarily used for testing.
50
+ #
51
+ # @return [void]
23
52
  def reset_site!
24
53
  @site = nil
25
54
  end
@@ -0,0 +1,4 @@
1
+ build/
2
+ node_modules/
3
+ lib/
4
+ .vite/
data/website/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "wytch", path: ".."
6
+
7
+ gem "builder", "~> 3.3"
8
+ gem "yard", "~> 0.9"
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ wytch (0.2.0)
5
+ concurrent-ruby (~> 1.3)
6
+ listen (~> 3.9)
7
+ phlex (~> 1.11)
8
+ puma (~> 6.4)
9
+ rack (~> 3.1)
10
+ thor (~> 1.4)
11
+ zeitwerk (~> 2.6)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ builder (3.3.0)
17
+ concurrent-ruby (1.3.5)
18
+ ffi (1.17.2)
19
+ ffi (1.17.2-aarch64-linux-gnu)
20
+ ffi (1.17.2-aarch64-linux-musl)
21
+ ffi (1.17.2-arm-linux-gnu)
22
+ ffi (1.17.2-arm-linux-musl)
23
+ ffi (1.17.2-arm64-darwin)
24
+ ffi (1.17.2-x86-linux-gnu)
25
+ ffi (1.17.2-x86-linux-musl)
26
+ ffi (1.17.2-x86_64-darwin)
27
+ ffi (1.17.2-x86_64-linux-gnu)
28
+ ffi (1.17.2-x86_64-linux-musl)
29
+ listen (3.9.0)
30
+ rb-fsevent (~> 0.10, >= 0.10.3)
31
+ rb-inotify (~> 0.9, >= 0.9.10)
32
+ nio4r (2.7.5)
33
+ phlex (1.11.0)
34
+ puma (6.6.1)
35
+ nio4r (~> 2.0)
36
+ rack (3.2.4)
37
+ rb-fsevent (0.11.2)
38
+ rb-inotify (0.11.1)
39
+ ffi (~> 1.0)
40
+ thor (1.4.0)
41
+ yard (0.9.38)
42
+ zeitwerk (2.7.3)
43
+
44
+ PLATFORMS
45
+ aarch64-linux-gnu
46
+ aarch64-linux-musl
47
+ arm-linux-gnu
48
+ arm-linux-musl
49
+ arm64-darwin
50
+ ruby
51
+ x86-linux-gnu
52
+ x86-linux-musl
53
+ x86_64-darwin
54
+ x86_64-linux-gnu
55
+ x86_64-linux-musl
56
+
57
+ DEPENDENCIES
58
+ builder (~> 3.3)
59
+ wytch!
60
+ yard (~> 0.9)
61
+
62
+ BUNDLED WITH
63
+ 2.6.9
@@ -0,0 +1,2 @@
1
+ // Main entry point for ReScript code
2
+ Console.log("Hello from Wytch-site!")
@@ -0,0 +1 @@
1
+ @import "tailwindcss";
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'yard'
6
+ require 'fileutils'
7
+
8
+ # Path to the wytch gem lib directory
9
+ WYTCH_LIB_PATH = File.expand_path('../../lib', __dir__)
10
+ API_CONTENT_DIR = File.expand_path('../content/api', __dir__)
11
+
12
+ puts "Cleaning existing API documentation..."
13
+ FileUtils.rm_rf(API_CONTENT_DIR)
14
+ FileUtils.mkdir_p(API_CONTENT_DIR)
15
+
16
+ puts "Parsing YARD documentation from #{WYTCH_LIB_PATH}..."
17
+ YARD.parse("#{WYTCH_LIB_PATH}/**/*.rb")
18
+
19
+ puts "Generating API content files..."
20
+ YARD::Registry.all(:class).each do |klass|
21
+ # Convert Wytch::Page to wytch/page
22
+ path_segments = klass.path.split('::').map(&:downcase)
23
+
24
+ # Create directory structure
25
+ dir_path = File.join(API_CONTENT_DIR, *path_segments[0..-2])
26
+ FileUtils.mkdir_p(dir_path) if path_segments.length > 1
27
+
28
+ # Create content file
29
+ file_path = File.join(API_CONTENT_DIR, *path_segments) + '.rb'
30
+
31
+ File.write(file_path, <<~RUBY)
32
+ # frozen_string_literal: true
33
+
34
+ view WytchSite::ApiClassView
35
+
36
+ @metadata[:title] = "#{klass.path}"
37
+ @metadata[:yard_path] = "#{klass.path}"
38
+ RUBY
39
+
40
+ puts " Created #{file_path.sub(API_CONTENT_DIR + '/', '')}"
41
+ end
42
+
43
+ puts "\nGenerated #{YARD::Registry.all(:class).count} API documentation pages"
44
+ puts "Run 'wytch build' to build the site"
data/website/config.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Wytch.configure do |site|
4
+ site.page_class = "WytchSite::Page"
5
+ # site.base_url = "https://example.com"
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::Builder"
6
+ @metadata[:yard_path] = "Wytch::Builder"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::CLI"
6
+ @metadata[:yard_path] = "Wytch::CLI"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::ContentLoader"
6
+ @metadata[:yard_path] = "Wytch::ContentLoader"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::Error"
6
+ @metadata[:yard_path] = "Wytch::Error"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::Once"
6
+ @metadata[:yard_path] = "Wytch::Once"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::Page"
6
+ @metadata[:yard_path] = "Wytch::Page"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::ReloadCoordinator"
6
+ @metadata[:yard_path] = "Wytch::ReloadCoordinator"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::Server"
6
+ @metadata[:yard_path] = "Wytch::Server"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::Site"
6
+ @metadata[:yard_path] = "Wytch::Site"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::ApiClassView
4
+
5
+ @metadata[:title] = "Wytch::SiteCodeLoaderMiddleware"
6
+ @metadata[:yard_path] = "Wytch::SiteCodeLoaderMiddleware"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ view WytchSite::HomeView
4
+
5
+ @metadata[:title] = "Wytch"
6
+ @metadata[:description] = "A minimal static site generator"
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ add WytchSite::SitemapHelper
4
+ view WytchSite::SitemapView
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "wytch-site",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build"
9
+ },
10
+ "devDependencies": {
11
+ "@jihchi/vite-plugin-rescript": "^7.1.0",
12
+ "rescript": "^11.1.4",
13
+ "tailwindcss": "^4.1.0",
14
+ "vite": "^7.2.2"
15
+ },
16
+ "dependencies": {
17
+ "@rescript/core": "^1.6.1"
18
+ }
19
+ }
@@ -0,0 +1,2 @@
1
+ User-agent: *
2
+ Allow: /
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "wytch-site",
3
+ "sources": [
4
+ {
5
+ "dir": "assets",
6
+ "subdirs": true
7
+ }
8
+ ],
9
+ "package-specs": [
10
+ {
11
+ "module": "esmodule",
12
+ "in-source": false
13
+ }
14
+ ],
15
+ "suffix": ".res.js",
16
+ "bs-dependencies": ["@rescript/core"],
17
+ "bsc-flags": ["-open RescriptCore"]
18
+ }
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WytchSite
4
+ class ApiClassView < Phlex::HTML
5
+ def initialize(page)
6
+ @page = page
7
+ @klass = @page.yard_object
8
+ end
9
+
10
+ def view_template
11
+ render Layout.new(@page) do
12
+ article do
13
+ header do
14
+ h1 { @klass.path }
15
+ p(class: "summary") { @klass.docstring.summary } unless @klass.docstring.summary.empty?
16
+ end
17
+
18
+ unless @klass.docstring.to_s.empty?
19
+ section(class: "description") do
20
+ h2 { "Description" }
21
+ div { unsafe_raw markdown_to_html(@klass.docstring.to_s) }
22
+ end
23
+ end
24
+
25
+ # Public methods
26
+ public_methods = @klass.meths(visibility: :public).reject { |m| m.name == :initialize }
27
+ if public_methods.any?
28
+ section(class: "methods") do
29
+ h2 { "Methods" }
30
+ public_methods.each do |method|
31
+ render_method(method)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def render_method(method)
42
+ article(class: "method", id: method.name) do
43
+ h3 { code { method.signature } }
44
+
45
+ unless method.docstring.to_s.empty?
46
+ div(class: "method-description") do
47
+ unsafe_raw markdown_to_html(method.docstring.to_s)
48
+ end
49
+ end
50
+
51
+ # Parameters
52
+ param_tags = method.tags.select { |t| t.tag_name == "param" }
53
+ if param_tags.any?
54
+ dl(class: "parameters") do
55
+ dt { "Parameters:" }
56
+ param_tags.each do |tag|
57
+ dd do
58
+ code { tag.name }
59
+ span { " (#{tag.types.join(', ')})" } if tag.types
60
+ plain " — #{tag.text}" if tag.text
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ # Returns
67
+ return_tags = method.tags.select { |t| t.tag_name == "return" }
68
+ if return_tags.any?
69
+ dl(class: "returns") do
70
+ dt { "Returns:" }
71
+ return_tags.each do |tag|
72
+ dd do
73
+ span { "(#{tag.types.join(', ')})" } if tag.types
74
+ plain " — #{tag.text}" if tag.text
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ def markdown_to_html(text)
83
+ # Simple markdown rendering - just handle basic formatting
84
+ text.gsub(/`([^`]+)`/, '<code>\1</code>')
85
+ .gsub(/\*\*([^*]+)\*\*/, '<strong>\1</strong>')
86
+ .gsub(/\n\n/, '</p><p>')
87
+ .then { |s| "<p>#{s}</p>" }
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WytchSite
4
+ class HomeView < Phlex::HTML
5
+ def initialize(page)
6
+ @page = page
7
+ end
8
+
9
+ def view_template
10
+ render Layout.new(@page) do
11
+ h1 { @page.metadata[:title] }
12
+ p { @page.metadata[:description] }
13
+
14
+ section do
15
+ h2 { "API Documentation" }
16
+ ul do
17
+ api_pages.each do |page|
18
+ li { a(href: page.path) { page.metadata[:title] } }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def api_pages
28
+ Wytch.site.pages.values
29
+ .select { |p| p.path.start_with?('/api/') }
30
+ .sort_by { |p| p.metadata[:title] }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WytchSite
4
+ class Layout < Phlex::HTML
5
+ def initialize(page)
6
+ @page = page
7
+ end
8
+
9
+ def view_template(&block)
10
+ doctype
11
+
12
+ html do
13
+ head do
14
+ meta charset: "utf-8"
15
+ title { @page.metadata[:title] }
16
+ meta name: "description", content: @page.metadata[:description] if @page.metadata[:description]
17
+ meta name: "viewport", content: "width=device-width, initial-scale=1.0"
18
+
19
+ # Vite assets
20
+ if ENV["RACK_ENV"] == "development"
21
+ script src: "http://localhost:6970/@vite/client", type: "module"
22
+ link rel: "stylesheet", href: "http://localhost:6970/assets/main.css"
23
+ script src: "http://localhost:6970/assets/Main.res", type: "module"
24
+ else
25
+ link rel: "stylesheet", href: "/assets/main.css"
26
+ script src: "/assets/app.js", type: "module"
27
+ end
28
+ end
29
+
30
+ body(&block)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yard'
4
+
5
+ module WytchSite
6
+ class Page < Wytch::Page
7
+ def yard_object
8
+ return nil unless @metadata[:yard_path]
9
+
10
+ # Parse YARD if registry is empty
11
+ if YARD::Registry.all.empty?
12
+ YARD.parse(File.expand_path('../../../lib/**/*.rb', __dir__))
13
+ end
14
+
15
+ YARD::Registry.at(@metadata[:yard_path])
16
+ end
17
+ end
18
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module <%= @site_module %>
3
+ module WytchSite
4
4
  module SitemapHelper
5
5
  def path
6
6
  "/sitemap.xml"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module <%= @site_module %>
3
+ module WytchSite
4
4
  class SitemapView
5
5
  def initialize(page)
6
6
  @page = page
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from "vite";
2
+ import createReScriptPlugin from "@jihchi/vite-plugin-rescript";
3
+
4
+ export default defineConfig({
5
+ plugins: [
6
+ createReScriptPlugin({
7
+ loader: {
8
+ suffix: ".res.js",
9
+ },
10
+ }),
11
+ ],
12
+ build: {
13
+ outDir: "build/assets",
14
+ manifest: true,
15
+ rollupOptions: {
16
+ input: {
17
+ main: "./assets/main.css",
18
+ app: "./assets/Main.res",
19
+ },
20
+ },
21
+ },
22
+ server: {
23
+ port: 6970,
24
+ strictPort: false,
25
+ },
26
+ });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wytch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Norman
@@ -131,6 +131,8 @@ files:
131
131
  - lib/wytch/server.rb
132
132
  - lib/wytch/site.rb
133
133
  - lib/wytch/site_code_loader_middleware.rb
134
+ - lib/wytch/sitemap_helper.rb
135
+ - lib/wytch/sitemap_view.rb
134
136
  - lib/wytch/templates/Gemfile.tt
135
137
  - lib/wytch/templates/config.rb.tt
136
138
  - lib/wytch/templates/content/feed.rb.tt
@@ -150,11 +152,38 @@ files:
150
152
  - lib/wytch/templates/src/site/page.rb.tt
151
153
  - lib/wytch/templates/src/site/post_helpers.rb.tt
152
154
  - lib/wytch/templates/src/site/post_view.rb.tt
153
- - lib/wytch/templates/src/site/sitemap_helper.rb.tt
154
- - lib/wytch/templates/src/site/sitemap_view.rb.tt
155
155
  - lib/wytch/templates/vite.config.js.tt
156
156
  - lib/wytch/version.rb
157
157
  - sig/wytch.rbs
158
+ - website/.gitignore
159
+ - website/Gemfile
160
+ - website/Gemfile.lock
161
+ - website/assets/Main.res
162
+ - website/assets/main.css
163
+ - website/bin/generate_api_docs
164
+ - website/config.rb
165
+ - website/content/api/wytch/builder.rb
166
+ - website/content/api/wytch/cli.rb
167
+ - website/content/api/wytch/contentloader.rb
168
+ - website/content/api/wytch/error.rb
169
+ - website/content/api/wytch/once.rb
170
+ - website/content/api/wytch/page.rb
171
+ - website/content/api/wytch/reloadcoordinator.rb
172
+ - website/content/api/wytch/server.rb
173
+ - website/content/api/wytch/site.rb
174
+ - website/content/api/wytch/sitecodeloadermiddleware.rb
175
+ - website/content/index.rb
176
+ - website/content/sitemap.rb
177
+ - website/package.json
178
+ - website/public/robots.txt
179
+ - website/rescript.json
180
+ - website/src/wytch_site/api_class_view.rb
181
+ - website/src/wytch_site/home_view.rb
182
+ - website/src/wytch_site/layout.rb
183
+ - website/src/wytch_site/page.rb
184
+ - website/src/wytch_site/sitemap_helper.rb
185
+ - website/src/wytch_site/sitemap_view.rb
186
+ - website/vite.config.js
158
187
  homepage: https://github.com/SuperGoodSoft/wytch
159
188
  licenses:
160
189
  - MIT