ghwikitools 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.simplecov +8 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -1
- data/README.md +8 -2
- data/Rakefile +1 -1
- data/bin/{ghwikitools.rb → ghwikitools} +1 -1
- data/ghwikitools.gemspec +7 -2
- data/lib/ghwikitools.rb +3 -1
- data/lib/ghwikitools/command.rb +43 -80
- data/lib/ghwikitools/page.rb +94 -37
- data/lib/ghwikitools/version.rb +1 -1
- data/test/ghwiki/Page-markdown-1.md +3 -0
- data/test/ghwiki/Page-markdown-4.abc.ja.md +1 -0
- data/test/ghwiki/Page-markdown-snippets.md +17 -0
- data/test/ghwiki/_Sidebar.md +1 -0
- data/test/ghwiki/snippet/_Footer.md +1 -0
- data/test/ghwiki/snippet/{Header.md → _Header.md} +0 -0
- data/test/spec_command.rb +57 -0
- data/test/spec_ghwikitools.rb +2 -0
- data/test/spec_page.rb +119 -3
- data/test/spec_snippet.rb +4 -2
- metadata +86 -10
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in
|
3
|
+
# Specify your gem's dependencies in forwardablex.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
gem 'simplecov', :require => false, :group => :test
|
7
|
+
gem 'coveralls', :require => false, :group => :test
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
ghwikitools is a set of GitHub wiki management tools.
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/ghwikitools.png)](http://badge.fury.io/rb/ghwikitools) [![Build Status](https://travis-ci.org/keita/ghwikitools.png?branch=master)](https://travis-ci.org/keita/ghwikitools) [![Coverage Status](https://coveralls.io/repos/keita/ghwikitools/badge.png?branch=master)](https://coveralls.io/r/keita/ghwikitools) [![Code Climate](https://codeclimate.com/github/keita/ghwikitools.png)](https://codeclimate.com/github/keita/ghwikitools)
|
6
|
+
|
5
7
|
## Functions
|
6
8
|
|
7
9
|
- Snippets
|
@@ -63,9 +65,13 @@ This command shows all ghwikitools commands.
|
|
63
65
|
|
64
66
|
This command inserts header and footer metadata, and updates all snippets.
|
65
67
|
|
66
|
-
##
|
68
|
+
## Documentation
|
69
|
+
|
70
|
+
- [API Documentation](http://www.rubydoc.info/gems/ghwikitools/)
|
71
|
+
|
72
|
+
## License
|
67
73
|
|
68
|
-
ghwikitools is free software distributed under MIT
|
74
|
+
ghwikitools is free software distributed under MIT license.
|
69
75
|
|
70
76
|
## Contributing
|
71
77
|
|
data/Rakefile
CHANGED
data/ghwikitools.gemspec
CHANGED
@@ -19,9 +19,14 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.
|
22
|
+
spec.add_dependency "iso-639"
|
23
|
+
spec.add_dependency "thor"
|
24
|
+
spec.add_dependency "forwardablex"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
23
27
|
spec.add_development_dependency "rake"
|
24
28
|
spec.add_development_dependency "yard"
|
25
|
-
spec.add_development_dependency "redcarpet"
|
29
|
+
spec.add_development_dependency "redcarpet" unless RUBY_PLATFORM == 'java'
|
26
30
|
spec.add_development_dependency "bacon"
|
31
|
+
spec.add_development_dependency "temppath"
|
27
32
|
end
|
data/lib/ghwikitools.rb
CHANGED
data/lib/ghwikitools/command.rb
CHANGED
@@ -1,100 +1,63 @@
|
|
1
1
|
module GHWikiTools
|
2
2
|
# Command is a class for making sub commands of ghwikitools.
|
3
|
-
class Command
|
4
|
-
@table = Hash.new {|hash, key| abort("unknown command %s" % key)}
|
5
|
-
|
6
|
-
@toplevel_options = OptionParser.new.tap do |opt|
|
7
|
-
opt.on("--help") do
|
8
|
-
@table[:list].new([]).run
|
9
|
-
exit
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
3
|
+
class Command < Thor
|
13
4
|
class << self
|
14
|
-
|
15
|
-
|
5
|
+
attr_accessor :test_mode
|
6
|
+
end
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
no_commands do
|
9
|
+
forward :class, :test_mode
|
10
|
+
end
|
20
11
|
|
21
|
-
|
22
|
-
|
23
|
-
# @param name [Symbol]
|
24
|
-
# command name
|
25
|
-
# @return [void]
|
26
|
-
def command(name)
|
27
|
-
Command.table[name] = self
|
28
|
-
end
|
12
|
+
class_option :help, :type => :boolean, :aliases => '-h', :desc => 'show help message'
|
13
|
+
class_option :directory, :type => :string, :aliases => '-d', :desc => "repository directory path", :banner => "DIR"
|
29
14
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def describe(msg)
|
36
|
-
@description = msg
|
15
|
+
desc "delete_snippet NAME", "Delete snippet metadata"
|
16
|
+
def delete_snippet(name)
|
17
|
+
if options[:directory]
|
18
|
+
puts "repositoy: %s" % options[:directory]
|
19
|
+
GHWikiTools.dir = options[:directory]
|
37
20
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# @param argv [Array<String>]
|
42
|
-
# command arguments
|
43
|
-
# @return [Command]
|
44
|
-
# subcommand
|
45
|
-
def get(argv)
|
46
|
-
@toplevel_options.order!(argv).tap do |_argv|
|
47
|
-
name, _argv = _argv
|
48
|
-
if name
|
49
|
-
return Command.table[name.to_sym].new(_argv)
|
50
|
-
else
|
51
|
-
@table[:list].new([]).run
|
52
|
-
exit
|
53
|
-
end
|
21
|
+
GHWikiTools::Page.all.each do |page|
|
22
|
+
if page.delete_snippet(name)
|
23
|
+
puts 'deleted snippet "%s" in the page %s' % [name, page.name]
|
54
24
|
end
|
55
|
-
rescue => e
|
56
|
-
abort(e.message)
|
57
25
|
end
|
58
26
|
end
|
59
27
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
28
|
+
desc "update", "Update header, footer, and other snippets"
|
29
|
+
def update
|
30
|
+
if options[:directory]
|
31
|
+
puts "repositoy: %s" % options[:directory]
|
32
|
+
GHWikiTools.dir = options[:directory]
|
33
|
+
end
|
34
|
+
GHWikiTools::Page.all.each do |page|
|
35
|
+
if page.insert_header
|
36
|
+
puts 'insert "Header" snippet metadata in the page "%s"' % page.wikiname
|
37
|
+
end
|
38
|
+
if page.insert_footer
|
39
|
+
puts 'insert "Footer" snippet metadata in the page "%s"' % page.wikiname
|
40
|
+
end
|
41
|
+
if page.update_snippets
|
42
|
+
puts 'update snippets in the page "%s"' % page.wikiname
|
43
|
+
end
|
44
|
+
end
|
71
45
|
end
|
72
|
-
end
|
73
46
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
Command.table.keys.each do |key|
|
82
|
-
puts " %-10s %s" % [key, Command.table[key].description]
|
47
|
+
no_commands do
|
48
|
+
define_method(:invoke_command) do |command, *args|
|
49
|
+
if options[:help]
|
50
|
+
Command.task_help(shell, command.name)
|
51
|
+
else
|
52
|
+
super(command, *args)
|
53
|
+
end
|
83
54
|
end
|
84
55
|
end
|
85
|
-
end
|
86
56
|
|
87
|
-
|
88
|
-
class CommandUpdate < Command
|
89
|
-
command :update
|
90
|
-
describe "update header, footer, and other snippets"
|
57
|
+
private
|
91
58
|
|
92
|
-
def
|
93
|
-
|
94
|
-
page.insert_header
|
95
|
-
page.insert_footer
|
96
|
-
page.update_snippets
|
97
|
-
end
|
59
|
+
def puts(*args)
|
60
|
+
Kernel.puts(*args) unless test_mode
|
98
61
|
end
|
99
62
|
end
|
100
63
|
end
|
data/lib/ghwikitools/page.rb
CHANGED
@@ -12,7 +12,7 @@ module GHWikiTools
|
|
12
12
|
# @return [Array<Page>]
|
13
13
|
# all pages
|
14
14
|
def all
|
15
|
-
Pathname.new(dir).entries.map do |entry|
|
15
|
+
Pathname.new(dir).entries.select{|e| (dir + e).file?}.map do |entry|
|
16
16
|
by_filename(entry.to_s)
|
17
17
|
end.select {|page| page.valid?}
|
18
18
|
end
|
@@ -24,8 +24,8 @@ module GHWikiTools
|
|
24
24
|
# @return [Page]
|
25
25
|
# the page
|
26
26
|
def by_filename(filename)
|
27
|
-
|
28
|
-
basename, lang, ext = parse_filename(filename)
|
27
|
+
raise ArgumentError.new(filename) unless filename.include?(".")
|
28
|
+
path, basename, lang, ext = parse_filename(filename)
|
29
29
|
new(path, basename, lang, ext)
|
30
30
|
end
|
31
31
|
|
@@ -39,11 +39,21 @@ module GHWikiTools
|
|
39
39
|
# basename(String), language name(Symbol), and extensiton(Symbol)
|
40
40
|
def parse_filename(filename)
|
41
41
|
filename.split(".").tap do |array|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
# extension
|
43
|
+
ext = array[-1].to_sym
|
44
|
+
|
45
|
+
# language
|
46
|
+
lang = array[-2].to_sym if array.size >= 3 and ISO_639.find(array[-2])
|
47
|
+
|
48
|
+
# basename
|
49
|
+
basename = (lang ? array[0..-3] : array[0..-2]).join(".").tap do |name|
|
50
|
+
break (name[0] == "_" and self == Snippet) ? name[1..-1] : name
|
51
|
+
end
|
52
|
+
|
53
|
+
# path
|
54
|
+
path = dir + filename
|
55
|
+
|
56
|
+
return path, basename, lang, ext
|
47
57
|
end
|
48
58
|
end
|
49
59
|
end
|
@@ -95,40 +105,50 @@ module GHWikiTools
|
|
95
105
|
|
96
106
|
# Insert a header snippet metadata.
|
97
107
|
#
|
98
|
-
# @return [
|
108
|
+
# @return [Boolean]
|
109
|
+
# true if header metadata was inserted
|
99
110
|
def insert_header
|
100
|
-
|
101
|
-
unless find_snippet_metadata.include?("Header")
|
102
|
-
content = @path.read
|
103
|
-
header = "<!-- >>> Header -->\n\n<!-- <<< Header -->\n\n"
|
104
|
-
@path.open("w+") do |f|
|
105
|
-
f.write(header + content)
|
106
|
-
end
|
107
|
-
end
|
111
|
+
insert_common_snippet("Header", :top)
|
108
112
|
end
|
109
113
|
|
110
114
|
# Insert a footer snippet metadata.
|
111
115
|
#
|
112
|
-
# @return [
|
116
|
+
# @return [Boolean]
|
117
|
+
# true if footer metadata was inserted
|
113
118
|
def insert_footer
|
114
|
-
|
115
|
-
content = @path.read
|
116
|
-
footer = "\n\n<!-- >>> Footer -->\n\n<!-- <<< Footer -->"
|
117
|
-
@path.open("w+") do |f|
|
118
|
-
f.write(content + footer)
|
119
|
-
end
|
120
|
-
end
|
119
|
+
insert_common_snippet("Footer", :bottom)
|
121
120
|
end
|
122
121
|
|
123
|
-
#
|
122
|
+
# Update sinppets content in the page. Return true if the page is changed.
|
124
123
|
#
|
125
|
-
# @return [
|
124
|
+
# @return [Boolean]
|
125
|
+
# true if the page is changed
|
126
126
|
def update_snippets
|
127
127
|
if content = render_snippets
|
128
128
|
unless content == @path.read
|
129
129
|
@path.open("w+") {|f| f.write(content)}
|
130
|
+
return true
|
130
131
|
end
|
131
132
|
end
|
133
|
+
return false
|
134
|
+
end
|
135
|
+
|
136
|
+
# Delete the snippet metadata from the page. Return true if the page is changed.
|
137
|
+
#
|
138
|
+
# @param name [String]
|
139
|
+
# snippet name
|
140
|
+
# @return [Boolean]
|
141
|
+
# true if the page is changed
|
142
|
+
def delete_snippet(name)
|
143
|
+
if find_snippet_metadata.include?(name)
|
144
|
+
content = @path.read
|
145
|
+
new_content = content.gsub(snippet_regexp(name), "")
|
146
|
+
unless content == new_content
|
147
|
+
@path.open("w+") {|f| f.write(new_content)}
|
148
|
+
return true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
return false
|
132
152
|
end
|
133
153
|
|
134
154
|
# Return the result of rendering snippets.
|
@@ -141,12 +161,59 @@ module GHWikiTools
|
|
141
161
|
content.gsub(snippet_regexp(snippet.name)) do
|
142
162
|
"%s\n\n%s\n\n%s" % [$1, snippet.render(self), $3]
|
143
163
|
end
|
164
|
+
else
|
165
|
+
content
|
144
166
|
end
|
145
167
|
end
|
146
168
|
end
|
147
169
|
|
170
|
+
# Return snippets in the page.
|
171
|
+
#
|
172
|
+
# @return [Array<Snippet>]
|
173
|
+
# snippets in the page
|
174
|
+
def find_snippets
|
175
|
+
find_snippet_metadata.map do |name|
|
176
|
+
Snippet.by_filename("_%s.%s" % [name, @ext])
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# Return true if the page includes snippet metadata that have the name.
|
181
|
+
#
|
182
|
+
# @param [String]
|
183
|
+
# snippet name
|
184
|
+
# @return [Boolean]
|
185
|
+
# true if the page includes snippet metadata that have the name
|
186
|
+
def include_snippet?(name)
|
187
|
+
find_snippet_metadata.include?(name)
|
188
|
+
end
|
189
|
+
|
148
190
|
private
|
149
191
|
|
192
|
+
# Insert common snippet.
|
193
|
+
#
|
194
|
+
# @param name [String]
|
195
|
+
# snippet name
|
196
|
+
# @param pos [Symbol]
|
197
|
+
# :top or :bottom
|
198
|
+
# @return [Boolean]
|
199
|
+
# true if the snippet metadata was inserted.
|
200
|
+
def insert_common_snippet(name, pos)
|
201
|
+
return false if @name[0] == "_"
|
202
|
+
return false unless Snippet.by_filename("_%s.md" % name).path.exist?
|
203
|
+
unless find_snippet_metadata.include?(name)
|
204
|
+
metadata = "<!-- >>> %s -->\n\n<!-- <<< %s -->" % [name, name]
|
205
|
+
case pos
|
206
|
+
when :top
|
207
|
+
content = metadata + "\n\n" + @path.read
|
208
|
+
when :bottom
|
209
|
+
content = @path.read + "\n\n" + metadata
|
210
|
+
end
|
211
|
+
@path.open("w+") {|f| f.write(content)}
|
212
|
+
return true
|
213
|
+
end
|
214
|
+
return false
|
215
|
+
end
|
216
|
+
|
150
217
|
# Return a regexp of the named snippet.
|
151
218
|
#
|
152
219
|
# @param name [String]
|
@@ -164,15 +231,5 @@ module GHWikiTools
|
|
164
231
|
def find_snippet_metadata
|
165
232
|
@path.read.scan(/<!--\s*>>>\s*(.+?)\s*-->/).flatten.uniq
|
166
233
|
end
|
167
|
-
|
168
|
-
# Return snippets in the page.
|
169
|
-
#
|
170
|
-
# @return [Array<Snippet>]
|
171
|
-
# snippets in the page
|
172
|
-
def find_snippets
|
173
|
-
@path.read.scan(/<!--\s*>>>\s*(.+?)\s*-->/).flatten.uniq.map do |name|
|
174
|
-
Snippet.by_filename("%s.%s" % [name, @ext])
|
175
|
-
end
|
176
|
-
end
|
177
234
|
end
|
178
235
|
end
|
data/lib/ghwikitools/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
This is Page-markdown-4.ab.ja.md.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!-- >>> Header -->
|
2
|
+
|
3
|
+
<!-- <<< Header -->
|
4
|
+
|
5
|
+
<!-- >>> Snippet1 -->
|
6
|
+
<!-- <<< Snippet1 -->
|
7
|
+
|
8
|
+
<!-- >>> Snippet2 --><!-- <<< Snippet2 -->
|
9
|
+
|
10
|
+
<!-- >>> Snippet3 -->
|
11
|
+
|
12
|
+
|
13
|
+
<!-- <<< Snippet3 -->
|
14
|
+
|
15
|
+
<!-- >>> Footer -->
|
16
|
+
|
17
|
+
<!-- <<< Footer -->
|
@@ -0,0 +1 @@
|
|
1
|
+
This is a side bar.
|
@@ -0,0 +1 @@
|
|
1
|
+
This is a footer.
|
File without changes
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "ghwikitools"
|
2
|
+
require "temppath"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
include GHWikiTools
|
6
|
+
Command.test_mode = true
|
7
|
+
|
8
|
+
describe "GHWikiTools::Command" do
|
9
|
+
before do
|
10
|
+
Temppath.update_tempdir
|
11
|
+
FileUtils.cp_r(File.join(File.dirname(__FILE__), "ghwiki"), Temppath.dir)
|
12
|
+
GHWikiTools.dir = Temppath.dir + "ghwiki"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should update" do
|
16
|
+
Command.new.invoke("update")
|
17
|
+
Page.by_filename("Page-markdown-3.md").tap do |page|
|
18
|
+
page.should.include_snippet "Header"
|
19
|
+
page.should.include_snippet "Footer"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should update in specified directory" do
|
24
|
+
Temppath.update_tempdir
|
25
|
+
FileUtils.cp_r(File.join(File.dirname(__FILE__), "ghwiki"), Temppath.dir)
|
26
|
+
Command.new.invoke("update", nil, {directory: (Temppath.dir + "ghwiki").to_s})
|
27
|
+
Page.by_filename("Page-markdown-3.md").tap do |page|
|
28
|
+
page.should.include_snippet "Header"
|
29
|
+
page.should.include_snippet "Footer"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should delete snippet" do
|
34
|
+
Command.new.invoke("delete_snippet", ["Footer"])
|
35
|
+
Page.by_filename("Page-markdown-1.md").tap do |page|
|
36
|
+
page.should.include_snippet "Header"
|
37
|
+
page.should.not.include_snippet "Footer"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should delete snippet in specified directory" do
|
42
|
+
Temppath.update_tempdir
|
43
|
+
FileUtils.cp_r(File.join(File.dirname(__FILE__), "ghwiki"), Temppath.dir)
|
44
|
+
Command.new.invoke("delete_snippet", ["Footer"], {directory: (Temppath.dir + "ghwiki").to_s})
|
45
|
+
Page.by_filename("Page-markdown-1.md").tap do |page|
|
46
|
+
page.should.include_snippet "Header"
|
47
|
+
page.should.not.include_snippet "Footer"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should get help message with the option '--help'" do
|
52
|
+
should.not.raise do
|
53
|
+
command = Command.new([], {help: true, quiet: true}, {})
|
54
|
+
command.invoke(:update)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/test/spec_ghwikitools.rb
CHANGED
data/test/spec_page.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
|
2
|
+
require "ghwikitools"
|
3
|
+
require "temppath"
|
4
|
+
require "fileutils"
|
4
5
|
|
5
6
|
include GHWikiTools
|
6
7
|
|
7
8
|
describe "GHWikiTools::Page" do
|
9
|
+
before do
|
10
|
+
Temppath.update_tempdir
|
11
|
+
FileUtils.cp_r(File.join(File.dirname(__FILE__), "ghwiki"), Temppath.dir)
|
12
|
+
GHWikiTools.dir = Temppath.dir + "ghwiki"
|
13
|
+
end
|
14
|
+
|
8
15
|
it "should get all pages" do
|
9
16
|
Page.all.tap do |pages|
|
10
|
-
pages.size.should ==
|
17
|
+
pages.size.should == 7
|
11
18
|
wikinames = pages.map{|page| page.wikiname}.uniq
|
12
19
|
wikinames.should.include "Page-markdown-1"
|
13
20
|
wikinames.should.include "Page-markdown-2"
|
@@ -34,11 +41,35 @@ describe "GHWikiTools::Page" do
|
|
34
41
|
page.should.valid
|
35
42
|
end
|
36
43
|
|
44
|
+
it "should get language and extension" do
|
45
|
+
Page.by_filename("Page-markdown-4.abc.ja.md").tap do |page|
|
46
|
+
page.wikiname.should == "Page-markdown-4.abc"
|
47
|
+
page.lang.should == :ja
|
48
|
+
page.ext.should == :md
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
37
52
|
it "should get wikiname of the language" do
|
38
53
|
page = Page.by_filename("Page-markdown-1.md")
|
39
54
|
page.wikiname(:ja).should == "Page-markdown-1.ja"
|
40
55
|
end
|
41
56
|
|
57
|
+
it "should include snippets" do
|
58
|
+
Page.by_filename("Page-markdown-snippets.md").tap do |page|
|
59
|
+
page.should.include_snippet "Header"
|
60
|
+
page.should.include_snippet "Snippet1"
|
61
|
+
page.should.include_snippet "Snippet2"
|
62
|
+
page.should.include_snippet "Snippet3"
|
63
|
+
page.should.include_snippet "Footer"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should find snippets" do
|
68
|
+
page = Page.by_filename("Page-markdown-snippets.md")
|
69
|
+
snippets = page.find_snippets
|
70
|
+
snippets.size.should == 5
|
71
|
+
end
|
72
|
+
|
42
73
|
it 'should get the page content with inserting the header' do
|
43
74
|
page = Page.by_filename("Page-markdown-1.md")
|
44
75
|
page.render_snippets.should == <<TXT
|
@@ -49,6 +80,12 @@ Languages: [[English|Page-markdown-1]] | [[日本語|Page-markdown-1.ja]]
|
|
49
80
|
<!-- <<< Header -->
|
50
81
|
|
51
82
|
This is Page1.
|
83
|
+
|
84
|
+
<!-- >>> Footer -->
|
85
|
+
|
86
|
+
This is a footer.
|
87
|
+
|
88
|
+
<!-- <<< Footer -->
|
52
89
|
TXT
|
53
90
|
end
|
54
91
|
|
@@ -64,4 +101,83 @@ Languages: [[English|Page-markdown-2]] | [[日本語|Page-markdown-2.ja]]
|
|
64
101
|
This is Page2.
|
65
102
|
TXT
|
66
103
|
end
|
104
|
+
|
105
|
+
it 'should insert header' do
|
106
|
+
Page.by_filename("Page-markdown-3.md").tap do |page|
|
107
|
+
page.should.not.include_snippet "Header"
|
108
|
+
page.insert_header.should == true
|
109
|
+
page.should.include_snippet "Header"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should not insert header when header snippet file not found' do
|
114
|
+
Snippet.by_filename("_Header.md").path.delete
|
115
|
+
Page.by_filename("Page-markdown-3.md").tap do |page|
|
116
|
+
page.should.not.include_snippet "Header"
|
117
|
+
page.insert_header.should == false
|
118
|
+
page.should.not.include_snippet "Header"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should not insert header when header snippet exists already' do
|
123
|
+
Page.by_filename("Page-markdown-2.md").tap do |page|
|
124
|
+
page.should.include_snippet "Header"
|
125
|
+
page.insert_header.should == false
|
126
|
+
page.should.include_snippet "Header"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should insert footer' do
|
131
|
+
Page.by_filename("Page-markdown-3.md").tap do |page|
|
132
|
+
page.should.not.include_snippet "Footer"
|
133
|
+
page.insert_footer.should == true
|
134
|
+
page.should.include_snippet "Footer"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should not insert footer when footer snippet file not found' do
|
139
|
+
Snippet.by_filename("_Footer.md").path.delete
|
140
|
+
Page.by_filename("Page-markdown-3.md").tap do |page|
|
141
|
+
page.should.not.include_snippet "Footer"
|
142
|
+
page.insert_footer.should == false
|
143
|
+
page.should.not.include_snippet "Footer"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should not insert footer when footer snippet exists already' do
|
148
|
+
Page.by_filename("Page-markdown-1.md").tap do |page|
|
149
|
+
page.should.include_snippet "Footer"
|
150
|
+
page.insert_footer.should == false
|
151
|
+
page.should.include_snippet "Footer"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should update snippets' do
|
156
|
+
Page.by_filename("Page-markdown-2.md").tap do |page|
|
157
|
+
content = page.render_snippets
|
158
|
+
page.update_snippets.should == true
|
159
|
+
page.path.read.should == content
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should not update snippets' do
|
164
|
+
Page.by_filename("Page-markdown-3.md").tap do |page|
|
165
|
+
page.update_snippets.should == false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should delete snippet' do
|
170
|
+
Page.by_filename("Page-markdown-2.md").tap do |page|
|
171
|
+
page.should.include_snippet "Header"
|
172
|
+
page.delete_snippet("Header").should == true
|
173
|
+
page.should.not.include_snippet "Header"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should delete snippet' do
|
178
|
+
Page.by_filename("Page-markdown-2.md").tap do |page|
|
179
|
+
page.should.not.include_snippet "Footer"
|
180
|
+
page.delete_snippet("Footer").should == false
|
181
|
+
end
|
182
|
+
end
|
67
183
|
end
|
data/test/spec_snippet.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require "ghwikitools"
|
2
3
|
|
3
4
|
GHWikiTools.dir = File.join(File.dirname(__FILE__), "ghwiki")
|
4
5
|
|
@@ -7,15 +8,16 @@ include GHWikiTools
|
|
7
8
|
describe "GHWikiTools::Snippet" do
|
8
9
|
it "should get all snippets" do
|
9
10
|
Snippet.all.tap do |snippets|
|
10
|
-
snippets.size.should ==
|
11
|
+
snippets.size.should == 2
|
11
12
|
names = snippets.map{|snippet| snippet.name}.uniq
|
12
13
|
names.should.include "Header"
|
14
|
+
names.should.include "Footer"
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
18
|
it "should render the snippet content with page informations" do
|
17
19
|
page = Page.by_filename("Page-markdown-1.md")
|
18
|
-
snippet = Snippet.by_filename("
|
20
|
+
snippet = Snippet.by_filename("_Header.md")
|
19
21
|
snippet.render(page).should ==
|
20
22
|
"Languages: [[English|Page-markdown-1]] | [[日本語|Page-markdown-1.ja]]"
|
21
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghwikitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,72 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: iso-639
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: thor
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: forwardablex
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
14
62
|
- !ruby/object:Gem::Dependency
|
15
63
|
name: bundler
|
16
64
|
requirement: !ruby/object:Gem::Requirement
|
17
65
|
none: false
|
18
66
|
requirements:
|
19
|
-
- -
|
67
|
+
- - ! '>='
|
20
68
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
69
|
+
version: '0'
|
22
70
|
type: :development
|
23
71
|
prerelease: false
|
24
72
|
version_requirements: !ruby/object:Gem::Requirement
|
25
73
|
none: false
|
26
74
|
requirements:
|
27
|
-
- -
|
75
|
+
- - ! '>='
|
28
76
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
77
|
+
version: '0'
|
30
78
|
- !ruby/object:Gem::Dependency
|
31
79
|
name: rake
|
32
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,20 +139,38 @@ dependencies:
|
|
91
139
|
- - ! '>='
|
92
140
|
- !ruby/object:Gem::Version
|
93
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: temppath
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
94
158
|
description: GitHub wiki management tools.
|
95
159
|
email:
|
96
160
|
- keita.yamaguchi@gmail.com
|
97
161
|
executables:
|
98
|
-
- ghwikitools
|
162
|
+
- ghwikitools
|
99
163
|
extensions: []
|
100
164
|
extra_rdoc_files: []
|
101
165
|
files:
|
102
166
|
- .gitignore
|
167
|
+
- .simplecov
|
168
|
+
- .travis.yml
|
103
169
|
- Gemfile
|
104
170
|
- LICENSE.txt
|
105
171
|
- README.md
|
106
172
|
- Rakefile
|
107
|
-
- bin/ghwikitools
|
173
|
+
- bin/ghwikitools
|
108
174
|
- ghwikitools.gemspec
|
109
175
|
- lib/ghwikitools.rb
|
110
176
|
- lib/ghwikitools/command.rb
|
@@ -115,8 +181,13 @@ files:
|
|
115
181
|
- test/ghwiki/Page-markdown-1.md
|
116
182
|
- test/ghwiki/Page-markdown-2.md
|
117
183
|
- test/ghwiki/Page-markdown-3.md
|
184
|
+
- test/ghwiki/Page-markdown-4.abc.ja.md
|
185
|
+
- test/ghwiki/Page-markdown-snippets.md
|
186
|
+
- test/ghwiki/_Sidebar.md
|
118
187
|
- test/ghwiki/not-page.txt
|
119
|
-
- test/ghwiki/snippet/
|
188
|
+
- test/ghwiki/snippet/_Footer.md
|
189
|
+
- test/ghwiki/snippet/_Header.md
|
190
|
+
- test/spec_command.rb
|
120
191
|
- test/spec_ghwikitools.rb
|
121
192
|
- test/spec_page.rb
|
122
193
|
- test/spec_snippet.rb
|
@@ -150,8 +221,13 @@ test_files:
|
|
150
221
|
- test/ghwiki/Page-markdown-1.md
|
151
222
|
- test/ghwiki/Page-markdown-2.md
|
152
223
|
- test/ghwiki/Page-markdown-3.md
|
224
|
+
- test/ghwiki/Page-markdown-4.abc.ja.md
|
225
|
+
- test/ghwiki/Page-markdown-snippets.md
|
226
|
+
- test/ghwiki/_Sidebar.md
|
153
227
|
- test/ghwiki/not-page.txt
|
154
|
-
- test/ghwiki/snippet/
|
228
|
+
- test/ghwiki/snippet/_Footer.md
|
229
|
+
- test/ghwiki/snippet/_Header.md
|
230
|
+
- test/spec_command.rb
|
155
231
|
- test/spec_ghwikitools.rb
|
156
232
|
- test/spec_page.rb
|
157
233
|
- test/spec_snippet.rb
|