ghwikitools 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/Rakefile +16 -0
- data/bin/ghwikitools.rb +7 -0
- data/ghwikitools.gemspec +27 -0
- data/lib/ghwikitools.rb +42 -0
- data/lib/ghwikitools/command.rb +100 -0
- data/lib/ghwikitools/page.rb +178 -0
- data/lib/ghwikitools/snippet.rb +48 -0
- data/lib/ghwikitools/version.rb +4 -0
- data/test/ghwiki/Page-markdown-1.ja.md +4 -0
- data/test/ghwiki/Page-markdown-1.md +4 -0
- data/test/ghwiki/Page-markdown-2.md +3 -0
- data/test/ghwiki/Page-markdown-3.md +3 -0
- data/test/ghwiki/not-page.txt +1 -0
- data/test/ghwiki/snippet/Header.md +1 -0
- data/test/spec_ghwikitools.rb +8 -0
- data/test/spec_page.rb +67 -0
- data/test/spec_snippet.rb +22 -0
- metadata +158 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Keita Yamaguchi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# ghwikitools
|
2
|
+
|
3
|
+
ghwikitools is a set of GitHub wiki management tools.
|
4
|
+
|
5
|
+
## Functions
|
6
|
+
|
7
|
+
- Snippets
|
8
|
+
- Internationalization
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
gem install ghwikitools
|
13
|
+
|
14
|
+
## Snippets
|
15
|
+
|
16
|
+
Snippets are re-usage texts. For example, there is a page("Test.md") with metadata that is formed as two Markdown comments.
|
17
|
+
|
18
|
+
<!-- >>> Header -->
|
19
|
+
|
20
|
+
<!-- <<< Header -->
|
21
|
+
|
22
|
+
This is a page.
|
23
|
+
|
24
|
+
This page embeds "Header" snippet. The snippet is written as ERB file at "snippet/Header.md" in the GitHub wiki cloned repository.
|
25
|
+
|
26
|
+
This is a header of [[<%= @page.wikiname %>]].
|
27
|
+
|
28
|
+
ghwikitools updates the page as follows:
|
29
|
+
|
30
|
+
<!-- >>> Header -->
|
31
|
+
|
32
|
+
This is a header of [[Test]].
|
33
|
+
|
34
|
+
<!-- <<< Header -->
|
35
|
+
|
36
|
+
This is a page.
|
37
|
+
|
38
|
+
There are header and footer snippets as default. You can make snippets as you like.
|
39
|
+
|
40
|
+
### Internationalization
|
41
|
+
|
42
|
+
GitHub wiki doesn't support internationalization directly, but you can use ghwikitools as internationalization system. This can do with the following convenstion:
|
43
|
+
|
44
|
+
- wikiname with language code like "Test.ja" is Japanese version of "Test" page
|
45
|
+
- make Header snippet as language links
|
46
|
+
- you update wiki pages with ghwikitools when new pages are appended
|
47
|
+
|
48
|
+
Header file is written like this:
|
49
|
+
|
50
|
+
Languages: [[English|<%= @page.wikiname %>]] | [[日本語|<%= @page.wikiname(:ja) %>]]
|
51
|
+
|
52
|
+
## Usage
|
53
|
+
|
54
|
+
### List
|
55
|
+
|
56
|
+
ghwikitools list
|
57
|
+
|
58
|
+
This command shows all ghwikitools commands.
|
59
|
+
|
60
|
+
### Update
|
61
|
+
|
62
|
+
ghwikitools update
|
63
|
+
|
64
|
+
This command inserts header and footer metadata, and updates all snippets.
|
65
|
+
|
66
|
+
## Licence
|
67
|
+
|
68
|
+
ghwikitools is free software distributed under MIT licence.
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc 'Test specs'
|
4
|
+
task 'test' do
|
5
|
+
sh "bundle exec bacon -a -r ghwikitools"
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Generate API document'
|
9
|
+
task 'html' do
|
10
|
+
sh "bundle exec yard doc -o html --hide-void-return --no-api"
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Show undocumented function list'
|
14
|
+
task 'html:undoc' do
|
15
|
+
sh "bundle exec yard stats --list-undoc --no-api --compact"
|
16
|
+
end
|
data/bin/ghwikitools.rb
ADDED
data/ghwikitools.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# coding: utf-8
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'ghwikitools/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "ghwikitools"
|
9
|
+
spec.version = GHWikiTools::VERSION
|
10
|
+
spec.authors = ["Keita Yamaguchi"]
|
11
|
+
spec.email = ["keita.yamaguchi@gmail.com"]
|
12
|
+
spec.description = "GitHub wiki management tools."
|
13
|
+
spec.summary = "GitHub wiki management tools."
|
14
|
+
spec.homepage = "https://github.com/keita/ghwikitools"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "yard"
|
25
|
+
spec.add_development_dependency "redcarpet"
|
26
|
+
spec.add_development_dependency "bacon"
|
27
|
+
end
|
data/lib/ghwikitools.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "erb"
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
require "ghwikitools/version"
|
6
|
+
require "ghwikitools/page"
|
7
|
+
require "ghwikitools/snippet"
|
8
|
+
require "ghwikitools/command"
|
9
|
+
|
10
|
+
# GHWikiTools is a name space for ghwikitools library.
|
11
|
+
module GHWikiTools
|
12
|
+
# available extensions in GitHub wiki
|
13
|
+
EXTENSIONS = [
|
14
|
+
:asciidoc , # ASCIIDoc
|
15
|
+
:creole , # Creole
|
16
|
+
:md , # Markdown
|
17
|
+
:org , # Org Mode
|
18
|
+
:pod , # Pod
|
19
|
+
:rdoc , # RDoc
|
20
|
+
:rest , # ReStructuredText
|
21
|
+
:textile , # Textile
|
22
|
+
:mediawiki # MediaWiki
|
23
|
+
]
|
24
|
+
|
25
|
+
class << self
|
26
|
+
# @return [Pathname]
|
27
|
+
# path of GitHub wiki directory
|
28
|
+
attr_reader :dir
|
29
|
+
|
30
|
+
# Set GitHub wiki cloned directory.
|
31
|
+
#
|
32
|
+
# @param path [String,Pathname]
|
33
|
+
# path of GitHub wiki cloned directory
|
34
|
+
# @return [void]
|
35
|
+
def dir=(path)
|
36
|
+
@dir = Pathname.new(path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# default path
|
41
|
+
@dir = Pathname.new(".")
|
42
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module GHWikiTools
|
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
|
+
|
13
|
+
class << self
|
14
|
+
# @api private
|
15
|
+
attr_reader :table
|
16
|
+
|
17
|
+
# @return [String]
|
18
|
+
# description of the command
|
19
|
+
attr_reader :description
|
20
|
+
|
21
|
+
# Declare the command name.
|
22
|
+
#
|
23
|
+
# @param name [Symbol]
|
24
|
+
# command name
|
25
|
+
# @return [void]
|
26
|
+
def command(name)
|
27
|
+
Command.table[name] = self
|
28
|
+
end
|
29
|
+
|
30
|
+
# Describe the aim of the command.
|
31
|
+
#
|
32
|
+
# @param msg [String]
|
33
|
+
# message
|
34
|
+
# @return [void]
|
35
|
+
def describe(msg)
|
36
|
+
@description = msg
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get subcommand.
|
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
|
54
|
+
end
|
55
|
+
rescue => e
|
56
|
+
abort(e.message)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param argv [Array<String>]
|
61
|
+
# command arguments
|
62
|
+
def initialize(argv)
|
63
|
+
@argv = argv
|
64
|
+
end
|
65
|
+
|
66
|
+
# Run the command.
|
67
|
+
#
|
68
|
+
# @return [void]
|
69
|
+
def run
|
70
|
+
raise NotImplementedError
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# CommandList provides the definition of "ghwikitools list".
|
75
|
+
class CommandList < Command
|
76
|
+
command :list
|
77
|
+
describe "print all commands"
|
78
|
+
|
79
|
+
def run
|
80
|
+
puts "commands:"
|
81
|
+
Command.table.keys.each do |key|
|
82
|
+
puts " %-10s %s" % [key, Command.table[key].description]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# CommandUpdate provides the definition of "ghwikitools update".
|
88
|
+
class CommandUpdate < Command
|
89
|
+
command :update
|
90
|
+
describe "update header, footer, and other snippets"
|
91
|
+
|
92
|
+
def run
|
93
|
+
GHWikiTools::Page.all.each do |page|
|
94
|
+
page.insert_header
|
95
|
+
page.insert_footer
|
96
|
+
page.update_snippets
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
module GHWikiTools
|
2
|
+
# Page is a class for wiki pages.
|
3
|
+
class Page
|
4
|
+
class << self
|
5
|
+
# Return pages directory.
|
6
|
+
def dir
|
7
|
+
GHWikiTools.dir
|
8
|
+
end
|
9
|
+
|
10
|
+
# Return all pages in the wiki.
|
11
|
+
#
|
12
|
+
# @return [Array<Page>]
|
13
|
+
# all pages
|
14
|
+
def all
|
15
|
+
Pathname.new(dir).entries.map do |entry|
|
16
|
+
by_filename(entry.to_s)
|
17
|
+
end.select {|page| page.valid?}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a page by the filename.
|
21
|
+
#
|
22
|
+
# @param filename [String]
|
23
|
+
# the filename
|
24
|
+
# @return [Page]
|
25
|
+
# the page
|
26
|
+
def by_filename(filename)
|
27
|
+
path = dir + filename
|
28
|
+
basename, lang, ext = parse_filename(filename)
|
29
|
+
new(path, basename, lang, ext)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Parse the filename.
|
35
|
+
#
|
36
|
+
# @param filename [String]
|
37
|
+
# the filename
|
38
|
+
# @return [Array]
|
39
|
+
# basename(String), language name(Symbol), and extensiton(Symbol)
|
40
|
+
def parse_filename(filename)
|
41
|
+
filename.split(".").tap do |array|
|
42
|
+
basename = array[0]
|
43
|
+
lang = array[1].to_sym if array.size == 3
|
44
|
+
ext = lang ? array[2] : array[1]
|
45
|
+
ext = ext.to_sym if ext
|
46
|
+
return basename, lang, ext
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @param [Pathname]
|
52
|
+
# path of the page
|
53
|
+
attr_reader :path
|
54
|
+
|
55
|
+
# @param [String]
|
56
|
+
# name of the page
|
57
|
+
attr_reader :name
|
58
|
+
|
59
|
+
# @param [String]
|
60
|
+
# language name of the page
|
61
|
+
attr_reader :lang
|
62
|
+
|
63
|
+
# @param [String]
|
64
|
+
# extension of the page
|
65
|
+
attr_reader :ext
|
66
|
+
|
67
|
+
# @param path [Pathname]
|
68
|
+
# page file path
|
69
|
+
# @param name [String]
|
70
|
+
# name
|
71
|
+
# @param lang [Symbol]
|
72
|
+
# language name
|
73
|
+
# @param ext [Symbol]
|
74
|
+
# extension name
|
75
|
+
def initialize(path, name, lang, ext)
|
76
|
+
@path = path
|
77
|
+
@name = name
|
78
|
+
@lang = lang
|
79
|
+
@ext = ext
|
80
|
+
end
|
81
|
+
|
82
|
+
# Return true if the page is valid in the meaning of this tools.
|
83
|
+
#
|
84
|
+
# @return [Boolean]
|
85
|
+
# true if the page is valid
|
86
|
+
def valid?
|
87
|
+
return false unless EXTENSIONS.include?(@ext) and @path.file? and @path.exist?
|
88
|
+
return true
|
89
|
+
end
|
90
|
+
|
91
|
+
# Return the wikiname of the page with lang
|
92
|
+
def wikiname(lang=nil)
|
93
|
+
lang ? "%s.%s" % [@name, lang] : @name
|
94
|
+
end
|
95
|
+
|
96
|
+
# Insert a header snippet metadata.
|
97
|
+
#
|
98
|
+
# @return [void]
|
99
|
+
def insert_header
|
100
|
+
return if @name[0] == "_"
|
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
|
108
|
+
end
|
109
|
+
|
110
|
+
# Insert a footer snippet metadata.
|
111
|
+
#
|
112
|
+
# @return [void]
|
113
|
+
def insert_footer
|
114
|
+
unless find_snippet_metadata.include?("Footer")
|
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
|
121
|
+
end
|
122
|
+
|
123
|
+
# Insert a footer snippet metadata.
|
124
|
+
#
|
125
|
+
# @return [void]
|
126
|
+
def update_snippets
|
127
|
+
if content = render_snippets
|
128
|
+
unless content == @path.read
|
129
|
+
@path.open("w+") {|f| f.write(content)}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Return the result of rendering snippets.
|
135
|
+
#
|
136
|
+
# @return [String]
|
137
|
+
# result of rendering snippets
|
138
|
+
def render_snippets
|
139
|
+
find_snippets.inject(@path.read) do |content, snippet|
|
140
|
+
if snippet.valid?
|
141
|
+
content.gsub(snippet_regexp(snippet.name)) do
|
142
|
+
"%s\n\n%s\n\n%s" % [$1, snippet.render(self), $3]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
# Return a regexp of the named snippet.
|
151
|
+
#
|
152
|
+
# @param name [String]
|
153
|
+
# snippet's name
|
154
|
+
# @return [Regexp]
|
155
|
+
# regexp that matches snippet metadata
|
156
|
+
def snippet_regexp(name)
|
157
|
+
/(<!--\s*>>>\s*#{name}\s*-->)(.*?)(<!--\s*<<<\s*#{name}\s*-->)/m
|
158
|
+
end
|
159
|
+
|
160
|
+
# Return snippets in the page.
|
161
|
+
#
|
162
|
+
# @return [Array<Snippet>]
|
163
|
+
# snippets in the page
|
164
|
+
def find_snippet_metadata
|
165
|
+
@path.read.scan(/<!--\s*>>>\s*(.+?)\s*-->/).flatten.uniq
|
166
|
+
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
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module GHWikiTools
|
2
|
+
# Snippet is a small block text of wiki page.
|
3
|
+
class Snippet < Page
|
4
|
+
class << self
|
5
|
+
# Return snippetss directory.
|
6
|
+
def dir
|
7
|
+
GHWikiTools.dir + "snippet"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Render the snippet with the page.
|
12
|
+
#
|
13
|
+
# @param page [Page]
|
14
|
+
# the page that the snippet embeds in it
|
15
|
+
def render(page)
|
16
|
+
ERB.new(@path.read, nil, 2).result(SnippetContext.create(page))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# SnippetContext provides snippet rendering informations.
|
21
|
+
class SnippetContext
|
22
|
+
class << self
|
23
|
+
# Return the context as binding object.
|
24
|
+
#
|
25
|
+
# @param page [Page]
|
26
|
+
# the page that the snippet embeds in it
|
27
|
+
# @return [Binding]
|
28
|
+
# snippet context as binding object
|
29
|
+
def create(page)
|
30
|
+
new(page).binding
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param page [Page]
|
35
|
+
# the page that the snippet embeds in it
|
36
|
+
def initialize(page)
|
37
|
+
@page = page
|
38
|
+
end
|
39
|
+
|
40
|
+
# Return the environment binding object.
|
41
|
+
#
|
42
|
+
# @return [Binding]
|
43
|
+
# the environment binding object
|
44
|
+
def binding
|
45
|
+
Kernel.binding
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
This is not a GitHub wiki page.
|
@@ -0,0 +1 @@
|
|
1
|
+
Languages: [[English|<%= @page.wikiname %>]] | [[日本語|<%= @page.wikiname(:ja) %>]]
|
@@ -0,0 +1,8 @@
|
|
1
|
+
GHWikiTools.dir = File.join(File.dirname(__FILE__), "ghwiki")
|
2
|
+
|
3
|
+
describe "GHWikiTools" do
|
4
|
+
it "should get GitHub wiki directory" do
|
5
|
+
GHWikiTools.dir.should.kind_of Pathname
|
6
|
+
GHWikiTools.dir.should == Pathname.new(File.join(File.dirname(__FILE__), "ghwiki"))
|
7
|
+
end
|
8
|
+
end
|
data/test/spec_page.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
GHWikiTools.dir = File.join(File.dirname(__FILE__), "ghwiki")
|
4
|
+
|
5
|
+
include GHWikiTools
|
6
|
+
|
7
|
+
describe "GHWikiTools::Page" do
|
8
|
+
it "should get all pages" do
|
9
|
+
Page.all.tap do |pages|
|
10
|
+
pages.size.should == 4
|
11
|
+
wikinames = pages.map{|page| page.wikiname}.uniq
|
12
|
+
wikinames.should.include "Page-markdown-1"
|
13
|
+
wikinames.should.include "Page-markdown-2"
|
14
|
+
wikinames.should.include "Page-markdown-3"
|
15
|
+
wikinames.should.not.include "not-page"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should get a page by the filename" do
|
20
|
+
page = Page.by_filename("Page-markdown-1.md")
|
21
|
+
page.should.kind_of Page
|
22
|
+
page.wikiname.should == "Page-markdown-1"
|
23
|
+
page.lang.should.nil
|
24
|
+
page.ext.should == :md
|
25
|
+
page.should.valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should get a Japanese page by the filename" do
|
29
|
+
page = Page.by_filename("Page-markdown-1.ja.md")
|
30
|
+
page.should.kind_of Page
|
31
|
+
page.wikiname.should == "Page-markdown-1"
|
32
|
+
page.lang.should == :ja
|
33
|
+
page.ext.should == :md
|
34
|
+
page.should.valid
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should get wikiname of the language" do
|
38
|
+
page = Page.by_filename("Page-markdown-1.md")
|
39
|
+
page.wikiname(:ja).should == "Page-markdown-1.ja"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should get the page content with inserting the header' do
|
43
|
+
page = Page.by_filename("Page-markdown-1.md")
|
44
|
+
page.render_snippets.should == <<TXT
|
45
|
+
<!-- >>> Header -->
|
46
|
+
|
47
|
+
Languages: [[English|Page-markdown-1]] | [[日本語|Page-markdown-1.ja]]
|
48
|
+
|
49
|
+
<!-- <<< Header -->
|
50
|
+
|
51
|
+
This is Page1.
|
52
|
+
TXT
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should get the page content with updating the header' do
|
56
|
+
page = Page.by_filename("Page-markdown-2.md")
|
57
|
+
page.render_snippets.should == <<TXT
|
58
|
+
<!-- >>> Header -->
|
59
|
+
|
60
|
+
Languages: [[English|Page-markdown-2]] | [[日本語|Page-markdown-2.ja]]
|
61
|
+
|
62
|
+
<!-- <<< Header -->
|
63
|
+
|
64
|
+
This is Page2.
|
65
|
+
TXT
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
GHWikiTools.dir = File.join(File.dirname(__FILE__), "ghwiki")
|
4
|
+
|
5
|
+
include GHWikiTools
|
6
|
+
|
7
|
+
describe "GHWikiTools::Snippet" do
|
8
|
+
it "should get all snippets" do
|
9
|
+
Snippet.all.tap do |snippets|
|
10
|
+
snippets.size.should == 1
|
11
|
+
names = snippets.map{|snippet| snippet.name}.uniq
|
12
|
+
names.should.include "Header"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should render the snippet content with page informations" do
|
17
|
+
page = Page.by_filename("Page-markdown-1.md")
|
18
|
+
snippet = Snippet.by_filename("Header.md")
|
19
|
+
snippet.render(page).should ==
|
20
|
+
"Languages: [[English|Page-markdown-1]] | [[日本語|Page-markdown-1.ja]]"
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghwikitools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Keita Yamaguchi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
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: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: redcarpet
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bacon
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: GitHub wiki management tools.
|
95
|
+
email:
|
96
|
+
- keita.yamaguchi@gmail.com
|
97
|
+
executables:
|
98
|
+
- ghwikitools.rb
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/ghwikitools.rb
|
108
|
+
- ghwikitools.gemspec
|
109
|
+
- lib/ghwikitools.rb
|
110
|
+
- lib/ghwikitools/command.rb
|
111
|
+
- lib/ghwikitools/page.rb
|
112
|
+
- lib/ghwikitools/snippet.rb
|
113
|
+
- lib/ghwikitools/version.rb
|
114
|
+
- test/ghwiki/Page-markdown-1.ja.md
|
115
|
+
- test/ghwiki/Page-markdown-1.md
|
116
|
+
- test/ghwiki/Page-markdown-2.md
|
117
|
+
- test/ghwiki/Page-markdown-3.md
|
118
|
+
- test/ghwiki/not-page.txt
|
119
|
+
- test/ghwiki/snippet/Header.md
|
120
|
+
- test/spec_ghwikitools.rb
|
121
|
+
- test/spec_page.rb
|
122
|
+
- test/spec_snippet.rb
|
123
|
+
homepage: https://github.com/keita/ghwikitools
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.8.25
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: GitHub wiki management tools.
|
148
|
+
test_files:
|
149
|
+
- test/ghwiki/Page-markdown-1.ja.md
|
150
|
+
- test/ghwiki/Page-markdown-1.md
|
151
|
+
- test/ghwiki/Page-markdown-2.md
|
152
|
+
- test/ghwiki/Page-markdown-3.md
|
153
|
+
- test/ghwiki/not-page.txt
|
154
|
+
- test/ghwiki/snippet/Header.md
|
155
|
+
- test/spec_ghwikitools.rb
|
156
|
+
- test/spec_page.rb
|
157
|
+
- test/spec_snippet.rb
|
158
|
+
has_rdoc:
|