sundysilence 0.0.3 → 0.0.4

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.
data/README.md CHANGED
@@ -1,18 +1,10 @@
1
1
  # SundySilence
2
2
 
3
- publish HTML site from Markdown files.
3
+ Publish static HTML site that is auto-linked to other pages with page title from Markdown files.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'sundysilence'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
7
+ Install it yourself as:
16
8
 
17
9
  $ gem install sundysilence
18
10
 
@@ -28,15 +20,15 @@ Create config.yml.
28
20
  pre_content: pre_content.html
29
21
  post_content: post_content.html
30
22
 
31
- title: "The Static Wiki"
23
+ site_title: "The Static Wiki"
32
24
  expect_title: index
33
25
  listpage_title: "All Pages"
34
26
 
35
27
  combination_page_file: all
36
28
 
37
- All entries are put in "input_dir" that are written in Markdown.
38
- "template_dir" includes "pre_content" file and "post_content" file.
39
- All entries that are replaced *.md with *.html are published to "ouput_dir".
29
+ All entries are put in "input_dir" setting that are written in Markdown.
30
+ "template_dir" setting includes "pre_content" setting file and "post_content" setting file.
31
+ All entries that are replaced *.md with *.html are published to "ouput_dir" setting.
40
32
 
41
33
  Write entries.
42
34
  This example file is named "the_page.md".
@@ -52,12 +44,19 @@ This example file is named "the_page.md".
52
44
  The first line is the page title.
53
45
  If a entry contains the title string,
54
46
  that string is linked to this entry.
55
- This title string is join the "title" setting above: "The Page - The Static Wiki".
47
+ This title string is join the "site_title" setting setting above: "The Page - The Static Wiki".
56
48
  The file is set "expect_title" setting is not joined the "title" setting.
57
49
  {{ title }} is replaced with that is joined string or not joined string
58
- in "pre_content", "post_content" and all entries.
50
+ in "pre_content" setting, "post_content" setting and all entries.
51
+ This sample is published to "the_page.html".
52
+
53
+ "list.html" that lists name of pages is automatically created.
54
+ The title of it is "listpage_title" setting.
55
+
56
+ "all.html" that lists all pages are contains if "combination_page_title" setting is set.
57
+ Carefully, sometimes this page is very long.
59
58
 
60
- Run SundySilence when these files are ready.
59
+ Finally, run SundySilence when these files above are ready.
61
60
 
62
61
  $ sundysilence
63
62
 
@@ -53,56 +53,58 @@ module SundySilence
53
53
  end
54
54
 
55
55
  if not @config['combination_page_file'].nil?
56
- @combination = ""
56
+ @combination = String.new
57
57
  end
58
58
  end
59
-
59
+
60
60
  def link_to_entries(text)
61
61
  @index.gsub(text) do |s, i|
62
62
  link_to = @entries[s].gsub(/(.*)\.(md|markdown)$/, '\1.html')
63
63
  "<a href=\"./#{CGI.escape(link_to)}\">#{CGI.escape_html(s)}</a>"
64
64
  end
65
65
  end
66
-
66
+
67
67
  def render_template(text, title)
68
+ title = CGI.escape_html(title)
68
69
  liquid = Liquid::Template.parse(text)
69
70
  liquid.render({'title' => title})
70
71
  end
71
-
72
- def build_a_entry(body, title)
73
- urls = Array.new
74
- body.gsub!(/((http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?)/) do |matched|
75
- url = matched
76
- breaks = ""
77
- if url =~ /^(.*)([\r\n]+)$/
78
- url = $1
79
- breaks = $2
80
- end
81
- urls << url
82
- "{{#{urls.size - 1}}}" + breaks
72
+
73
+ def link_and_render(text)
74
+ text.gsub!(/&/, '&amp;')
75
+ splitted_text = Array.new
76
+ rest = text
77
+ while rest =~ /((http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w\- \/.?%&=]*)?)/
78
+ pre = $~.pre_match
79
+ url = $&
80
+ rest = $~.post_match
81
+ splitted_text << link_to_entries(pre)
82
+ splitted_text << url
83
83
  end
84
- body = link_to_entries(body)
85
- (0..urls.size - 1).each do |i|
86
- body.sub!(/\{\{#{i.to_s}\}\}/, urls[i].to_s)
87
- end if urls.size > 0
88
- body = @markdown.render(body)
84
+ splitted_text << link_to_entries(rest)
85
+ text = splitted_text.join
86
+ @markdown.render(text)
87
+ end
88
+
89
+ def build_a_entry(body, title)
90
+ body = link_and_render(body)
89
91
  if not @config['combination_page_file'].nil?
90
92
  @combination += body
91
93
  end
92
94
  page = @pre_content + body + @post_content
93
- page = render_template(page, title)
95
+ render_template(page, title)
94
96
  end
95
-
97
+
96
98
  def build_entries
97
99
  @entries.each do |page_title, filename|
98
100
  output_filename = nil
99
101
  open(File.join(@config['input_dir'], filename), 'rb') do |fd|
100
102
  fd.gets
101
103
  body = fd.read
102
- if not filename =~ /#{@config['expect_title']}\.(md|markdown)/
103
- title = page_title + " - " + @config['title']
104
- else
104
+ if filename =~ /#{@config['expect_title']}\.(md|markdown)/
105
105
  title = page_title
106
+ else
107
+ title = page_title + " - " + @config['title']
106
108
  end
107
109
  page = build_a_entry(body, title)
108
110
  output_filename = filename.gsub(/(.*)\.(md|markdown)$/, '\1.html')
@@ -112,19 +114,10 @@ module SundySilence
112
114
  end
113
115
  end
114
116
  end
115
-
116
- def build_pages
117
- build_entries
118
- build_list_page
119
- if not @config['combination_page_file'].nil?
120
- build_combination_page
121
- end
122
- FileUtils.cp_r(@config['stylesheet_dir'], @config['output_dir'])
123
- end
124
117
 
125
118
  def build_combination_page
126
119
  open(File.join(@config['output_dir'], @config['combination_page_file'] + '.html'), 'w') do |fd|
127
- title = 'all - ' + @config['title']
120
+ title = "#{@config['combination_page_file']} - #{@config['title']}"
128
121
  page = @pre_content + @combination + @post_content
129
122
  page = render_template(page, title)
130
123
  fd.puts page
@@ -132,22 +125,30 @@ module SundySilence
132
125
  end
133
126
 
134
127
  def build_list_page
128
+ title = @config['listpage_title'] + ' - ' + @config['title']
129
+ body = "\# #{title}\n\n"
130
+ list_text = String.new
131
+ @entries.each do |title, filename|
132
+ list_text += "* #{title}\n"
133
+ end
134
+ body += list_text
135
+ body = link_and_render(body)
136
+ page = @pre_content + body + @post_content
137
+ page = render_template(page, title)
135
138
  open(File.join(@config['output_dir'], 'list.html'), 'w') do |fd|
136
- title = @config['listpage_title'] + ' - ' + @config['title']
137
- body = "\# #{title}\n\n"
138
- list_text = ""
139
- @entries.each do |title, filename|
140
- list_text += "* #{title}\n"
141
- end
142
- body += list_text
143
- body = link_to_entries(body)
144
- body = @markdown.render(body)
145
- page = @pre_content + body + @post_content
146
- page = render_template(page, title)
147
139
  fd.puts page
148
140
  end
149
141
  end
150
-
142
+
143
+ def build_pages
144
+ build_entries
145
+ build_list_page
146
+ if not @config['combination_page_file'].nil?
147
+ build_combination_page
148
+ end
149
+ FileUtils.cp_r(@config['stylesheet_dir'], @config['output_dir'])
150
+ end
151
+
151
152
  def cleanup
152
153
  File.unlink(INDEX_FILE)
153
154
  end
@@ -1,3 +1,3 @@
1
1
  module SundySilence
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,7 +4,7 @@ require File.expand_path('../lib/sundysilence/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Code Ass (aycabta)"]
6
6
  gem.email = ["aycabta@gmail.com"]
7
- gem.description = "publish HTML site from Markdown files."
7
+ gem.description = "Publish static HTML Wiki that is auto-linked to other pages with page title from Markdown files."
8
8
  gem.summary = gem.description
9
9
  gem.homepage = "https://github.com/aycabta/sundysilence"
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sundysilence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-10 00:00:00.000000000 Z
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: publish HTML site from Markdown files.
14
+ description: Publish static HTML Wiki that is auto-linked to other pages with page
15
+ title from Markdown files.
15
16
  email:
16
17
  - aycabta@gmail.com
17
18
  executables:
@@ -53,5 +54,6 @@ rubyforge_project:
53
54
  rubygems_version: 1.8.23
54
55
  signing_key:
55
56
  specification_version: 3
56
- summary: publish HTML site from Markdown files.
57
+ summary: Publish static HTML Wiki that is auto-linked to other pages with page title
58
+ from Markdown files.
57
59
  test_files: []