paperwork 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a4d78a79310dd0ce95afc1fa65864f5a5b8f71a0d01972762484c9ab4d4e28c
4
- data.tar.gz: 6d5edf6cddc099b47bf01e659a639df84a7305ac1d895aeb31018d65a20f8e87
3
+ metadata.gz: acec360949d7b7403f5b7d6985a6cca4289d03c19cf13f7c12a5db5d468072ea
4
+ data.tar.gz: d6cdb1bd4f9cbb211d2663c62b1ccd461c15a7c8d7a84f9afad049c31a8c2dd4
5
5
  SHA512:
6
- metadata.gz: 5983c073fb3c2295aa6827c66f6c27f647a3f3d19efaad7bce6c5ccaccdf0b67e42aeea9096c3a814ec5fea39a7980eee4df5c65aa462da0e82f51dfbccdcba4
7
- data.tar.gz: 7038d59fa69df43ef00541adc169a440439dda1f418822a0c4c36fcb86322f2866f2f988cca6e55143cb25bd81c92449b234dbf0dbff8c911521bfd1730d6191
6
+ metadata.gz: e6a1b14be156b22c42345512735e242a58b1b4ea38354e9b0550c1cab88d4c52d3a8b3efacbefbbe010f983fdaaf7536351efb394390604db58566086c085d98
7
+ data.tar.gz: 3b781ef6f0ce74100687d61e04a425a6477629f1ad1cf65f2f476a80629eddef4a32cbed834d5ef0012addd5f1dcc1dd0652aafeda8280f2e281aac6ecd958dc
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paperwork (0.2.3)
4
+ paperwork (0.3.1)
5
5
  rake (~> 12.3)
6
6
  redcarpet (~> 3.5.0)
7
+ thor (~> 1.1.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -51,6 +52,7 @@ GEM
51
52
  docile (~> 1.1)
52
53
  simplecov-html (~> 0.11)
53
54
  simplecov-html (0.12.2)
55
+ thor (1.1.0)
54
56
  unicode-display_width (1.7.0)
55
57
 
56
58
  PLATFORMS
data/Rakefile CHANGED
@@ -13,4 +13,4 @@ task rebuild: [:clean, :build]
13
13
  task default: :spec
14
14
  CLEAN.include(".work/coverage")
15
15
 
16
- paperwork :doc, sources: ["README.md", "nested_example/navdemo.md", "site.yml", "custom.js", "custom.css"]
16
+ paperwork :doc, sources: ["README.md", "nested_example/navdemo.md", "paperwork.yml", "custom.js", "custom.css"]
data/bin/paperwork ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "paperwork"
5
+
6
+ Paperwork::CLI.start
data/lib/paperwork.rb CHANGED
@@ -35,5 +35,7 @@ require "paperwork/tasks/root_helpers"
35
35
  require "paperwork/tasks/document"
36
36
  require "paperwork/tasks/template"
37
37
 
38
+ require "paperwork/cli"
39
+
38
40
 
39
41
  include Paperwork # rubocop:disable Style/MixinUsage
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # globla namespace for paperwork
5
+ #
6
+ module Paperwork
7
+ require "yaml"
8
+ require "thor"
9
+ require "paperwork"
10
+
11
+ ##
12
+ # command line interface for paperwork
13
+ #
14
+ class CLI < Thor
15
+ attr_accessor :config
16
+
17
+ CONFIG_FILE = "paperwork.yml"
18
+
19
+ class_option :verbose, aliases: "-v", desc: "be verbose about the build", type: :boolean, default: false
20
+
21
+ desc "build",
22
+ <<~DESC
23
+ creates documentation as defined in
24
+ #{CONFIG_FILE} and writes it to
25
+ '#{Paperwork::Config[:build_root]}/<name>/build'
26
+ DESC
27
+ def build
28
+ build_internal "build"
29
+ end
30
+
31
+ desc "rebuild",
32
+ <<~DESC
33
+ removes previous builds and creates
34
+ documentation as defined in
35
+ #{CONFIG_FILE} and writes it to
36
+ '#{Paperwork::Config[:build_root]}/<name>/build'
37
+ DESC
38
+ def rebuild
39
+ build_internal "rebuild"
40
+ end
41
+
42
+ desc "server",
43
+ "starts a aerver that serves documentation as defined in #{CONFIG_FILE}"
44
+ def server
45
+ build_internal "server"
46
+ end
47
+
48
+ protected
49
+
50
+ def build_internal(task)
51
+ setup_config
52
+ setup_tasks
53
+ invoke_tasks task
54
+ end
55
+
56
+ def setup_config
57
+ unless File.exist?(CONFIG_FILE)
58
+ raise Exception.new(
59
+ "#{CONFIG_FILE} not found. You need to create a configuration file first."
60
+ )
61
+ end
62
+
63
+ yaml = YAML.load_file(CONFIG_FILE)
64
+ self.config = yaml["config"]
65
+ self.config["sources"] << CONFIG_FILE
66
+
67
+ return unless self.config.nil?
68
+
69
+ raise Exception.new(
70
+ "No 'config' found in #{CONFIG_FILE}. You need to describe the build setup in a 'config' section first."
71
+ )
72
+ end
73
+
74
+ def setup_tasks
75
+ paperwork self.config["name"], sources: self.config["sources"]
76
+ end
77
+
78
+ def invoke_tasks(target)
79
+ Rake::Task["paperwork:#{self.config["name"]}:set_verbose"].invoke if options[:verbose]
80
+ Rake::Task["paperwork:#{self.config["name"]}:#{target}"].invoke
81
+ end
82
+ end
83
+ end
@@ -9,7 +9,7 @@ module Paperwork
9
9
  ##
10
10
  # main task generator for building the document
11
11
  #
12
- class Document < Paperwork::Tasks::Base
12
+ class Document < Paperwork::Tasks::Base # rubocop:disable Metrics/ClassLength
13
13
  attr_reader :dir
14
14
 
15
15
  include Rake::DSL
@@ -34,20 +34,26 @@ module Paperwork
34
34
 
35
35
  private
36
36
 
37
- def get_destination(dst_base, src) # rubocop:disable Metrics/AbcSize
38
- dst_base = File.join(dst_base, File.dirname(src))
37
+ def get_destination(dst_base, src) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
38
+ nested_base = File.dirname(src)
39
+ nested_base = if nested_base == "."
40
+ dst_base
41
+ else
42
+ File.join(dst_base, nested_base)
43
+ end
44
+
39
45
  ext = File.extname(src)
40
46
  case ext
41
47
  when ".md"
42
- File.join(dst_base, File.basename(src)).gsub(".md", ".html.md")
48
+ File.join(nested_base, File.basename(src)).gsub(".md", ".html.md")
43
49
  when ".scss"
44
- Paperwork::Config[:custom_css] << File.basename(src)
50
+ Paperwork::Config[:custom_css] << File.basename(src, ext)
45
51
  File.join(dst_base, "stylesheets", File.basename(src)).gsub(".scss", ".css.scss")
46
52
  when ".css"
47
- Paperwork::Config[:custom_css] << File.basename(src)
53
+ Paperwork::Config[:custom_css] << File.basename(src, ext)
48
54
  File.join(dst_base, "stylesheets", File.basename(src))
49
55
  when ".js"
50
- Paperwork::Config[:custom_js] << File.basename(src)
56
+ Paperwork::Config[:custom_js] << File.basename(src, ext)
51
57
  File.join(dst_base, "javascripts", File.basename(src))
52
58
  when ".yml"
53
59
  File.join(dst_base, "..", "data", File.basename(src))
@@ -80,9 +86,9 @@ module Paperwork
80
86
  end
81
87
  end
82
88
 
83
- def tasks_nested # rubocop:disable Metrics/AbcSize
84
- namespace :paperwork do
85
- namespace self.name do
89
+ def tasks_nested # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
90
+ namespace :paperwork do # rubocop:disable Metrics/BlockLength
91
+ namespace self.name do # rubocop:disable Metrics/BlockLength
86
92
  task build: ["paperwork:#{self.name}"]
87
93
 
88
94
  desc "rebuild documentation from scratch for '#{self.name}'"
@@ -99,6 +105,31 @@ module Paperwork
99
105
  task :clean do
100
106
  rm_rf self.dir
101
107
  end
108
+
109
+ desc "start middleman server for editing documents and get visual feedback with live reload"
110
+ task server: :build do
111
+ Dir.chdir(self.dir) do
112
+ Bundler.with_unbundled_env do
113
+ Process.spawn(
114
+ "bundle exec middleman server",
115
+ out: :out,
116
+ in: :in,
117
+ err: :err
118
+ )
119
+ end
120
+ puts
121
+ puts "+---------------------------------------------------------------+"
122
+ puts "| |"
123
+ puts "| IMPORTANT: Edit documents in #{self.dir} for live reload! |"
124
+ puts "| ---------- The documents there are hard links to your |"
125
+ puts "| source files, so the changes will be there |"
126
+ puts "| as well. |"
127
+ puts "| |"
128
+ puts "+---------------------------------------------------------------+"
129
+ puts
130
+ Process.waitall
131
+ end
132
+ end
102
133
  end
103
134
  end
104
135
  end
@@ -50,7 +50,6 @@ set :relative_links, true
50
50
  activate :relative_assets
51
51
  activate :livereload
52
52
  activate :syntax, line_numbers: true
53
- # activate :directory_indexes
54
53
 
55
54
 
56
55
  require "lib/doc_renderer"
@@ -6,10 +6,12 @@
6
6
  #
7
7
  module DocRenderer
8
8
  require "middleman-core/renderers/redcarpet"
9
+ require_relative "info_helpers"
9
10
 
10
11
  # This is a basic renderer for transforming markdown to HTML
11
12
  # inherit from this renderer to create more specific variants
12
13
  class Base < Middleman::Renderers::MiddlemanRedcarpetHTML
14
+ include InfoHelpers
13
15
 
14
16
  # block level calls
15
17
  def block_code(code, language)
@@ -79,11 +81,11 @@ module DocRenderer
79
81
  # def emphasis(text)
80
82
  # end
81
83
 
82
- # def image(link, title, alt_text, default_class: "img-fluid")
83
- # <<~IMG
84
- # <img src="#{link}" alt="#{alt_text}" class="#{default_class}">
85
- # IMG
86
- # end
84
+ def image(link, title, alt_text)
85
+ <<~IMG
86
+ <img src="#{relative_link link, scope.current_path}" alt="#{alt_text}" class="img-fluid">#{title}</img>
87
+ IMG
88
+ end
87
89
 
88
90
  # def linebreak()
89
91
  # end
@@ -20,9 +20,9 @@ module InfoHelpers
20
20
  end
21
21
  end
22
22
 
23
- def relative_link(stringifyable)
23
+ def relative_link(stringifyable, current_path = current_page.path)
24
24
  relative = String.new
25
- dots = current_page.path.split(/[\/\\]/).size - 1
25
+ dots = current_path.split(/[\/\\]/).size - 1
26
26
  dots.times{ relative += "../" }
27
27
  # This has been some nasty part to debug...
28
28
  # keep these comments for debugging session yet to come
@@ -35,28 +35,29 @@ module InfoHelpers
35
35
  relative + stringifyable.to_s
36
36
  end
37
37
 
38
- def site?
39
- data.respond_to?(:site)
38
+ def paperwork?
39
+ data.respond_to?(:paperwork)
40
40
  end
41
41
 
42
42
  def navbar?
43
- site? && data.site.respond_to?(:navbar)
43
+ paperwork? && data.paperwork.respond_to?(:navbar)
44
44
  end
45
45
 
46
46
  def navbar_links
47
- nav = data.site.navbar.links if navbar?
47
+ nav = data.paperwork.navbar.links if navbar?
48
48
  nav ||= {}
49
+ mapped = {}
49
50
  nav.each do |name, link|
50
- nav[name] = relative_link(link)
51
+ mapped[name] = relative_link(link)
51
52
  end
52
- nav
53
+ mapped
53
54
  end
54
55
 
55
56
  def navbar_brand
56
- data.site.navbar.brand if navbar?
57
+ data.paperwork.navbar.brand if navbar?
57
58
  end
58
59
 
59
60
  def footer_text
60
- data.site.footer if site?
61
+ data.paperwork.footer if paperwork?
61
62
  end
62
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paperwork
4
- VERSION = "0.2.3"
4
+ VERSION = "0.3.1"
5
5
  end
data/paperwork.gemspec CHANGED
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_runtime_dependency "rake", "~> 12.3"
37
37
  spec.add_runtime_dependency "redcarpet", "~> 3.5.0"
38
+ spec.add_runtime_dependency "thor", "~> 1.1.0"
38
39
  end
@@ -5,3 +5,11 @@ navbar:
5
5
  links:
6
6
  Home: README.md
7
7
  Navbar Demo: nested_example/navdemo.md
8
+
9
+ config:
10
+ name: doc
11
+ sources:
12
+ - README.md
13
+ - nested_example/navdemo.md
14
+ - custom.js
15
+ - custom.css
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperwork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schmid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-19 00:00:00.000000000 Z
11
+ date: 2021-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -108,12 +108,25 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 3.5.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: thor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.1.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.1.0
111
125
  description:
112
126
  email:
113
127
  - couchbelag@gmail.com
114
128
  executables:
115
- - console
116
- - setup
129
+ - paperwork
117
130
  extensions: []
118
131
  extra_rdoc_files: []
119
132
  files:
@@ -127,13 +140,13 @@ files:
127
140
  - LICENSE.txt
128
141
  - README.md
129
142
  - Rakefile
130
- - bin/console
131
- - bin/setup
143
+ - bin/paperwork
132
144
  - custom.css
133
145
  - custom.js
134
146
  - lib/paperwork.rb
135
147
  - lib/paperwork/assets/paperwork/presentation.css
136
148
  - lib/paperwork/assets/presentation.css
149
+ - lib/paperwork/cli.rb
137
150
  - lib/paperwork/config.rb
138
151
  - lib/paperwork/tasks.rb
139
152
  - lib/paperwork/tasks/base.rb
@@ -163,7 +176,7 @@ files:
163
176
  - lib/paperwork/version.rb
164
177
  - nested_example/navdemo.md
165
178
  - paperwork.gemspec
166
- - site.yml
179
+ - paperwork.yml
167
180
  homepage: https://gitlab.com/couchbelag/paperwork
168
181
  licenses:
169
182
  - MIT
data/bin/console DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "paperwork"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here