diff --git a/.forgejo/workflows/docs.yml b/.forgejo/workflows/docs.yml new file mode 100644 index 0000000..a3a96a3 --- /dev/null +++ b/.forgejo/workflows/docs.yml @@ -0,0 +1,17 @@ +on: + push: + branches: + - main + +jobs: + build: + runs-on: selfhosted + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install dependencies + run: bundle install + - name: Build documentation + run: bundle exec ruby docs/build.rb + - name: Publish site + run: cp -rfv _build/* /srv/docs/phlexite/ diff --git a/.forgejo/workflows/gem-push.yml b/.forgejo/workflows/gem-push.yml new file mode 100644 index 0000000..46ed5a0 --- /dev/null +++ b/.forgejo/workflows/gem-push.yml @@ -0,0 +1,46 @@ +name: Ruby Gem + +on: + push: + tags: ["*"] + +jobs: + build: + name: Build + Publish + runs-on: docs + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby 3.3 + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 + with: + ruby-version: 3.3.x + + - name: Publish to GPR + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem build *.gemspec + gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem + env: + GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}" + OWNER: ${{ github.repository_owner }} + + - name: Publish to RubyGems + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem build *.gemspec + gem push *.gem + env: + GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" diff --git a/.forgejo/workflows/main.yml b/.forgejo/workflows/main.yml new file mode 100644 index 0000000..9a0b5a8 --- /dev/null +++ b/.forgejo/workflows/main.yml @@ -0,0 +1,27 @@ +name: Ruby + +on: + push: + branches: + - main + + pull_request: + +jobs: + build: + runs-on: docker + name: Ruby ${{ matrix.ruby }} + strategy: + matrix: + ruby: + - "3.3.5" + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run the default task + run: bundle exec rake diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index b131488..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Ruby - -on: - push: - branches: - - main - - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - name: Ruby ${{ matrix.ruby }} - strategy: - matrix: - ruby: - - '3.3.5' - - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run the default task - run: bundle exec rake diff --git a/.gitignore b/.gitignore index 9106b2a..dea589d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /pkg/ /spec/reports/ /tmp/ +_build/ diff --git a/Gemfile b/Gemfile index 06ed10c..824b40d 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,6 @@ gem "minitest", "~> 5.16" gem "standard", "~> 1.3" -gem "phlex", "~> 1.11" +gem "phlex", "~> 2.3" -gem "steep", "~> 1.7", :group => :development +gem "steep", "~> 1.7", group: :development diff --git a/Gemfile.lock b/Gemfile.lock index ba81738..ba33887 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -26,6 +26,7 @@ GEM drb (2.2.1) ffi (1.17.0) ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x64-mingw-ucrt) fileutils (1.7.2) i18n (1.14.5) concurrent-ruby (~> 1.0) @@ -107,6 +108,7 @@ GEM PLATFORMS arm64-darwin-23 ruby + x64-mingw-ucrt DEPENDENCIES minitest (~> 5.16) diff --git a/docs/build.rb b/docs/build.rb new file mode 100644 index 0000000..5b57a00 --- /dev/null +++ b/docs/build.rb @@ -0,0 +1,13 @@ +require_relative '../lib/phlexite' +require 'phlex' + +module Phlexite + module Docs end +end + +require_relative 'pages/layout' +require_relative 'pages/index' + +Phlexite::Site.new { |s| + s.page 'index.html', Phlexite::Docs::Pages::Index.new +} diff --git a/docs/pages/index.rb b/docs/pages/index.rb new file mode 100644 index 0000000..c841521 --- /dev/null +++ b/docs/pages/index.rb @@ -0,0 +1,10 @@ +module Phlexite::Docs::Pages + class Index < ::Phlex::HTML + def view_template + render Layout.new { + h1 { 'Phlexite' } + p { 'Phlexite is a simple static site generator for Ruby.' } + } + end + end +end \ No newline at end of file diff --git a/docs/pages/layout.rb b/docs/pages/layout.rb new file mode 100644 index 0000000..4fbf287 --- /dev/null +++ b/docs/pages/layout.rb @@ -0,0 +1,29 @@ +module Phlexite::Docs::Pages + class Layout < ::Phlex::HTML + def view_template + doctype + html { + head { + meta charset: 'utf-8' + + meta name: 'viewport', content: 'width=device-width, initial-scale=1.0' + title { "Phlexite" } + + link rel: 'stylesheet', href: 'https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css' + } + body(style: "padding: 0; margin: 0; display: flex; flex-direction: row; height: 100vh; width: 100vw;") { + aside(style: 'padding: 30px; min-width: 15%; border-right: 1px solid #6F7887;') { + nav { + ul { + li { a(href: '/') { 'Home' } } + } + } + } + div(class: 'container', style: 'padding: 20px') { + yield + } + } + } + end + end +end \ No newline at end of file diff --git a/lib/phlexite/router.rb b/lib/phlexite/router.rb index 2363b53..1c2f5b9 100644 --- a/lib/phlexite/router.rb +++ b/lib/phlexite/router.rb @@ -1,4 +1,4 @@ -require 'fileutils' +require "fileutils" class Phlexite::Router def initialize(base, site) @@ -7,25 +7,25 @@ class Phlexite::Router end def group(new_base) - router = Phlexite::Router.new(File::join(@base, new_base), @site) + router = Phlexite::Router.new(File.join(@base, new_base), @site) yield router end def page(out_path, component) out = full_out_path(out_path) - FileUtils::mkdir_p File::dirname(out) - File::write(out, component.call) + FileUtils.mkdir_p File.dirname(out) + File.write(out, component.call) end def mount(local_directory, on:) out = full_out_path(on) - FileUtils::mkdir_p out - FileUtils::cp_r File::join(local_directory, "."), out + FileUtils.mkdir_p out + FileUtils.cp_r File.join(local_directory, "."), out end -private + private def full_out_path(out_path) - File::join(@site.build_dir, @site.base_url, @base, out_path) + File.join(@site.build_dir, @site.base_url, @base, out_path) end end diff --git a/lib/phlexite/site.rb b/lib/phlexite/site.rb index 5232f8c..21ef3a1 100644 --- a/lib/phlexite/site.rb +++ b/lib/phlexite/site.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'router.rb' +require_relative "router" class Phlexite::Site < Phlexite::Router attr_accessor :build_dir, :base_url diff --git a/test/test_phlexite.rb b/test/test_phlexite.rb index 16e3ebd..703d7ed 100644 --- a/test/test_phlexite.rb +++ b/test/test_phlexite.rb @@ -12,10 +12,10 @@ class TestPhlexite < Minitest::Test end def test_that_site_is_defined - assert ::Phlexite::Site != nil + assert !::Phlexite::Site.nil? end def test_that_router_is_defined - assert ::Phlexite::Router != nil + assert !::Phlexite::Router.nil? end end