Add examples

This commit is contained in:
Alex Kotov 2024-02-25 08:54:16 +04:00
parent 37af17d870
commit 8ec0774613
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
15 changed files with 303 additions and 44 deletions

View File

@ -2,3 +2,18 @@ Repubmark
=========
A Markdown-inspired markup language that can be compiled into HTML and Gemtext.
Examples
--------
* `./exe/repubmark examples/config.yml word_count < examples/hello.repub`
* `./exe/repubmark examples/config.yml http < examples/hello.repub`
* `./exe/repubmark examples/config.yml gemini < examples/hello.repub`
* `./exe/repubmark examples/config.yml rss < examples/hello.repub`
* `./exe/repubmark examples/config.yml word_count < examples/full.repub`
* `./exe/repubmark examples/config.yml http < examples/full.repub`
* `./exe/repubmark examples/config.yml gemini < examples/full.repub`
* `./exe/repubmark examples/config.yml rss < examples/full.repub`

View File

@ -1,7 +0,0 @@
---
format: gemtext
base_url: 'gemini://causa-arcana.com'
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
images_prefix: '/assets/images/blog'
relative_urls: true

View File

@ -1,16 +0,0 @@
---
format: html
base_url: 'https://causa-arcana.com'
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
images_prefix: '/assets/images/blog'
relative_urls: true
css_class_annotation: 'nice-annotation'
css_class_blockquote_figure: 'nice-blockquote'
css_class_figure_self: 'nice-figure'
css_class_figure_wrap: 'd-flex justify-content-center'
css_class_figures_left: 'col-xl-6'
css_class_figures_right: 'col-xl-6'
css_class_figures_wrap: 'row'
css_class_iframe_wrap: 'ratio ratio-16x9'

View File

@ -1,16 +0,0 @@
---
format: html
base_url: 'https://causa-arcana.com'
current_path: '/xx/blog/xxxx/xx/xx/xxxxx.xxx'
images_prefix: '/assets/images/blog'
relative_urls: false
css_class_annotation: 'nice-annotation'
css_class_blockquote_figure: 'nice-blockquote'
css_class_figure_self: 'nice-figure'
css_class_figure_wrap: 'd-flex justify-content-center'
css_class_figures_left: 'col-xl-6'
css_class_figures_right: 'col-xl-6'
css_class_figures_wrap: 'row'
css_class_iframe_wrap: 'ratio ratio-16x9'

View File

@ -1,2 +0,0 @@
---
format: word_count

43
examples/config.yml Normal file
View File

@ -0,0 +1,43 @@
---
##########
# Shared #
##########
paths: &paths
current_path: '/xxxxx.xxx'
images_prefix: '/assets/images'
css_classes: &css_classes
css_class_annotation: 'nice-annotation'
css_class_blockquote_figure: 'nice-blockquote'
css_class_figure_self: 'nice-figure'
css_class_figure_wrap: 'd-flex justify-content-center'
css_class_figures_left: 'col-xl-6'
css_class_figures_right: 'col-xl-6'
css_class_figures_wrap: 'row'
css_class_iframe_wrap: 'ratio ratio-16x9'
############
# Profiles #
############
word_count:
format: word_count
gemini:
<<: *paths
format: gemtext
relative_urls: true
http:
<<: *paths
<<: *css_classes
format: html
relative_urls: true
rss:
<<: *paths
<<: *css_classes
format: html
relative_urls: false
base_url: 'https://example.com'

36
examples/full.gmi Normal file
View File

@ -0,0 +1,36 @@
Gemtext prolofue
Annotation paragraph text
> Blockquote paragraph text
Blockquote caption text
```
[[:foo, 1], [:bar, 2], [:car, 3]].each do |str, num|
puts str
puts num**2
end
```
=> https://example.com Example.com
=> assets/images/foo.jpg The Foo
=> assets/images/qwe.jpg The Qwe
=> assets/images/rty.jpg The Rty
## Chapter 1
Chapter 1 paragraph text
## Chapter 2
Chapter 2 paragraph text
Gemtext epilogue

83
examples/full.html Normal file
View File

@ -0,0 +1,83 @@
<div>
HTTP prologue
</div>
<div class="nice-annotation">
<p>
<span>
Annotation paragraph text
</span>
</p>
</div>
<figure class="nice-blockquote">
<blockquote>
<p>
<span>
Blockquote paragraph text
</span>
</p>
</blockquote>
<figcaption>
<span>
Blockquote caption text
</span>
</figcaption>
</figure>
<pre><code><span class="hl lin"> 1 </span><span class="hl opt">[[</span><span class="hl kwc">:foo</span><span class="hl opt">,</span> <span class="hl num">1</span><span class="hl opt">], [</span><span class="hl kwc">:bar</span><span class="hl opt">,</span> <span class="hl num">2</span><span class="hl opt">], [</span><span class="hl kwc">:car</span><span class="hl opt">,</span> <span class="hl num">3</span><span class="hl opt">]].</span>each <span class="hl kwa">do</span> <span class="hl opt">|</span>str<span class="hl opt">,</span> num<span class="hl opt">|</span>
<span class="hl lin"> 2 </span> puts str
<span class="hl lin"> 3 </span> puts num<span class="hl opt">**</span><span class="hl num">2</span>
<span class="hl lin"> 4 </span><span class="hl kwa">end</span>
</code></pre>
<div class="ratio ratio-16x9">
<iframe
title="Example.com"
src="https://example.com"
allowfullscreen=""
frameborder="0"
sandbox="allow-same-origin allow-scripts allow-popups"
></iframe>
</div>
<div class="d-flex justify-content-center">
<figure class="nice-figure">
<img src="assets/images/foo.jpg" alt="The Foo"/>
<figcaption>
The Foo
</figcaption>
</figure>
</div>
<div class="row">
<div class="col-xl-6">
<div class="d-flex justify-content-center">
<figure class="nice-figure">
<img src="assets/images/qwe.jpg" alt="The Qwe"/>
<figcaption>
The Qwe
</figcaption>
</figure>
</div>
</div>
<div class="col-xl-6">
<div class="d-flex justify-content-center">
<figure class="nice-figure">
<img src="assets/images/rty.jpg" alt="The Rty"/>
<figcaption>
The Rty
</figcaption>
</figure>
</div>
</div>
</div>
<h2>Chapter 1</h2>
<p>
<span>
Chapter 1 paragraph text
</span>
</p>
<h2>Chapter 2</h2>
<p>
<span>
Chapter 2 paragraph text
</span>
</p>
<div>
HTTP epilogue
</div>

60
examples/full.repub Normal file
View File

@ -0,0 +1,60 @@
article.prologue do |custom|
custom.for :html, 'HTTP prologue'
custom.for :gemtext, 'Gemtext prolofue'
end
article.annotation do |annotation|
annotation.paragraph do |paragraph|
paragraph.text 'Annotation paragraph text'
end
end
article.blockquote do |blockquote|
blockquote.paragraph do |paragraph|
paragraph.text 'Blockquote paragraph text'
end
blockquote.caption do |caption|
caption.text 'Blockquote caption text'
end
end
article.code_block :ruby, <<~CODE
[[:foo, 1], [:bar, 2], [:car, 3]].each do |str, num|
puts str
puts num**2
end
CODE
article.iframe 'Example.com', 'https://example.com'
article.nice_figure 'foo.jpg', 'The Foo'
article.nice_figures do |figures|
figures.figure 'qwe.jpg', 'The Qwe'
figures.figure 'rty.jpg', 'The Rty'
end
article.chapter 'Chapter 1' do |chapter|
chapter.paragraph do |paragraph|
paragraph.text 'Chapter 1 paragraph text'
end
end
article.chapter 'Chapter 2' do |chapter|
chapter.paragraph do |paragraph|
paragraph.text 'Chapter 2 paragraph text'
end
end
article.epilogue do |custom|
custom.for :html, 'HTTP epilogue'
custom.for :gemtext, 'Gemtext epilogue'
end

1
examples/hello.gmi Normal file
View File

@ -0,0 +1 @@
Hello, World!

5
examples/hello.html Normal file
View File

@ -0,0 +1,5 @@
<p>
<span>
Hello, World!
</span>
</p>

3
examples/hello.repub Normal file
View File

@ -0,0 +1,3 @@
article.paragraph do |paragraph|
paragraph.text 'Hello, World!'
end

View File

@ -8,7 +8,10 @@ require 'bundler/setup'
require 'repubmark'
config = Repubmark::Config.load_file String ARGV[0]
config_filename = String(ARGV[0]).freeze
profile = String(ARGV[1]).freeze
config = Repubmark::Config.load_file config_filename, profile
$article = Repubmark::Elems::Article.new config
template = $stdin.read.freeze

View File

@ -21,8 +21,12 @@ module Repubmark
attr_reader :format
def self.load_file(filename)
new(**YAML.safe_load_file(filename).transform_keys(&:to_sym))
def self.load_file(filename, profile)
config_data = YAML.safe_load_file filename, aliases: true
profile_data = config_data[profile]
raise 'Unknown profile' if profile_data.nil?
new(**profile_data.transform_keys(&:to_sym))
end
def initialize(format:, **kwargs)

47
test.rb Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'open3'
EXE = File.expand_path('exe/repubmark', __dir__).freeze
EXAMPLES = File.expand_path('examples', __dir__).freeze
EXAMPLES_GLOB = File.expand_path('examples/*.repub', __dir__).freeze
CONFIG = File.expand_path('examples/config.yml', __dir__).freeze
PROFILES = [
%w[http html],
%w[gemini gmi],
].map(&:freeze).freeze
Dir[EXAMPLES_GLOB].each do |example_filename|
example = File.read example_filename
PROFILES.each do |profile_name, expected_ext|
expected_filename = "#{example_filename[...-6]}.#{expected_ext}"
expected = File.read expected_filename
puts '=' * 80
puts "Config: #{CONFIG}"
puts "Example: #{example_filename}"
puts "Profile: #{profile_name}"
puts "Expected: #{expected_filename}"
puts '-' * 80
puts example.strip
puts '-' * 80
puts expected.strip
stdin, stdout, wait_thr = Open3.popen2 EXE, CONFIG, profile_name
stdin.puts example
stdin.close
result = stdout.read
stdout.close
raise 'Template engine error' unless wait_thr.value.success?
next if result == expected
puts '-' * 80
puts result.strip
puts '=' * 80
raise 'Invalid output'
end
end
puts '=' * 80