charsi 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f1f4d275d1e0160a13c59583ba73d13718c6010935543c5dd9281b97071b4a4b
4
+ data.tar.gz: 4f85f65b66740a9f6bfe9c1f3204ed8f50a3fe8509facd150698c3c1dd65beb6
5
+ SHA512:
6
+ metadata.gz: ca51e1d73a4d3aed16d2ea3c72ab1638c38c035b68c3bc93ead2e1b85fe84b36dca66d2ed05d0dc4c6c111349fa79a05478d3debaf2fba0a73efd58d0715f4fb
7
+ data.tar.gz: f278453dca7038b2b10a3ea3c4750243c9138864b28ca3833b3aab55e263ddab7092da003f1939fca3d7c078c1fc5db311da3bbf42821c51e7797b27c016eea5
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in charsi.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+ gem 'terser', '~> 1.2'
10
+ gem 'tilt', '~> 2.6'
11
+ gem 'tailwindcss-ruby', '~> 4.1'
12
+ gem 'filewatcher', '~> 2.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ charsi (0.1.0)
5
+ filewatcher (~> 2.1)
6
+ logger (~> 1.6)
7
+ tailwindcss-ruby (~> 4.1)
8
+ terser (~> 1.2)
9
+ tilt (~> 2.6)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ execjs (2.10.0)
15
+ filewatcher (2.1.0)
16
+ module_methods (~> 0.1.0)
17
+ logger (1.7.0)
18
+ module_methods (0.1.0)
19
+ rake (13.3.0)
20
+ tailwindcss-ruby (4.1.11-x86_64-linux-gnu)
21
+ terser (1.2.6)
22
+ execjs (>= 0.3.0, < 3)
23
+ tilt (2.6.1)
24
+
25
+ PLATFORMS
26
+ x86_64-linux
27
+
28
+ DEPENDENCIES
29
+ charsi!
30
+ filewatcher (~> 2.0)
31
+ rake (~> 13.0)
32
+ tailwindcss-ruby (~> 4.1)
33
+ terser (~> 1.2)
34
+ tilt (~> 2.6)
35
+
36
+ BUNDLED WITH
37
+ 2.6.9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Ryan Beasse
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Charsi
2
+
3
+ A static site generator for Ruby.
4
+
5
+ ## Usage
6
+
7
+ ### Build the site
8
+
9
+ Run the static site generator:
10
+
11
+ ```bash
12
+ bundle exec charsi build
13
+ ```
14
+
15
+ ### Watch for changes
16
+
17
+ Run the static site generator with file watching:
18
+
19
+ ```bash
20
+ bundle exec charsi build --watch
21
+ ```
22
+
23
+ ### Create a new project
24
+
25
+ Generate a new Charsi project:
26
+
27
+ ```bash
28
+ bundle exec charsi new <project_name>
29
+ ```
data/bin/charsi ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'charsi'
4
+
5
+ command = ARGV[0]
6
+ watch_flag = ARGV.include?('--watch')
7
+
8
+ if command == 'build'
9
+ charsi = Charsi::Builder.new
10
+
11
+ charsi.build
12
+ charsi.watch if watch_flag
13
+ elsif command == 'new'
14
+ project_name = ARGV[1]
15
+
16
+ raise ArgumentError, 'Project name is required' if project_name.nil?
17
+
18
+ Charsi::Generator.generate(project_name)
19
+ else
20
+ puts 'Usage: charsi build [--watch]'
21
+ end
data/charsi.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'charsi'
3
+ spec.version = '0.1.0'
4
+
5
+ spec.authors = ['Ryan Beasse']
6
+ spec.email = ['me@ryanbeasse.com']
7
+
8
+ spec.summary = 'Simple static site generator.'
9
+ spec.homepage = 'https://github.com/rbeasse/charsi'
10
+ spec.license = 'MIT'
11
+
12
+ spec.required_ruby_version = '>= 3.0.0'
13
+
14
+ spec.metadata['homepage_uri'] = spec.homepage
15
+ spec.metadata['source_code_uri'] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(__dir__) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
22
+ end
23
+ end
24
+
25
+ spec.executables << 'charsi'
26
+
27
+ spec.add_dependency 'terser', '~> 1.2'
28
+ spec.add_dependency 'tilt', '~> 2.6'
29
+ spec.add_dependency 'tailwindcss-ruby', '~> 4.1'
30
+ spec.add_dependency 'filewatcher', '~> 2.1'
31
+ spec.add_dependency 'logger', '~> 1.6'
32
+ end
data/lib/charsi/app.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Charsi
2
+ # Standard app class.
3
+ #
4
+ # This class is used to build the app. It includes all utility methods to be acccessed through the
5
+ # templating.
6
+ class App
7
+ attr_reader :cache_slug
8
+
9
+ def initialize
10
+ @cache_slug = Time.now.to_i
11
+ end
12
+
13
+ protected
14
+
15
+ def stylesheet_tag(asset)
16
+ "<link rel='stylesheet' href='assets/css/#{asset}?#{@cache_slug}'>"
17
+ end
18
+
19
+ def javascript_tag(asset)
20
+ "<script src='assets/javascript/#{asset}?#{@cache_slug}'></script>"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ module Charsi
2
+ # Itterates each assets, processes them, and copies them to the output directory.
3
+ #
4
+ # JavaScript and CSS files are minified.
5
+ class Asset
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def build
11
+ assets_path = @config.path(:assets_dir, '**', '*.*')
12
+
13
+ Dir.glob(assets_path).each do |asset|
14
+ extension = File.extname(asset)
15
+ destination_dir = @config.path(:output_dir, 'assets')
16
+ destination_path = asset.sub(@config.path(:assets_dir), destination_dir)
17
+
18
+ next process_javascript(asset, destination_path) if extension == '.js'
19
+ next process_tailwind(asset, destination_path) if asset.include?('tailwind.css')
20
+
21
+ Charsi::FileManagement.copy(asset, destination_path)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def process_tailwind(asset, destination_path)
28
+ commands = [Tailwindcss::Ruby.executable]
29
+ commands += ['-i', asset, '-o', destination_path, '--minify']
30
+ commands += ['--config', 'tailwind.config.js']
31
+
32
+ system(*commands)
33
+ end
34
+
35
+ def process_javascript(asset, destination_path)
36
+ processed_asset = Terser.compile(File.read(asset))
37
+
38
+ Charsi::FileManagement.write(destination_path, processed_asset)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ module Charsi
2
+ # Builds the application and handles file watching for changes.
3
+ class Builder
4
+ def initialize
5
+ @app = defined?(::App) ? ::App.new : Charsi::App.new
6
+ @config = Configuration.new
7
+ end
8
+
9
+ def build
10
+ start_time = Time.now
11
+
12
+ Charsi::FileManagement.reset_output_dir(@config.path(:output_dir))
13
+ Charsi::Asset.new(@config).build
14
+ Charsi::Template.new(@app, @config).build
15
+
16
+ puts "[charsi] Build completed in #{Time.now - start_time} seconds."
17
+ end
18
+
19
+ def watch
20
+ Filewatcher.new(watch_paths).watch do |changes|
21
+ changes.each do |filename, event|
22
+ puts "[charsi][#{event}] #{filename}"
23
+ end
24
+
25
+ build
26
+ end
27
+ rescue Interrupt
28
+ puts "\n[charsi] Done watching."
29
+ end
30
+
31
+ private
32
+
33
+ def watch_paths
34
+ [
35
+ @config.path(:assets_dir),
36
+ @config.path(:views_dir),
37
+ @config.path(:layout_dir)
38
+ ]
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module Charsi
2
+ # Handles configuration for the Charsi application.
3
+ class Configuration
4
+ CONFIG_FILE = 'config.yml'.freeze
5
+
6
+ def initialize
7
+ @config ||= app_config
8
+ end
9
+
10
+ def path(config_key, *keys)
11
+ config_path = @config.dig('paths', config_key.to_s)
12
+
13
+ File.join(Dir.pwd, config_path, *keys)
14
+ end
15
+
16
+ private
17
+
18
+ def app_config
19
+ app_config_path = File.join(Dir.pwd, CONFIG_FILE)
20
+
21
+ YAML.load_file(app_config_path)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Charsi
2
+ # Tools for working with file operations.
3
+ class FileManagement
4
+ def self.write(path, content)
5
+ destination_folder = File.dirname(path)
6
+
7
+ FileUtils.mkdir_p(destination_folder)
8
+ File.write(path, content)
9
+ end
10
+
11
+ def self.copy(path, destination)
12
+ destination_folder = File.dirname(destination)
13
+
14
+ FileUtils.mkdir_p(destination_folder)
15
+ FileUtils.cp(path, destination)
16
+ end
17
+
18
+ def self.reset_output_dir(output_dir)
19
+ FileUtils.rm_rf(output_dir) if Dir.exist?(output_dir)
20
+ FileUtils.mkdir_p(output_dir)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ module Charsi
2
+ # The Generator class is responsible for creating new Charsi projects from our template.
3
+ class Generator
4
+ def self.generate(project, template: 'site')
5
+ templates_dir = File.join(__dir__, '../../templates', template)
6
+ templates_glob = File.join(templates_dir, '**', '*.template')
7
+
8
+ Dir.glob(templates_glob).each do |template|
9
+ output_path = template.delete_prefix(templates_dir)
10
+ output_path = output_path.delete_suffix('.template')
11
+ output_path = File.join(Dir.pwd, project, output_path)
12
+
13
+ processed_template = parse_erb(template, project)
14
+
15
+ puts "[charsi] #{output_path}"
16
+
17
+ Charsi::FileManagement.write(output_path, processed_template)
18
+ end
19
+
20
+ puts "\n[charsi] Created new static site: #{project}"
21
+ end
22
+
23
+ private
24
+
25
+ def self.titleize(string)
26
+ string.split(/_|-/).map(&:capitalize).join(' ')
27
+ end
28
+
29
+ def self.parse_erb(template_path, project)
30
+ template = Tilt::ERBTemplate.new(template_path)
31
+
32
+ template.render(nil, project_title: titleize(project))
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Charsi
2
+ # Itterates over all views and builds them into the output directory.
3
+ #
4
+ # Each view is created with a layout. The default layout is `default.erb`.
5
+ class Template
6
+ def initialize(app, config)
7
+ @app = app
8
+ @config = config
9
+ end
10
+
11
+ def build
12
+ views_path = @config.path(:views_dir, '*.erb')
13
+
14
+ Dir.glob(views_path).each do |view|
15
+ output_file = File.basename(view, '.erb') + '.html'
16
+ output_path = @config.path(:output_dir, output_file)
17
+
18
+ processed_view = parse_erb_with_layout(view)
19
+
20
+ Charsi::FileManagement.write(output_path, processed_view)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def parse_erb_with_layout(view_path, layout: 'default.erb')
27
+ layout_path = @config.path(:layout_dir, layout)
28
+
29
+ layout = Tilt::ERBTemplate.new(layout_path)
30
+ view = Tilt::ERBTemplate.new(view_path)
31
+
32
+ layout.render(@app) { view.render(@app) }
33
+ end
34
+ end
35
+ end
data/lib/charsi.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+ require 'tilt'
4
+ require 'terser'
5
+ require 'tailwindcss/ruby'
6
+ require 'yaml'
7
+ require 'filewatcher'
8
+
9
+ module Charsi
10
+ require 'charsi/configuration'
11
+ require 'charsi/file'
12
+ require 'charsi/template'
13
+ require 'charsi/asset'
14
+ require 'charsi/app'
15
+ require 'charsi/builder'
16
+ require 'charsi/generator'
17
+ end
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'charsi'
@@ -0,0 +1,58 @@
1
+ @import "tailwindcss";
2
+
3
+ @theme {
4
+ --color-catppuccin-rosewater: #f5e0dc;
5
+ --color-catppuccin-flamingo: #f2cdcd;
6
+ --color-catppuccin-pink: #f5c2e7;
7
+ --color-catppuccin-mauve: #cba6f7;
8
+ --color-catppuccin-red: #f38ba8;
9
+ --color-catppuccin-maroon: #eba0ac;
10
+ --color-catppuccin-peach: #fab387;
11
+ --color-catppuccin-yellow: #f9e2af;
12
+ --color-catppuccin-green: #a6e3a1;
13
+ --color-catppuccin-teal: #94e2d5;
14
+ --color-catppuccin-sky: #89dceb;
15
+ --color-catppuccin-sapphire: #74c7ec;
16
+ --color-catppuccin-blue: #89b4fa;
17
+ --color-catppuccin-lavender: #b4befe;
18
+ --color-catppuccin-text: #cdd6f4;
19
+ --color-catppuccin-subtext1: #bac2de;
20
+ --color-catppuccin-subtext0: #a6adc8;
21
+ --color-catppuccin-overlay2: #9399b2;
22
+ --color-catppuccin-overlay1: #7f849c;
23
+ --color-catppuccin-overlay0: #6c7086;
24
+ --color-catppuccin-surface2: #585b70;
25
+ --color-catppuccin-surface1: #45475a;
26
+ --color-catppuccin-surface0: #313244;
27
+ --color-catppuccin-base: #1e1e2e;
28
+ --color-catppuccin-mantle: #181825;
29
+ --color-catppuccin-crust: #11111b;
30
+ }
31
+
32
+ h1, h2, h3, h4, h5, h6 {
33
+ @apply font-bold text-catppuccin-sky;
34
+ }
35
+
36
+ h1 {
37
+ @apply text-3xl border-b border-catppuccin-sky;
38
+ }
39
+
40
+ h2 {
41
+ @apply text-2xl;
42
+ }
43
+
44
+ h3 {
45
+ @apply text-xl;
46
+ }
47
+
48
+ h4 {
49
+ @apply text-3xl;
50
+ }
51
+
52
+ h5 {
53
+ @apply text-2xl;
54
+ }
55
+
56
+ h6 {
57
+ @apply text-xl;
58
+ }
@@ -0,0 +1 @@
1
+ console.log('Hello world!');
@@ -0,0 +1,5 @@
1
+ paths:
2
+ output_dir: '_build'
3
+ layout_dir: 'layouts'
4
+ assets_dir: 'assets'
5
+ views_dir: 'views'
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%=project_title%></title>
5
+ <%%= stylesheet_tag('tailwind.css') %>
6
+ </head>
7
+
8
+ <body class="bg-catppuccin-base">
9
+ <main class="container mx-auto px-6 py-8 font-sans text-catppuccin-text">
10
+ <%%= yield %>
11
+ </main>
12
+
13
+ <%%= javascript_tag('app.js') %>
14
+ </body>
15
+ </html>
@@ -0,0 +1,7 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: [
4
+ "./views/**/*.erb",
5
+ "./layouts/**/*.erb"
6
+ ],
7
+ }
@@ -0,0 +1,2 @@
1
+ <h1><%=project_title%></h1>
2
+ <p class="text-lg mb-4">Simple static site generator written in Ruby.</p>
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: charsi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Beasse
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: terser
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.2'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.2'
26
+ - !ruby/object:Gem::Dependency
27
+ name: tilt
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.6'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.6'
40
+ - !ruby/object:Gem::Dependency
41
+ name: tailwindcss-ruby
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.1'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.1'
54
+ - !ruby/object:Gem::Dependency
55
+ name: filewatcher
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.1'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.1'
68
+ - !ruby/object:Gem::Dependency
69
+ name: logger
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.6'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.6'
82
+ email:
83
+ - me@ryanbeasse.com
84
+ executables:
85
+ - charsi
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - LICENSE.txt
92
+ - README.md
93
+ - bin/charsi
94
+ - charsi.gemspec
95
+ - lib/charsi.rb
96
+ - lib/charsi/app.rb
97
+ - lib/charsi/asset.rb
98
+ - lib/charsi/builder.rb
99
+ - lib/charsi/configuration.rb
100
+ - lib/charsi/file.rb
101
+ - lib/charsi/generator.rb
102
+ - lib/charsi/template.rb
103
+ - templates/site/Gemfile.template
104
+ - templates/site/assets/css/tailwind.css.template
105
+ - templates/site/assets/javascript/app.js.template
106
+ - templates/site/config.yml.template
107
+ - templates/site/layouts/default.erb.template
108
+ - templates/site/tailwind.config.js.template
109
+ - templates/site/views/index.erb.template
110
+ homepage: https://github.com/rbeasse/charsi
111
+ licenses:
112
+ - MIT
113
+ metadata:
114
+ homepage_uri: https://github.com/rbeasse/charsi
115
+ source_code_uri: https://github.com/rbeasse/charsi
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 3.0.0
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubygems_version: 3.6.9
131
+ specification_version: 4
132
+ summary: Simple static site generator.
133
+ test_files: []