khaleesi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/LICENSE +22 -0
  4. data/bin/khaleesi +10 -0
  5. data/khaleesi.gemspec +18 -0
  6. data/lib/khaleesi.rb +12 -0
  7. data/lib/khaleesi/about.rb +23 -0
  8. data/lib/khaleesi/cli.rb +641 -0
  9. data/lib/khaleesi/generator.rb +635 -0
  10. data/test/khaleesi_commands_test.rb +50 -0
  11. data/test/khaleesi_test.rb +171 -0
  12. data/test/resources/java-samplecode +9 -0
  13. data/test/resources/test_parse_single_file.md +26 -0
  14. data/test/resources/test_parse_single_file_enable_linenumbers_result +25 -0
  15. data/test/resources/test_parse_single_file_without_linenumbers_result +20 -0
  16. data/test/resources/test_site/_decorators/basic.html +25 -0
  17. data/test/resources/test_site/_decorators/code_snippet.html +8 -0
  18. data/test/resources/test_site/_decorators/post.html +6 -0
  19. data/test/resources/test_site/_decorators/theme.html +15 -0
  20. data/test/resources/test_site/_pages/index.html +49 -0
  21. data/test/resources/test_site/_pages/javasmpcode.md +11 -0
  22. data/test/resources/test_site/_pages/posts/2013/netroid-introduction.md +11 -0
  23. data/test/resources/test_site/_pages/posts/2014/khaleesi-introduction.md +8 -0
  24. data/test/resources/test_site/_pages/studio/cameras/camera1.md +6 -0
  25. data/test/resources/test_site/_pages/studio/cameras/camera2.md +6 -0
  26. data/test/resources/test_site/_pages/studio/cameras/camera3.md +6 -0
  27. data/test/resources/test_site/_pages/studio/cameras/camera4.md +6 -0
  28. data/test/resources/test_site/_pages/themes/base16_solarized.md +119 -0
  29. data/test/resources/test_site/_pages/themes/base16_solarized_dark.md +117 -0
  30. data/test/resources/test_site/_pages/themes/github.md +272 -0
  31. data/test/resources/test_site/_pages/themes_illustrates/base16_solarized.html +4 -0
  32. data/test/resources/test_site/_pages/themes_illustrates/base16_solarized_dark.html +4 -0
  33. data/test/resources/test_site/_pages/themes_illustrates/github.html +4 -0
  34. data/test/resources/test_site/_pages/themes_illustrates/monokai.html +4 -0
  35. data/test/resources/test_site/_pages/themes_illustrates/monokai_sublime.html +4 -0
  36. data/test/resources/test_site/_raw/css/site.css +340 -0
  37. data/test/resources/test_site/expected_base16_solarized_dark_html +146 -0
  38. data/test/resources/test_site/expected_base16_solarized_html +150 -0
  39. data/test/resources/test_site/expected_github_html +301 -0
  40. data/test/resources/test_site/expected_index_html +373 -0
  41. metadata +86 -0
@@ -0,0 +1,50 @@
1
+ require 'test/unit'
2
+ require 'khaleesi'
3
+
4
+ class KhaleesiCommandsTest < Test::Unit::TestCase
5
+ def test_the_khaleesi_produce_command
6
+ result = %x[khaleesi produce resources/test_parse_single_file.md 2>&1]
7
+ assert result.end_with?(IO.read('resources/test_parse_single_file_without_linenumbers_result'))
8
+ end
9
+
10
+ def test_the_khaleesi_construction_command
11
+ site_name = 'mysite'
12
+ result = %x[khaleesi construction #{site_name} 2>&1]
13
+ assert result.start_with?('A sample site of Khaleesi was built in')
14
+ assert_equal Dir["#{site_name}/_decorators/*"].length, 2
15
+ assert_equal Dir["#{site_name}/_pages/**/*"].length, 6
16
+ assert_equal Dir["#{site_name}/_raw/**/*"].length, 3
17
+ assert_equal Dir["#{site_name}/**/*"].length, 16
18
+ %x[rm -fr #{site_name}]
19
+ end
20
+
21
+ def test_the_khaleesi_createpost_command
22
+ post_name = 'mypost'
23
+ result = %x[khaleesi createpost #{post_name} 2>&1]
24
+ assert result.start_with?('A post page was created')
25
+
26
+ post_name << '.md'
27
+ page_content = IO.read(post_name)
28
+ assert_match /^‡{6,}$/, page_content
29
+ assert_match /^identifier:\p{Blank}?\p{Alnum}{20}$/, page_content
30
+ %x[rm -fr #{post_name}]
31
+ end
32
+
33
+ def test_the_khaleesi_build_command
34
+ dst_dir = File.absolute_path('resources/test_site/gen_site')
35
+ src_dir = File.absolute_path('resources/test_site')
36
+
37
+ result = %x[khaleesi build --src-dir #{src_dir} --dest-dir #{dst_dir} 2>&1]
38
+ assert_match /^Done(.+)Generator time elapsed(.+)$/m, result
39
+
40
+ # examine various foreach logical's correctness.
41
+ assert_equal IO.read(dst_dir + '/index.html'), IO.read(src_dir + '/expected_index_html')
42
+
43
+ # examine chain logical's correctness.
44
+ assert_equal IO.read(dst_dir + '/themes/github.html'), IO.read(src_dir + '/expected_github_html') # only present next
45
+ assert_equal IO.read(dst_dir + '/themes/base16_solarized.html'), IO.read(src_dir + '/expected_base16_solarized_html') # present next and previous
46
+ assert_equal IO.read(dst_dir + '/themes/base16_solarized_dark.html'), IO.read(src_dir + '/expected_base16_solarized_dark_html') # only present previous
47
+
48
+ %x[rm -fr #{dst_dir}/*]
49
+ end
50
+ end
@@ -0,0 +1,171 @@
1
+ require 'test/unit'
2
+ require 'khaleesi'
3
+
4
+ class KhaleesiTest < Test::Unit::TestCase
5
+ def setup
6
+ @opts = {}
7
+ end
8
+
9
+
10
+ def test_parse_markdown_file_without_linenumbers
11
+ result = Khaleesi::Generator.new(@opts).parse_markdown_file('resources/test_parse_single_file.md')
12
+ assert_equal result.strip, IO.read('resources/test_parse_single_file_without_linenumbers_result')
13
+ end
14
+
15
+ def test_parse_markdown_file_enable_line_numbers
16
+ @opts[:line_numbers] = 'true'
17
+ result = Khaleesi::Generator.new(@opts).parse_markdown_file('resources/test_parse_single_file.md')
18
+ assert_equal result.strip, IO.read('resources/test_parse_single_file_enable_linenumbers_result')
19
+ end
20
+
21
+
22
+
23
+ def test_highlighting_code_snippet_without_linenumbers
24
+ highlighting_by_rouge = execute_highlighting
25
+
26
+ @opts[:highlighter] = 'pygments'
27
+ highlighting_by_pygments = execute_highlighting
28
+
29
+ # both highlighters share an identical structure.
30
+ regexp = /<div class="sourcecode java">(.{0,2})<pre>(.+?)<\/pre>(.{0,2})<\/div>/m
31
+ assert_match regexp, highlighting_by_pygments
32
+ assert_match regexp, highlighting_by_rouge
33
+ end
34
+
35
+ def execute_highlighting
36
+ @opts[:css_class] = 'sourcecode'
37
+ Khaleesi::Generator.new(@opts) # just for renew some global variables.
38
+ Khaleesi::Generator::HTML.new.block_code(IO.read('resources/java-samplecode'), 'java')
39
+ end
40
+
41
+ def test_highlighting_code_snippet_enable_linenumbers
42
+ @opts[:line_numbers] = 'true'
43
+ highlighting_by_rouge = execute_highlighting
44
+
45
+ @opts[:highlighter] = 'pygments'
46
+ highlighting_by_pygments = execute_highlighting
47
+
48
+ # both highlighters share an identical structure.
49
+ regexp = /<div class="sourcecode java">(.{0,2})<table><tr><td class="linenos"><pre>(.+?)<\/pre><\/td><td><pre>(.+)<\/pre>(.+)<\/table>(.{0,2})<\/div>/m
50
+ assert_match regexp, highlighting_by_pygments
51
+ assert_match regexp, highlighting_by_rouge
52
+ end
53
+
54
+
55
+
56
+ def test_generate_page_link
57
+ generator = Khaleesi::Generator.new(@opts)
58
+
59
+ page_path = "#{Dir.pwd}/_pages/posts/2014/khaleesi.html"
60
+
61
+ variables = "name : Khaleesi's introduction\nslug : index.html"
62
+ assert_nil generator.gen_link(page_path, variables)
63
+
64
+ variables = "title : Khaleesi's introduction\nslug : index.html"
65
+ assert_equal generator.gen_link(page_path, variables), '/posts/2014/index.html'
66
+
67
+ variables = "title : Khaleesi's introduction"
68
+ assert_equal generator.gen_link(page_path, variables), '/posts/2014/khaleesis-introduction.html'
69
+
70
+
71
+ page_path = "#{Dir.pwd}/_pages/posts/2014/khaleesi.md"
72
+ assert_equal generator.gen_link(page_path, variables), '/posts/2014/khaleesis-introduction.html'
73
+
74
+ variables = 'title : 一些事一些情'
75
+ assert_equal generator.gen_link(page_path, variables), '/posts/2014/khaleesi.html'
76
+
77
+ page_path = "#{Dir.pwd}/_pages/posts/2014/khaleesi.info.md"
78
+ assert_equal generator.gen_link(page_path, variables), '/posts/2014/khaleesi.info.html'
79
+
80
+ page_path = "#{Dir.pwd}/_pages/posts/2014/khaleesi.info.html"
81
+ assert_equal generator.gen_link(page_path, variables), '/posts/2014/khaleesi.info.html'
82
+ end
83
+
84
+
85
+
86
+ def test_format_as_legal_link
87
+ text = 'easily to know and switch the ellipsize mode of textview in Android'
88
+ Khaleesi::Generator.format_as_legal_link(text)
89
+ assert_equal text, 'easily-to-know-and-switch-the-ellipsize-mode-of-textview-in-android'
90
+
91
+ text = ' Android : is Google\'s OS for digital devices ---- stackoverflow '
92
+ Khaleesi::Generator.format_as_legal_link(text)
93
+ assert_equal text, 'android-is-googles-os-for-digital-devices-stackoverflow'
94
+
95
+ text = '一些事一些情'
96
+ Khaleesi::Generator.format_as_legal_link(text)
97
+ assert text.empty?
98
+ end
99
+
100
+
101
+
102
+ def test_header_anchor
103
+ $toc_index = 0
104
+
105
+ text = 'easily to know and switch the ellipsize mode of textview in Android'
106
+ assert_equal Khaleesi::Generator::HTML.new.header_anchor(text), 'easily-to-know-and-switch-the-ellipsize-mode-of-textview-in-android'
107
+
108
+ text = ' Android : is Google\'s OS for digital devices ---- stackoverflow '
109
+ assert_equal Khaleesi::Generator::HTML.new.header_anchor(text), 'android-is-googles-os-for-digital-devices-stackoverflow'
110
+
111
+ text = 'test &quot;unescaping&quot; &#60;&#233;lan&#62; I&#39;m working'
112
+ assert_equal Khaleesi::Generator::HTML.new.header_anchor(text), 'test-unescaping-im-working'
113
+
114
+ text = 'Install with <code>RubyGems</code>'
115
+ assert_equal Khaleesi::Generator::HTML.new.header_anchor(text), 'install-with-rubygems'
116
+
117
+ text = '一些事一些情'
118
+ assert_equal Khaleesi::Generator::HTML.new.header_anchor(text), 'header-1'
119
+
120
+ text = '一些事一些情 : 一些好音乐'
121
+ assert_equal Khaleesi::Generator::HTML.new.header_anchor(text), 'header-2'
122
+
123
+ text = ' 一些事一些情 : 一些好音乐 -- 双低 '
124
+ assert_equal Khaleesi::Generator::HTML.new.header_anchor(text), 'header-3'
125
+ end
126
+
127
+
128
+
129
+ def test_toc_header_generation
130
+ html = Khaleesi::Generator::HTML.new
131
+ title = 'Introduction of Kahleesi'
132
+ illegal_title = '一些事一些情'
133
+
134
+ $toc_index = 0
135
+ $toc_selection = ''
136
+ assert_equal html.header(title, 1), "\n<h1>#{title}</h1>\n"
137
+ assert_equal html.header(title, 2), "\n<h2>#{title}</h2>\n"
138
+ assert_equal html.header(title, 3), "\n<h3>#{title}</h3>\n"
139
+ assert_equal html.header(title, '4'), "\n<h4>#{title}</h4>\n"
140
+ assert_equal html.header(illegal_title, '4'), "\n<h4>#{illegal_title}</h4>\n"
141
+
142
+ $toc_index = 0
143
+ $toc_selection = 'h1,h3'
144
+ assert_equal html.header(title, '1'), "\n<h1 id=\"introduction-of-kahleesi\">#{title}</h1>\n"
145
+ assert_equal html.header(illegal_title, 1), "\n<h1 id=\"header-1\">#{illegal_title}</h1>\n"
146
+ assert_equal html.header(title, 2), "\n<h2>#{title}</h2>\n"
147
+ assert_equal html.header(title, 3), "\n<h3 id=\"introduction-of-kahleesi\">#{title}</h3>\n"
148
+ assert_equal html.header(illegal_title, '3'), "\n<h3 id=\"header-2\">#{illegal_title}</h3>\n"
149
+ assert_equal html.header(title, '4'), "\n<h4>#{title}</h4>\n"
150
+
151
+ $toc_index = 0
152
+ $toc_selection = 'h1,h2[unique]'
153
+ assert_equal html.header(title, '1'), "\n<h1 id=\"header-1\">#{title}</h1>\n"
154
+ assert_equal html.header(title, 2), "\n<h2 id=\"header-2\">#{title}</h2>\n"
155
+ assert_equal html.header(illegal_title, 2), "\n<h2 id=\"header-3\">#{illegal_title}</h2>\n"
156
+ assert_equal html.header(title, 3), "\n<h3>#{title}</h3>\n"
157
+ assert_equal html.header(title, '4'), "\n<h4>#{title}</h4>\n"
158
+ end
159
+
160
+
161
+
162
+ def test_identifier_uniquify
163
+ require 'set'
164
+ identifier_set = Set.new
165
+ times = 100000
166
+ times.times do
167
+ identifier_set << SecureRandom.hex(10)
168
+ end
169
+ assert_equal identifier_set.size, times
170
+ end
171
+ end
@@ -0,0 +1,9 @@
1
+ public class JavaHelloWorld {
2
+ public static void main(String[] args) {
3
+ printOne();
4
+ }
5
+
6
+ public static void printOne() {
7
+ System.out.println("Hello World");
8
+ }
9
+ }
@@ -0,0 +1,26 @@
1
+ title: khaleesi
2
+ ‡‡‡‡‡‡‡‡‡‡‡‡‡‡
3
+
4
+ # Introduction
5
+
6
+ Khaleesi is a blog-aware or documentation-aware static site generator write in Ruby. Please visit my project's official site [khaleesi.vincestyling.com](http://khaleesi.vincestyling.com/) for more details.
7
+
8
+ # Installation
9
+
10
+ ## Requirements
11
+
12
+ ```bash
13
+ # => make sure the ruby version >= 2.1.2
14
+ ~ $ /usr/bin/ruby --version
15
+
16
+ # => make sure the RubyGems version >= 2.2.2
17
+ ~ $ /usr/bin/gem --version
18
+ ```
19
+
20
+ ## Install with RubyGems
21
+
22
+ Once you have Ruby and RubyGems up, you are ready to install Khaleesi. At the terminal prompt, you can simply run the following command to install :
23
+
24
+ ```bash
25
+ [sudo] gem install khaleesi
26
+ ```
@@ -0,0 +1,25 @@
1
+ <h1>Introduction</h1>
2
+
3
+ <p>Khaleesi is a blog-aware or documentation-aware static site generator write in Ruby. Please visit my project&#39;s official site <a href="http://khaleesi.vincestyling.com/">khaleesi.vincestyling.com</a> for more details.</p>
4
+
5
+ <h1>Installation</h1>
6
+
7
+ <h2>Requirements</h2>
8
+ <div class="highlight bash"><table><tr><td class="linenos"><pre>1
9
+ 2
10
+ 3
11
+ 4
12
+ 5</pre></td><td><pre><span class="c"># =&gt; make sure the ruby version &gt;= 2.1.2</span>
13
+ ~ <span class="nv">$ </span>/usr/bin/ruby --version
14
+
15
+ <span class="c"># =&gt; make sure the RubyGems version &gt;= 2.2.2</span>
16
+ ~ <span class="nv">$ </span>/usr/bin/gem --version
17
+ </pre></td></tr></table>
18
+ </div>
19
+
20
+ <h2>Install with RubyGems</h2>
21
+
22
+ <p>Once you have Ruby and RubyGems up, you are ready to install Khaleesi. At the terminal prompt, you can simply run the following command to install :</p>
23
+ <div class="highlight bash"><table><tr><td class="linenos"><pre>1</pre></td><td><pre><span class="o">[</span>sudo] gem install khaleesi
24
+ </pre></td></tr></table>
25
+ </div>
@@ -0,0 +1,20 @@
1
+ <h1>Introduction</h1>
2
+
3
+ <p>Khaleesi is a blog-aware or documentation-aware static site generator write in Ruby. Please visit my project&#39;s official site <a href="http://khaleesi.vincestyling.com/">khaleesi.vincestyling.com</a> for more details.</p>
4
+
5
+ <h1>Installation</h1>
6
+
7
+ <h2>Requirements</h2>
8
+ <div class="highlight bash"><pre><span class="c"># =&gt; make sure the ruby version &gt;= 2.1.2</span>
9
+ ~ <span class="nv">$ </span>/usr/bin/ruby --version
10
+
11
+ <span class="c"># =&gt; make sure the RubyGems version &gt;= 2.2.2</span>
12
+ ~ <span class="nv">$ </span>/usr/bin/gem --version
13
+ </pre>
14
+ </div>
15
+ <h2>Install with RubyGems</h2>
16
+
17
+ <p>Once you have Ruby and RubyGems up, you are ready to install Khaleesi. At the terminal prompt, you can simply run the following command to install :</p>
18
+ <div class="highlight bash"><pre><span class="o">[</span>sudo] gem install khaleesi
19
+ </pre>
20
+ </div>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
+ <link rel="stylesheet" href="/css/site.css" type="text/css" media="screen">
6
+ <title>${variable:title}</title>
7
+ </head>
8
+ <body>
9
+ <div class="header">
10
+ A khaleesi demonstration site
11
+ </div>
12
+ <div class="content">
13
+ ${decorator:content}
14
+ </div>
15
+ <div class="footer">
16
+ <div class="left">
17
+ <div>Licensed under the <a href="http://choosealicense.com/licenses/mit/">MIT License</a></div>
18
+ </div>
19
+ <div class="right">
20
+ <div>A pure-ruby static site generator</div>
21
+ <div>Find <a href="https://github.com/vince-styling/khaleesi">khaleesi</a> in github</div>
22
+ </div>
23
+ </div>
24
+ </body>
25
+ </html>
@@ -0,0 +1,8 @@
1
+ <div class="theme-tabs">
2
+ <div class="subject">
3
+ <a id="${variable:name}" class="link" href="/themes/${variable:name}.html">${variable:name}</a>
4
+ </div>
5
+ <div class="tab-content ${variable:name} clearfix">
6
+ ${page:javasmpcode}
7
+ </div>
8
+ </div>
@@ -0,0 +1,6 @@
1
+ decorator: basic
2
+ ‡‡‡‡‡‡‡‡‡‡‡‡‡‡
3
+ <h1 class="post_title">${variable:title}</h1>
4
+ <div class="post-thumb">
5
+ ${decorator:content}
6
+ </div>
@@ -0,0 +1,15 @@
1
+ decorator: basic
2
+ ‡‡‡‡‡‡‡‡‡‡‡‡‡‡
3
+ <div class="theme ${variable:title}">
4
+ <a href="/">Home</a>
5
+ <h1>Theme : ${variable:title}</h1>
6
+ ${decorator:content}
7
+ <div class="chain_snippet clearfix">
8
+ #if chain:prev($theme)
9
+ <div class="prev">Prev Theme : <a href="${theme:link}">${theme:title}</a></div>
10
+ #end
11
+ #if chain:next($theme)
12
+ <div class="next">Next Theme : <a href="${theme:link}">${theme:title}</a></div>
13
+ #end
14
+ </div>
15
+ </div>
@@ -0,0 +1,49 @@
1
+ title: Khaleesi Index
2
+ decorator: basic
3
+ slug: index.html
4
+ ‡‡‡‡‡‡‡‡‡‡‡‡‡‡
5
+ <div class="primary">
6
+ <h4>test for order by create time, ascending order, full list.</h4>
7
+ <h4>test many way of wrong variable expression syntax.</h4>
8
+ <ul class="post_list">
9
+ #foreach ($post : $posts)
10
+ <li title="${post:title}">
11
+ <p>$ { : } {} : ${ } ${--} ${:} ${} ${ $a{ } } ${variable:absent_var} ${page:absent_page}</p>
12
+ <a href="${post:link}">${post:title}</a>
13
+ <p>${post:description}</p>
14
+ </li>
15
+ #end
16
+ </ul>
17
+
18
+ <h4>test sub-directory looping.</h4>
19
+ <ul class="post_list">
20
+ #foreach ($camera : $studio/cameras)
21
+ <li title="${camera:subject}">
22
+ <p>subject: ${camera:subject}</p>
23
+ <p>price: ${camera:price}</p>
24
+ <p>Monitor Size : ${camera:MonitorSize}</p>
25
+ <p>Weight: ${camera:Weight}</p>
26
+ </li>
27
+ #end
28
+ </ul>
29
+
30
+ <h4>test for order by sequence, ascending order, full list.</h4>
31
+ #foreach ($theme : $themes_illustrates)
32
+ ${theme:content}
33
+ #end
34
+
35
+ <h4>test for order by sequence, ascending order, limit 2 items.</h4>
36
+ #foreach ($theme : $themes_illustrates 2)
37
+ ${theme:content}
38
+ #end
39
+
40
+ <h4>test for order by sequence, descending order, full list.</h4>
41
+ #foreach ($theme : $themes_illustrates desc)
42
+ ${theme:content}
43
+ #end
44
+
45
+ <h4>test for order by sequence, descending order, limit 3 items.</h4>
46
+ #foreach ($theme : $themes_illustrates desc 3)
47
+ ${theme:content}
48
+ #end
49
+ </div>
@@ -0,0 +1,11 @@
1
+ ```java
2
+ public class JavaHelloWorld {
3
+ public static void main(String[] args) {
4
+ printOne();
5
+ }
6
+
7
+ public static void printOne() {
8
+ System.out.println("Hello World");
9
+ }
10
+ }
11
+ ```
@@ -0,0 +1,11 @@
1
+ title: netroid's introduction
2
+ decorator: post
3
+ description: Netroid is a Http Framework for Android that based on Volley.
4
+ ‡‡‡‡‡‡‡‡‡‡‡‡‡‡
5
+
6
+ Netroid library for Android
7
+ ---------------------------
8
+
9
+ Netroid is a http library for Android that based on Volley, That purpose is make your android development easier than before, provide fast, handly, useful way to do async http operation by background thread.
10
+
11
+ please check [this](https://github.com/vince-styling/Netroid) for more details.