sancho 0.6.2 → 0.7.1

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.
@@ -0,0 +1,25 @@
1
+ module Sancho
2
+ module_function
3
+
4
+ VERSION = '0.7.1'
5
+
6
+ def root
7
+ File.expand_path(File.dirname(__dir__))
8
+ end
9
+
10
+ def assets
11
+ File.join(root, LAYOUTS_DIR)
12
+ end
13
+
14
+ CONFIG_FILE = '.sancho.yml'
15
+
16
+ LAYOUTS_DIR = '_layouts'
17
+
18
+ DEFAULT_SITE_DIR = 'docs'
19
+
20
+ DEFAULT_SITE_DOMAIN = 'domain'
21
+
22
+ DEFAULT_SITE_TITLE = 'Sancho'
23
+ end
24
+
25
+ # puts Sancho.root, Sancho.assets
@@ -0,0 +1,8 @@
1
+ module Sancho
2
+ module Model
3
+
4
+ # Config model
5
+ Config = Data.define(:directory, :domain, :title, :pages)
6
+
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ module Sancho
2
+ module Model
3
+
4
+ # Page model
5
+ Page = Data.define(:source, :url, :date) do
6
+ # @param source [String] filename
7
+ # @param url [String]
8
+ def self.from(source, url = '')
9
+ url = File.basename(source, '.md').downcase + '.html' if url.empty?
10
+ date = File.mtime(source).to_date
11
+ new(source:, url:, date:)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'page'
2
+ require 'forwardable'
3
+
4
+ module Sancho
5
+ module Model
6
+
7
+ # Site model
8
+ Site = Data.define(:domain, :title, :pages) do
9
+ extend Forwardable
10
+ def_delegator :pages, :each, :each_page
11
+
12
+ def pages_by_date
13
+ pages.sort{|a, b| b.date <=> a.date }
14
+ end
15
+
16
+ def add(page)
17
+ with(pages: pages.push(page))
18
+ end
19
+ alias << add
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'model/page'
2
+ require_relative 'model/site'
3
+ require_relative 'model/config'
4
+
5
+ module Sancho
6
+
7
+ # Model namespace
8
+ module Model
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ require_relative '../config'
2
+ require_relative '../model'
3
+ require 'fileutils'
4
+
5
+ module Sancho
6
+ module Task
7
+
8
+ # Basic action
9
+ class Basic
10
+ extend FileUtils
11
+
12
+ def self.run(*args, **kwargs)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,55 @@
1
+ require_relative 'basic'
2
+ require 'tmpdir'
3
+ require 'erb'
4
+
5
+ module Sancho
6
+ module Task
7
+
8
+ # Build site
9
+ class BuildSite < Basic
10
+ # @param config [Model::Config]
11
+ def self.run(config)
12
+ %w[images css jss]
13
+ .map{ File.join(config.directory, it) }
14
+ .each{ mkdir_p it }
15
+
16
+ styles = File.join(Sancho::LAYOUTS_DIR, 'styles.css')
17
+ cp styles, File.join(config.directory, 'css')
18
+
19
+ pages = config.pages.map{ Model::Page.from(it) }
20
+ index = config.pages.find{ it.downcase =~ /^index/ }
21
+ pages << Model::Page.from(config.pages.first, 'index.html') \
22
+ unless index
23
+
24
+ site = Model::Site.new(
25
+ domain: config.domain,
26
+ title: config.title,
27
+ pages:)
28
+
29
+ # process erb require site variable
30
+ Dir["#{Sancho::LAYOUTS_DIR}/*.erb"].each do |erb|
31
+ content = ERB.new(File.read(erb), trim_mode: '%').result(binding)
32
+ filename = File.join(config.directory, File.basename(erb,'.erb'))
33
+ File.write(filename, content)
34
+ end
35
+
36
+ srcdir = Dir.pwd
37
+ Dir.mktmpdir do |dir|
38
+ header = File.join(dir, 'header.html')
39
+ footer = File.join(dir, 'footer.html')
40
+ system "pandoc -o #{header} #{Sancho::LAYOUTS_DIR}/header.md"
41
+ system "pandoc -o #{footer} #{Sancho::LAYOUTS_DIR}/footer.md"
42
+
43
+ optns = PANDOC_OPTIONS + " -B #{header} -A #{footer}"
44
+ site.pages.each{
45
+ source = File.join(srcdir, it.source)
46
+ system "pandoc #{optns} -o #{config.directory}/#{it.url} #{source}"
47
+ }
48
+ end
49
+ end
50
+
51
+ PANDOC_OPTIONS = "-s --toc --template #{Sancho::LAYOUTS_DIR}/layout.html -c css/styles.css"
52
+ end
53
+
54
+ end
55
+ end
@@ -1,6 +1,6 @@
1
1
  # https://devcenter.heroku.com/articles/static-sites-ruby
2
2
  require 'rack/static'
3
- require 'sancho'
3
+ require_relative 'read_config'
4
4
 
5
5
  use Rack::Static,
6
6
  :urls => ["/images", "/js", "/css"],
@@ -12,9 +12,10 @@ text_html = {
12
12
  'cache-control' => 'public, max-age=86400'
13
13
  }
14
14
 
15
+ config = Sancho::Task::ReadConfig.run
15
16
  run lambda {|env|
16
17
  target = env['REQUEST_PATH'][1..-1]
17
- source = File.join(Sancho::DOCS, target)
18
+ source = File.join(config.directory, target)
18
19
  return [404, text_plain, ['not found']] \
19
20
  unless File.exist?(source)
20
21
  [200, text_html, File.open(source, File::RDONLY)]
@@ -0,0 +1,19 @@
1
+ require_relative 'basic'
2
+
3
+ module Sancho
4
+ module Task
5
+
6
+ # Copy Sancho assets
7
+ class CopyAssets < Basic
8
+ # @param dest [String] directory to punch
9
+ def self.run
10
+ dir = Sancho::LAYOUTS_DIR
11
+ return if Dir.exist?(dir)
12
+
13
+ mkdir_p dir
14
+ cp_r "#{Sancho.assets}/.", dir
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'basic'
2
+ require 'psych'
3
+
4
+ module Sancho
5
+ module Task
6
+
7
+ # Read configuration
8
+ class ReadConfig < Basic
9
+ def self.run
10
+ config = Sancho::CONFIG_FILE
11
+
12
+ begin
13
+ if File.exist?(config)
14
+ Psych
15
+ .load(File.read(config))
16
+ .transform_keys(&:to_sym)
17
+ .then{ return Model::Config.new(**it) }
18
+ end
19
+ rescue StandardError => e
20
+ puts "Sancho configuration error", e.message
21
+ end
22
+
23
+ conf = Model::Config.new(
24
+ Sancho::DEFAULT_SITE_DIR,
25
+ Sancho::DEFAULT_SITE_DOMAIN,
26
+ Sancho::DEFAULT_SITE_TITLE,
27
+ %w[README.md CHANGELOG.md])
28
+
29
+ dump = Psych.dump(conf.to_h.transform_keys(&:to_s))
30
+ File.write(config, dump)
31
+
32
+ conf
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'basic'
2
+
3
+ module Sancho
4
+ module Task
5
+
6
+ # Serve site
7
+ class ServeSite
8
+ def self.run
9
+ ru = File.join(__dir__, CONFIG_RU)
10
+ system "rackup #{ru}"
11
+ end
12
+
13
+ # rackup file
14
+ CONFIG_RU = 'config.ru'
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'tasks/read_config'
2
+ require_relative 'tasks/copy_assets'
3
+ require_relative 'tasks/build_site'
4
+ require_relative 'tasks/serve_site'
5
+
6
+ module Sancho
7
+
8
+ # Tasks (interactors) namespace
9
+ module Task
10
+ end
11
+ end
data/lib/sancho.rb CHANGED
@@ -1,37 +1,8 @@
1
- # frozen_string_literal: true
2
- require 'date'
3
- require_relative 'sancho/conf'
4
- require_relative 'sancho/page'
5
- require_relative 'sancho/site'
1
+ require_relative 'sancho/config'
2
+ require_relative 'sancho/model'
3
+ require_relative 'sancho/tasks'
4
+ require_relative 'sancho/cli'
6
5
 
7
6
  # Github Pages site generator
8
7
  module Sancho
9
- extend self
10
-
11
- VERSION = "0.6.2"
12
-
13
- DOCS = 'docs'.freeze
14
-
15
- def root
16
- dir = File.dirname(__dir__)
17
- File.expand_path(dir)
18
- end
19
-
20
- def assets
21
- File.join(root, '_layouts')
22
- end
23
-
24
- def docs
25
- Site.new(**Conf.read.to_h)
26
- end
27
-
28
- def lib
29
- File.join(root, 'lib')
30
- end
31
-
32
- # Rake.application.rake_require "tasks", [sancho]
33
- def tasks
34
- ['tasks', [lib]]
35
- end
36
-
37
8
  end
data/lib/tasks.rake CHANGED
@@ -25,10 +25,11 @@ namespace :sancho do
25
25
 
26
26
  Sancho initialized!
27
27
 
28
- To create Site Pages:
29
- $ rake sancho:init
30
- $ rake sancho:docs
31
- $ rake sancho:serve
28
+ To create GitHub Pages:
29
+ 1. run 'git checkout -b docs'
30
+ 2. configure in 'sancho.yml'
31
+ 3. run 'rake sancho:docs'
32
+ 4. commit changes, push 'docs'
32
33
  EOF
33
34
  end
34
35
 
@@ -72,9 +73,20 @@ namespace :sancho do
72
73
  end
73
74
 
74
75
  desc "serve"
75
- task serve: [:docs] do
76
+ task :serve do
76
77
  ru = File.join(Sancho.lib, 'config.ru')
77
78
  sh "rackup #{ru}"
78
79
  end
79
80
 
81
+ desc "release.."
82
+ task :release do
83
+ sh 'git checkout docs'
84
+ sh 'git merge master'
85
+ Rake::Task['sancho:docs'].execute
86
+ sh 'git add .'
87
+ sh 'git commit -m "sancho:docs"'
88
+ sh 'git push'
89
+ sh 'git checkout master'
90
+ end
91
+
80
92
  end
data/sancho.gemspec CHANGED
@@ -9,16 +9,12 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["nvoynov@gmail.com"]
10
10
 
11
11
  spec.summary = "Github Pages Generator"
12
- # spec.description = "Simple Site Generator from Markdown to Html by Pandoc"
13
- # spec.homepage = "https://github/nvoynov/sancho"
14
- spec.required_ruby_version = ">= 2.6.0"
12
+ spec.description = "Simple Site Generator from Markdown to Html by Pandoc"
13
+ spec.homepage = "https://github/nvoynov/sancho"
14
+ spec.required_ruby_version = ">= 3.4.0"
15
15
 
16
16
  # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
17
 
18
- # spec.metadata["homepage_uri"] = spec.homepage
19
- # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
-
22
18
  # Specify which files should be added to the gem when it is released.
23
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
20
  spec.files = Dir.chdir(__dir__) do
metadata CHANGED
@@ -1,34 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sancho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikolay Voynov
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-03-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
12
+ description: Simple Site Generator from Markdown to Html by Pandoc
14
13
  email:
15
14
  - nvoynov@gmail.com
16
- executables: []
15
+ executables:
16
+ - sancho
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".dockerignore"
21
+ - ".rubocop.yml"
22
+ - ".sancho.yml"
20
23
  - CHANGELOG.md
21
24
  - Gemfile
22
25
  - Gemfile.lock
23
26
  - README.md
24
27
  - Rakefile
25
28
  - STORY.md
26
- - _layouts/footer.md
27
- - _layouts/header.md
28
- - _layouts/layout.html
29
- - _layouts/robots.txt.erb
30
- - _layouts/sitemap.xml.erb
31
- - _layouts/styles.css
32
29
  - docs/changelog.html
33
30
  - docs/css/styles.css
34
31
  - docs/index.html
@@ -37,18 +34,33 @@ files:
37
34
  - docs/sitemap.xml
38
35
  - docs/story.html
39
36
  - docs/styles.css
40
- - lib/config.ru
37
+ - exe/sancho
38
+ - lib/_layouts/footer.md
39
+ - lib/_layouts/header.md
40
+ - lib/_layouts/layout.html
41
+ - lib/_layouts/robots.txt.erb
42
+ - lib/_layouts/sitemap.xml.erb
43
+ - lib/_layouts/styles.css
41
44
  - lib/sancho.rb
42
- - lib/sancho/conf.rb
43
- - lib/sancho/page.rb
44
- - lib/sancho/site.rb
45
+ - lib/sancho/cli.rb
46
+ - lib/sancho/config.rb
47
+ - lib/sancho/model.rb
48
+ - lib/sancho/model/config.rb
49
+ - lib/sancho/model/page.rb
50
+ - lib/sancho/model/site.rb
51
+ - lib/sancho/tasks.rb
52
+ - lib/sancho/tasks/basic.rb
53
+ - lib/sancho/tasks/build_site.rb
54
+ - lib/sancho/tasks/config.ru
55
+ - lib/sancho/tasks/copy_assets.rb
56
+ - lib/sancho/tasks/read_config.rb
57
+ - lib/sancho/tasks/serve_site.rb
45
58
  - lib/tasks.rake
46
59
  - sancho.gemspec
47
60
  - sancho.yml
48
- homepage:
61
+ homepage: https://github/nvoynov/sancho
49
62
  licenses: []
50
63
  metadata: {}
51
- post_install_message:
52
64
  rdoc_options: []
53
65
  require_paths:
54
66
  - lib
@@ -56,15 +68,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
68
  requirements:
57
69
  - - ">="
58
70
  - !ruby/object:Gem::Version
59
- version: 2.6.0
71
+ version: 3.4.0
60
72
  required_rubygems_version: !ruby/object:Gem::Requirement
61
73
  requirements:
62
74
  - - ">="
63
75
  - !ruby/object:Gem::Version
64
76
  version: '0'
65
77
  requirements: []
66
- rubygems_version: 3.5.5
67
- signing_key:
78
+ rubygems_version: 3.6.9
68
79
  specification_version: 4
69
80
  summary: Github Pages Generator
70
81
  test_files: []
@@ -1,4 +0,0 @@
1
- User-agent: *
2
- Allow: /
3
-
4
- Sitemap: https://<%= @site.domain %>/sitemap.xml
data/lib/sancho/conf.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'psych'
2
-
3
- module Sancho
4
- class Conf < Data.define(:domain, :title, :pages)
5
- def self.read
6
- return new(**Psych.load(File.read(CONF)).transform_keys(&:to_sym)) \
7
- if File.exist?(CONF)
8
-
9
- new.tap{|o| File.write(CONF, Psych.dump(o.to_h.transform_keys(&:to_s))) }
10
- rescue => e
11
- puts 'Sancho: reading config error', e.full_message
12
- new
13
- end
14
-
15
- def initialize(domain: 'domain', title: 'title', pages: %w[README.md CHANGELOG.md])
16
- super
17
- end
18
-
19
- CONF = 'sancho.yml'
20
- end
21
- end
data/lib/sancho/page.rb DELETED
@@ -1,11 +0,0 @@
1
- module Sancho
2
-
3
- class Page < Data.define(:source, :url, :date)
4
- def initialize(source:, url: '')
5
- url = File.basename(source, '.md').downcase + '.html' if url.empty?
6
- date = File.mtime(source).to_date
7
- super(source: source, url: url, date: date)
8
- end
9
- end
10
-
11
- end
data/lib/sancho/site.rb DELETED
@@ -1,24 +0,0 @@
1
- require_relative 'page'
2
- require 'forwardable'
3
-
4
- module Sancho
5
-
6
- class Site < Data.define(:domain, :title, :pages)
7
- extend Forwardable
8
- def_delegator :pages, :each, :each_page
9
-
10
- def initialize(domain:, title:, pages:)
11
- pages = pages.map{|e| Page.new(e) }
12
- super
13
- end
14
-
15
- def pages_by_date
16
- pages.sort{|a, b| b.date <=> a.date}
17
- end
18
-
19
- def <<(page)
20
- with(pages: pages.unshift(page))
21
- end
22
- end
23
-
24
- end
File without changes
File without changes
File without changes
File without changes