snaptoken 0.11.0 → 0.12.0
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 +4 -4
- data/lib/snaptoken/commands/base_command.rb +5 -0
- data/lib/snaptoken/commands/doc.rb +31 -13
- data/lib/snaptoken/commands/fancy.rb +0 -8
- data/lib/snaptoken/commands/repo.rb +5 -1
- data/lib/snaptoken/diff.rb +8 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '03814fd3146986918c4c33d8fa606e741245fd68'
|
4
|
+
data.tar.gz: 18e23c04b3104332f2fdb9a752bb1eb51e6fbbd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd071cc29eb3336f2dc4b8fe40cdc4f76dba7163cadd350f647f9fcc7c08744ee11eecfa9aa0a6300229e9fbae766c1b3552deca61299961261c2d24cb37555a
|
7
|
+
data.tar.gz: e77a2cdc1c27dcc53f6f81070559fe347790b365f0491566ace1fc016d13ca7ff6019cfba710b7d47aa0e203bf8ab7f56a97a7c063acd4ccc68d492f90fcf500
|
@@ -17,6 +17,9 @@ class Snaptoken::Commands::BaseCommand
|
|
17
17
|
true: "You are not in a leg working directory.",
|
18
18
|
false: "You are already in a leg working directory."
|
19
19
|
},
|
20
|
+
config_name: {
|
21
|
+
true: "You need to set a name in leg.yml."
|
22
|
+
},
|
20
23
|
config_title: {
|
21
24
|
true: "You need to set a title in leg.yml."
|
22
25
|
},
|
@@ -57,6 +60,8 @@ class Snaptoken::Commands::BaseCommand
|
|
57
60
|
case what
|
58
61
|
when :config
|
59
62
|
valid = true if @config
|
63
|
+
when :config_name
|
64
|
+
valid = true if @config[:name]
|
60
65
|
when :config_title
|
61
66
|
valid = true if @config[:title]
|
62
67
|
when :steps_folder
|
@@ -8,7 +8,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def run
|
11
|
-
needs! :config, :config_title, :steps_folder, :steps, :doc
|
11
|
+
needs! :config, :config_name, :config_title, :steps_folder, :steps, :doc
|
12
12
|
|
13
13
|
FileUtils.cd(File.join(@config[:path], "doc")) do
|
14
14
|
FileUtils.rm_rf("html_out")
|
@@ -40,7 +40,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
|
|
40
40
|
def copy_static_files
|
41
41
|
Dir["html_in/*"].each do |f|
|
42
42
|
name = File.basename(f)
|
43
|
-
unless %w(template.html style.css).include? name
|
43
|
+
unless %w(template.html template_index.html style.css).include? name
|
44
44
|
FileUtils.cp_r(f, "html_out/#{name}")
|
45
45
|
end
|
46
46
|
end
|
@@ -73,7 +73,7 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
|
|
73
73
|
names << $1
|
74
74
|
end
|
75
75
|
|
76
|
-
diff = Snaptoken::Diff.new(last_step, step)
|
76
|
+
diff = Snaptoken::Diff.new(@config, last_step, step)
|
77
77
|
|
78
78
|
names.each do |name|
|
79
79
|
diffs[name] = diff.html.values.join("\n")
|
@@ -91,24 +91,35 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
|
|
91
91
|
|
92
92
|
index = ""
|
93
93
|
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
|
94
|
-
Dir["*.md"].sort.
|
95
|
-
|
96
|
-
|
97
|
-
md = File.read(md_file)
|
94
|
+
pages = Dir["*.md"].sort.map { |f| f.sub(/\.md$/, '') }
|
95
|
+
pages.each.with_index do |page, idx|
|
96
|
+
md = File.read("#{page}.md")
|
98
97
|
md =~ /^# (.+)$/
|
99
98
|
title = $1
|
100
99
|
|
101
|
-
index << "<li><a href='#{
|
100
|
+
index << "<li><a href='#{page}.html'>#{title}</a></li>\n"
|
101
|
+
|
102
|
+
prev_link = "<a href='#'></a>"
|
103
|
+
if idx > 0
|
104
|
+
prev_link = "<a href='#{pages[idx-1]}.html'>← prev</a>"
|
105
|
+
end
|
106
|
+
|
107
|
+
next_link = "<a href='#'></a>"
|
108
|
+
if idx < pages.length - 1
|
109
|
+
next_link = "<a href='#{pages[idx+1]}.html'>next →</a>"
|
110
|
+
end
|
102
111
|
|
103
112
|
content = markdown.render(md)
|
104
113
|
content = Redcarpet::Render::SmartyPants.render(content)
|
105
114
|
content.gsub!(/<p>{{([\w-]+)}}<\/p>/) { diffs[$1] }
|
106
115
|
|
107
116
|
html = html_template.dup
|
108
|
-
html.gsub!("{{title}}") { "#{
|
117
|
+
html.gsub!("{{title}}") { "#{idx+1}. #{title} | #{@config[:title]}" }
|
118
|
+
html.gsub!("{{prev_link}}") { prev_link }
|
119
|
+
html.gsub!("{{next_link}}") { next_link }
|
109
120
|
html.gsub!("{{content}}") { content }
|
110
121
|
|
111
|
-
File.write(File.join("html_out",
|
122
|
+
File.write(File.join("html_out", "#{page}.html"), html)
|
112
123
|
end
|
113
124
|
|
114
125
|
content = <<~HTML
|
@@ -119,9 +130,16 @@ class Snaptoken::Commands::Doc < Snaptoken::Commands::BaseCommand
|
|
119
130
|
</ol>
|
120
131
|
HTML
|
121
132
|
|
122
|
-
|
123
|
-
|
124
|
-
|
133
|
+
if File.exist?("html_in/template_index.html")
|
134
|
+
html = File.read("html_in/template_index.html")
|
135
|
+
else
|
136
|
+
html = html_template.dup
|
137
|
+
end
|
138
|
+
|
139
|
+
html.gsub!("{{title}}") { "Table of contents | #{@config[:title]}" }
|
140
|
+
html.gsub!("{{prev_link}}") { "<a href='#'></a>" }
|
141
|
+
html.gsub!("{{next_link}}") { "<a href='#{pages.first}.html'>next →</a>" }
|
142
|
+
html.gsub!("{{content}}") { content }
|
125
143
|
|
126
144
|
File.write("html_out/index.html", html)
|
127
145
|
end
|
@@ -14,13 +14,5 @@ class Snaptoken::Commands::Fancy < Snaptoken::Commands::BaseCommand
|
|
14
14
|
exec("cat steps.diff | colordiff | diff-so-fancy | less --tabs=4 -RFX")
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def apply_diff(dir, diff)
|
21
|
-
stdin = IO.popen("git --git-dir= apply --directory=#{dir} -", "w")
|
22
|
-
stdin.write diff
|
23
|
-
stdin.close
|
24
|
-
end
|
25
17
|
end
|
26
18
|
|
@@ -34,7 +34,11 @@ class Snaptoken::Commands::Repo < Snaptoken::Commands::BaseCommand
|
|
34
34
|
options[:parents] = repo.empty? ? [] : [repo.head.target]
|
35
35
|
options[:update_ref] = 'HEAD'
|
36
36
|
|
37
|
-
Rugged::Commit.create(repo, options)
|
37
|
+
commit_oid = Rugged::Commit.create(repo, options)
|
38
|
+
|
39
|
+
if step_name(step)
|
40
|
+
repo.references.create("refs/tags/#{step_name(step)}", commit_oid)
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
44
|
repo.checkout_head(strategy: :force)
|
data/lib/snaptoken/diff.rb
CHANGED
@@ -3,14 +3,18 @@ class Snaptoken::Diff
|
|
3
3
|
|
4
4
|
attr_reader :files, :html
|
5
5
|
|
6
|
-
def initialize(step_a, step_b)
|
6
|
+
def initialize(config, step_a, step_b)
|
7
7
|
git_diff = `git diff #{GIT_DIFF_OPTIONS} #{step_a} #{step_b}`
|
8
8
|
parse_git_diff(git_diff)
|
9
9
|
@files.values.each(&:omit_adjacent_removals!)
|
10
10
|
|
11
|
+
step = step_b.split('-')
|
12
|
+
step.shift
|
13
|
+
step = step.join('-')
|
14
|
+
|
11
15
|
@html = {}
|
12
16
|
@files.each do |filename, file|
|
13
|
-
@html[filename] = file.to_html
|
17
|
+
@html[filename] = file.to_html(config[:name], step)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
@@ -96,7 +100,7 @@ class Snaptoken::Diff
|
|
96
100
|
end
|
97
101
|
end
|
98
102
|
|
99
|
-
def to_html
|
103
|
+
def to_html(project, step)
|
100
104
|
formatter = Rouge::Formatters::HTML.new
|
101
105
|
formatter = HTMLLineByLine.new(formatter)
|
102
106
|
|
@@ -105,7 +109,7 @@ class Snaptoken::Diff
|
|
105
109
|
|
106
110
|
html = ""
|
107
111
|
html << "<div class=\"diff\">\n"
|
108
|
-
html << "<div class=\"filename\">#{@filename}</div>\n"
|
112
|
+
html << "<div class=\"filename\"><a href=\"https://github.com/snaptoken/#{project}/blob/#{step}/#{@filename}\">#{@filename}</a></div>\n"
|
109
113
|
html << "<pre class=\"highlight\"><code>"
|
110
114
|
|
111
115
|
to_render = @contents.dup
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snaptoken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ruten
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|