leg 0.0.1 → 0.0.2
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 +5 -5
- data/.gitignore +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +21 -0
- data/README.md +59 -0
- data/Rakefile +11 -0
- data/TUTORIAL.md +243 -0
- data/bin/console +9 -0
- data/bin/setup +6 -0
- data/exe/leg +6 -0
- data/leg.gemspec +31 -0
- data/lib/leg.rb +27 -0
- data/lib/leg/cli.rb +42 -0
- data/lib/leg/commands.rb +19 -0
- data/lib/leg/commands/amend.rb +49 -0
- data/lib/leg/commands/base_command.rb +99 -0
- data/lib/leg/commands/build.rb +126 -0
- data/lib/leg/commands/commit.rb +48 -0
- data/lib/leg/commands/diff.rb +29 -0
- data/lib/leg/commands/help.rb +43 -0
- data/lib/leg/commands/init.rb +46 -0
- data/lib/leg/commands/reset.rb +26 -0
- data/lib/leg/commands/resolve.rb +31 -0
- data/lib/leg/commands/save.rb +31 -0
- data/lib/leg/commands/status.rb +54 -0
- data/lib/leg/commands/step.rb +31 -0
- data/lib/leg/config.rb +42 -0
- data/lib/leg/default_templates.rb +340 -0
- data/lib/leg/diff.rb +151 -0
- data/lib/leg/diff_transformers.rb +11 -0
- data/lib/leg/diff_transformers/base_transformer.rb +13 -0
- data/lib/leg/diff_transformers/fold_sections.rb +89 -0
- data/lib/leg/diff_transformers/omit_adjacent_removals.rb +38 -0
- data/lib/leg/diff_transformers/syntax_highlight.rb +32 -0
- data/lib/leg/diff_transformers/trim_blank_lines.rb +25 -0
- data/lib/leg/line.rb +83 -0
- data/lib/leg/markdown.rb +20 -0
- data/lib/leg/page.rb +27 -0
- data/lib/leg/representations.rb +9 -0
- data/lib/leg/representations/base_representation.rb +42 -0
- data/lib/leg/representations/git.rb +388 -0
- data/lib/leg/representations/litdiff.rb +85 -0
- data/lib/leg/step.rb +16 -0
- data/lib/leg/template.rb +95 -0
- data/lib/leg/tutorial.rb +49 -0
- data/lib/leg/version.rb +3 -0
- metadata +112 -38
- data/bin/leg +0 -9
- data/lib/snaptoken.rb +0 -24
- data/lib/snaptoken/cli.rb +0 -61
- data/lib/snaptoken/commands.rb +0 -13
- data/lib/snaptoken/commands/amend.rb +0 -27
- data/lib/snaptoken/commands/base_command.rb +0 -92
- data/lib/snaptoken/commands/build.rb +0 -107
- data/lib/snaptoken/commands/commit.rb +0 -27
- data/lib/snaptoken/commands/help.rb +0 -38
- data/lib/snaptoken/commands/resolve.rb +0 -27
- data/lib/snaptoken/commands/status.rb +0 -21
- data/lib/snaptoken/commands/step.rb +0 -35
- data/lib/snaptoken/default_templates.rb +0 -287
- data/lib/snaptoken/diff.rb +0 -180
- data/lib/snaptoken/diff_line.rb +0 -54
- data/lib/snaptoken/diff_transformers.rb +0 -9
- data/lib/snaptoken/diff_transformers/base_transformer.rb +0 -9
- data/lib/snaptoken/diff_transformers/fold_sections.rb +0 -85
- data/lib/snaptoken/diff_transformers/omit_adjacent_removals.rb +0 -28
- data/lib/snaptoken/diff_transformers/trim_blank_lines.rb +0 -21
- data/lib/snaptoken/markdown.rb +0 -18
- data/lib/snaptoken/page.rb +0 -64
- data/lib/snaptoken/representations.rb +0 -8
- data/lib/snaptoken/representations/base_representation.rb +0 -38
- data/lib/snaptoken/representations/git.rb +0 -262
- data/lib/snaptoken/representations/litdiff.rb +0 -81
- data/lib/snaptoken/step.rb +0 -27
- data/lib/snaptoken/template.rb +0 -53
- data/lib/snaptoken/tutorial.rb +0 -64
data/lib/snaptoken.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'optparse'
|
4
|
-
require 'redcarpet'
|
5
|
-
require 'rouge'
|
6
|
-
require 'rouge/plugins/redcarpet'
|
7
|
-
require 'rugged'
|
8
|
-
require 'yaml'
|
9
|
-
|
10
|
-
module Snaptoken
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'snaptoken/cli'
|
14
|
-
require 'snaptoken/commands'
|
15
|
-
require 'snaptoken/default_templates'
|
16
|
-
require 'snaptoken/diff'
|
17
|
-
require 'snaptoken/diff_line'
|
18
|
-
require 'snaptoken/diff_transformers'
|
19
|
-
require 'snaptoken/markdown'
|
20
|
-
require 'snaptoken/page'
|
21
|
-
require 'snaptoken/representations'
|
22
|
-
require 'snaptoken/step'
|
23
|
-
require 'snaptoken/template'
|
24
|
-
require 'snaptoken/tutorial'
|
data/lib/snaptoken/cli.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
class Snaptoken::CLI
|
2
|
-
CONFIG_FILE = "leg.yml"
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
initial_dir = FileUtils.pwd
|
6
|
-
|
7
|
-
@tutorial = nil
|
8
|
-
last_dir = nil
|
9
|
-
while FileUtils.pwd != last_dir
|
10
|
-
if File.exist?(CONFIG_FILE)
|
11
|
-
config = YAML.load_file(CONFIG_FILE)
|
12
|
-
if config == false
|
13
|
-
puts "Error: Invalid config file."
|
14
|
-
exit!
|
15
|
-
end
|
16
|
-
config = {} unless config.is_a?(Hash)
|
17
|
-
config[:path] = FileUtils.pwd
|
18
|
-
config = symbolize_keys(config)
|
19
|
-
@tutorial = Snaptoken::Tutorial.new(config)
|
20
|
-
break
|
21
|
-
end
|
22
|
-
|
23
|
-
last_dir = FileUtils.pwd
|
24
|
-
FileUtils.cd('..')
|
25
|
-
end
|
26
|
-
|
27
|
-
FileUtils.cd(initial_dir)
|
28
|
-
end
|
29
|
-
|
30
|
-
def run(args)
|
31
|
-
args = ["help"] if args.empty?
|
32
|
-
cmd_name = args.shift.downcase
|
33
|
-
|
34
|
-
if cmd_name =~ /\A\d+\z/
|
35
|
-
args.unshift(cmd_name)
|
36
|
-
cmd_name = "step"
|
37
|
-
end
|
38
|
-
|
39
|
-
if cmd = Snaptoken::Commands::LIST.find { |cmd| cmd.name == cmd_name }
|
40
|
-
cmd.new(args, @tutorial).run
|
41
|
-
else
|
42
|
-
puts "There is no '#{cmd_name}' command. Run `leg help` for help."
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def symbolize_keys(value)
|
49
|
-
case value
|
50
|
-
when Hash
|
51
|
-
value.map do |k, v|
|
52
|
-
[k.to_sym, symbolize_keys(v)]
|
53
|
-
end.to_h
|
54
|
-
when Array
|
55
|
-
value.map { |v| symbolize_keys(v) }
|
56
|
-
else
|
57
|
-
value
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
data/lib/snaptoken/commands.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Snaptoken::Commands
|
2
|
-
LIST = []
|
3
|
-
end
|
4
|
-
|
5
|
-
require 'snaptoken/commands/base_command'
|
6
|
-
|
7
|
-
require 'snaptoken/commands/build'
|
8
|
-
require 'snaptoken/commands/status'
|
9
|
-
require 'snaptoken/commands/commit'
|
10
|
-
require 'snaptoken/commands/amend'
|
11
|
-
require 'snaptoken/commands/resolve'
|
12
|
-
require 'snaptoken/commands/step'
|
13
|
-
require 'snaptoken/commands/help'
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class Snaptoken::Commands::Amend < Snaptoken::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"amend"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Modify a step."
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.usage
|
11
|
-
""
|
12
|
-
end
|
13
|
-
|
14
|
-
def setopts!(o)
|
15
|
-
end
|
16
|
-
|
17
|
-
def run
|
18
|
-
needs! :config, :repo
|
19
|
-
|
20
|
-
if @git.commit!(amend: true)
|
21
|
-
git_to_litdiff!
|
22
|
-
puts "Success!"
|
23
|
-
else
|
24
|
-
puts "Looks like you've got a conflict to resolve!"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
class Snaptoken::Commands::BaseCommand
|
2
|
-
attr_reader :config
|
3
|
-
|
4
|
-
def initialize(args, tutorial)
|
5
|
-
@args = args
|
6
|
-
@tutorial = tutorial
|
7
|
-
@git = Snaptoken::Representations::Git.new(@tutorial)
|
8
|
-
@litdiff = Snaptoken::Representations::Litdiff.new(@tutorial)
|
9
|
-
parseopts!
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.name; raise NotImplementedError; end
|
13
|
-
def self.summary; raise NotImplementedError; end
|
14
|
-
def setopts!(o); raise NotImplementedError; end
|
15
|
-
def run; raise NotImplementedError; end
|
16
|
-
|
17
|
-
def self.inherited(subclass)
|
18
|
-
Snaptoken::Commands::LIST << subclass
|
19
|
-
end
|
20
|
-
|
21
|
-
def parseopts!
|
22
|
-
parser = OptionParser.new do |o|
|
23
|
-
o.banner = "Usage: leg #{self.class.name} #{self.class.usage}"
|
24
|
-
self.class.summary.split("\n").each do |line|
|
25
|
-
o.separator " #{line}"
|
26
|
-
end
|
27
|
-
o.separator ""
|
28
|
-
o.separator "Options:"
|
29
|
-
setopts!(o)
|
30
|
-
o.on_tail("-h", "--help", "Show this message") do
|
31
|
-
puts o
|
32
|
-
exit
|
33
|
-
end
|
34
|
-
end
|
35
|
-
@opts = {}
|
36
|
-
parser.parse!(@args)
|
37
|
-
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument => e
|
38
|
-
puts "#{e.message}"
|
39
|
-
puts
|
40
|
-
parser.parse("--help")
|
41
|
-
end
|
42
|
-
|
43
|
-
def needs!(*whats)
|
44
|
-
whats.each do |what|
|
45
|
-
case what
|
46
|
-
when :config
|
47
|
-
if @tutorial.nil?
|
48
|
-
puts "Error: You are not in a leg working directory."
|
49
|
-
exit 1
|
50
|
-
end
|
51
|
-
when :repo
|
52
|
-
if @litdiff.modified? and @git.modified?
|
53
|
-
puts "Error: doc/ and .leg/repo have diverged!"
|
54
|
-
exit 1
|
55
|
-
elsif @litdiff.modified? or !@git.exists?
|
56
|
-
litdiff_to_git!
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def git_to_litdiff!
|
63
|
-
@git.load! do |step_num|
|
64
|
-
print "\r\e[K[repo/ -> Tutorial] Step #{step_num}" unless @opts[:quiet]
|
65
|
-
end
|
66
|
-
puts unless @opts[:quiet]
|
67
|
-
|
68
|
-
num_steps = @tutorial.num_steps
|
69
|
-
@litdiff.save! do |step_num|
|
70
|
-
print "\r\e[K[Tutorial -> doc/] Step #{step_num}/#{num_steps}" unless @opts[:quiet]
|
71
|
-
end
|
72
|
-
puts unless @opts[:quiet]
|
73
|
-
|
74
|
-
@tutorial.synced!
|
75
|
-
end
|
76
|
-
|
77
|
-
def litdiff_to_git!
|
78
|
-
@litdiff.load! do |step_num|
|
79
|
-
print "\r\e[K[doc/ -> Tutorial] Step #{step_num}" unless @opts[:quiet]
|
80
|
-
end
|
81
|
-
puts unless @opts[:quiet]
|
82
|
-
|
83
|
-
num_steps = @tutorial.num_steps
|
84
|
-
@git.save! do |step_num|
|
85
|
-
print "\r\e[K[Tutorial -> repo/] Step #{step_num}/#{num_steps}" unless @opts[:quiet]
|
86
|
-
end
|
87
|
-
puts unless @opts[:quiet]
|
88
|
-
|
89
|
-
@tutorial.synced!
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
@@ -1,107 +0,0 @@
|
|
1
|
-
class Snaptoken::Commands::Build < Snaptoken::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"build"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Render repo/ into an HTML or Markdown book."
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.usage
|
11
|
-
"[-q]"
|
12
|
-
end
|
13
|
-
|
14
|
-
def setopts!(o)
|
15
|
-
o.on("-q", "--quiet", "Don't output progress") do |q|
|
16
|
-
@opts[:quiet] = q
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def run
|
21
|
-
args = @opts[:quiet] ? ["--quiet"] : []
|
22
|
-
|
23
|
-
needs! :config, :repo
|
24
|
-
|
25
|
-
@git.load!(full_diffs: true, diffs_ignore_whitespace: true) do |step_num|
|
26
|
-
print "\r\e[K[repo/ -> Tutorial] Step #{step_num}" unless @opts[:quiet]
|
27
|
-
end
|
28
|
-
puts unless @opts[:quiet]
|
29
|
-
|
30
|
-
num_steps = @tutorial.num_steps
|
31
|
-
|
32
|
-
if @tutorial.config[:diff_transformers]
|
33
|
-
transformers = @tutorial.config[:diff_transformers].map do |transformer_config|
|
34
|
-
if transformer_config.is_a? String
|
35
|
-
transformer = transformer_config
|
36
|
-
options = {}
|
37
|
-
else
|
38
|
-
transformer = transformer_config.keys.first
|
39
|
-
options = transformer_config.values.first
|
40
|
-
end
|
41
|
-
Snaptoken::DiffTransformers.const_get(transformer).new(options)
|
42
|
-
end
|
43
|
-
|
44
|
-
@tutorial.transform_diffs(transformers) do |step_num|
|
45
|
-
print "\r\e[K[Transform diffs] Step #{step_num}/#{num_steps}" unless @opts[:quiet]
|
46
|
-
end
|
47
|
-
puts unless @opts[:quiet]
|
48
|
-
end
|
49
|
-
|
50
|
-
FileUtils.mkdir_p(File.join(@tutorial.config[:path], "template"))
|
51
|
-
FileUtils.cd(File.join(@tutorial.config[:path], "template")) do
|
52
|
-
FileUtils.rm_rf("../build")
|
53
|
-
FileUtils.mkdir_p("../build/html")
|
54
|
-
FileUtils.mkdir_p("../build/html-offline")
|
55
|
-
|
56
|
-
include_default_css = true
|
57
|
-
if File.exist?("page.html.erb")
|
58
|
-
@tutorial.page_template = File.read("page.html.erb")
|
59
|
-
include_default_css = false
|
60
|
-
end
|
61
|
-
|
62
|
-
if File.exist?("step.html.erb")
|
63
|
-
@tutorial.step_template = File.read("step.html.erb")
|
64
|
-
end
|
65
|
-
@tutorial.step_template.gsub!(/\\\s*/, "")
|
66
|
-
|
67
|
-
@tutorial.pages.each do |page|
|
68
|
-
print "\r\e[K[Tutorial -> build/] Page #{page.filename}" unless @opts[:quiet]
|
69
|
-
|
70
|
-
html = page.to_html(@tutorial, false)
|
71
|
-
File.write("../build/html/#{page.filename}.html", html)
|
72
|
-
|
73
|
-
offline_html = page.to_html(@tutorial, true)
|
74
|
-
File.write("../build/html-offline/#{page.filename}.html", offline_html)
|
75
|
-
end
|
76
|
-
puts unless @opts[:quiet]
|
77
|
-
|
78
|
-
Dir["*"].each do |f|
|
79
|
-
name = File.basename(f)
|
80
|
-
|
81
|
-
next if %w(page.html.erb step.html.erb).include? name
|
82
|
-
next if name.start_with? "_"
|
83
|
-
|
84
|
-
# XXX: currently only processes top-level ERB template files.
|
85
|
-
if name.end_with? ".erb"
|
86
|
-
output = Snaptoken::Template.new(File.read(f), @tutorial, offline: false).render_template
|
87
|
-
File.write("../build/html/#{name[0..-5]}", output)
|
88
|
-
|
89
|
-
output = Snaptoken::Template.new(File.read(f), @tutorial, offline: true).render_template
|
90
|
-
File.write("../build/html-offline/#{name[0..-5]}", output)
|
91
|
-
else
|
92
|
-
FileUtils.cp_r(f, "../build/html/#{name}")
|
93
|
-
FileUtils.cp_r(f, "../build/html-offline/#{name}")
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
if include_default_css && !File.exist?("../build/html/style.css")
|
98
|
-
output = Snaptoken::Template.new(Snaptoken::DefaultTemplates::CSS, @tutorial, offline: false).render_template
|
99
|
-
File.write("../build/html/style.css", output)
|
100
|
-
end
|
101
|
-
if include_default_css && !File.exist?("../build/html-offline/style.css")
|
102
|
-
output = Snaptoken::Template.new(Snaptoken::DefaultTemplates::CSS, @tutorial, offline: true).render_template
|
103
|
-
File.write("../build/html-offline/style.css", output)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class Snaptoken::Commands::Commit < Snaptoken::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"commit"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Append or insert a new step."
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.usage
|
11
|
-
""
|
12
|
-
end
|
13
|
-
|
14
|
-
def setopts!(o)
|
15
|
-
end
|
16
|
-
|
17
|
-
def run
|
18
|
-
needs! :config, :repo
|
19
|
-
|
20
|
-
if @git.commit!
|
21
|
-
git_to_litdiff!
|
22
|
-
puts "Success!"
|
23
|
-
else
|
24
|
-
puts "Looks like you've got a conflict to resolve!"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
class Snaptoken::Commands::Help < Snaptoken::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"help"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Print out list of commands, or get help\n" +
|
8
|
-
"on a specific command."
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.usage
|
12
|
-
"[<command>]"
|
13
|
-
end
|
14
|
-
|
15
|
-
def setopts!(o)
|
16
|
-
end
|
17
|
-
|
18
|
-
def run
|
19
|
-
if @args.empty?
|
20
|
-
puts "Usage: leg <command> [args...]"
|
21
|
-
puts
|
22
|
-
puts "Commands:"
|
23
|
-
Snaptoken::Commands::LIST.each do |cmd|
|
24
|
-
puts " #{cmd.name} #{cmd.usage}"
|
25
|
-
cmd.summary.split("\n").each do |line|
|
26
|
-
puts " #{line}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
puts
|
30
|
-
puts "For more help on a specific command, run `leg help <command>`."
|
31
|
-
elsif cmd = Snaptoken::Commands::LIST.find { |cmd| cmd.name == @args.first }
|
32
|
-
cmd.new(["--help"], @tutorial)
|
33
|
-
else
|
34
|
-
puts "There is no '#{@args.first}' command."
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class Snaptoken::Commands::Resolve < Snaptoken::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"resolve"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Continue rewriting steps after resolving a merge conflict."
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.usage
|
11
|
-
""
|
12
|
-
end
|
13
|
-
|
14
|
-
def setopts!(o)
|
15
|
-
end
|
16
|
-
|
17
|
-
def run
|
18
|
-
needs! :config, :repo
|
19
|
-
|
20
|
-
if @git.resolve!
|
21
|
-
git_to_litdiff!
|
22
|
-
puts "Success!"
|
23
|
-
else
|
24
|
-
puts "Looks like you've got a conflict to resolve!"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class Snaptoken::Commands::Status < Snaptoken::Commands::BaseCommand
|
2
|
-
def self.name
|
3
|
-
"status"
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.summary
|
7
|
-
"Show whether doc/ and repo/ were\n" +
|
8
|
-
"last modified since the last sync."
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.usage
|
12
|
-
""
|
13
|
-
end
|
14
|
-
|
15
|
-
def setopts!(o)
|
16
|
-
end
|
17
|
-
|
18
|
-
def run
|
19
|
-
needs! :config
|
20
|
-
end
|
21
|
-
end
|