sundysilence 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sundysilence.gemspec
4
+ gemspec
5
+
6
+ gem "redcarpet"
7
+ gem "tx"
8
+ gem "liquid"
9
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Code Ass (aycabta)
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,29 @@
1
+ # SundySilence
2
+
3
+ publish HTML site from Markdown files.
4
+
5
+ ## Installation
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:
16
+
17
+ $ gem install sundysilence
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/sundysilence ADDED
@@ -0,0 +1,16 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # points.rb: publish HTML site from Markdown files.
5
+ #
6
+ # Copyright (C) 2012 by Code Ass (aycabta) <aycabta@gmail.com>
7
+ # Distributed under MIT Lisence.
8
+ #
9
+
10
+ require 'rubygems'
11
+ require 'sundysilence'
12
+
13
+ ss = SundySilence::Builder.new
14
+ ss.build_pages
15
+ ss.cleanup
16
+
data/config.yml.sample ADDED
@@ -0,0 +1,14 @@
1
+ input_dir: input
2
+ output_dir: published
3
+ template_dir: templates
4
+ stylesheet_dir: stylesheets
5
+
6
+ pre_content: pre_content.html
7
+ post_content: post_content.html
8
+
9
+ title: "SundySilence Site"
10
+ expect_title: index
11
+ listpage_title: "list of pages"
12
+
13
+ combination_page_file: all
14
+
@@ -0,0 +1,156 @@
1
+ # encoding: utf-8
2
+
3
+ require 'fileutils'
4
+ require 'cgi'
5
+ require 'yaml'
6
+ require 'redcarpet'
7
+ require 'tx'
8
+ require 'liquid'
9
+
10
+ INDEX_FILE = "tmp.index"
11
+
12
+ module SundySilence
13
+ class Builder
14
+ def initialize
15
+ @config = YAML::load(open('./config.yml'))
16
+ @markdown = Redcarpet::Markdown.new(Redcarpet::Render::XHTML.new(:hard_wrap => true), :fenced_code_blocks => true, :autolink => true, :superscript => true)
17
+ @entries = Hash.new
18
+
19
+ if not Dir.exist?(@config['input_dir'])
20
+ puts "#{@config['input_dir']} is not found\n"
21
+ exit -1
22
+ end
23
+
24
+ Dir.foreach(@config['input_dir']) do |filename|
25
+ if filename =~ /^\.+$/
26
+ next
27
+ end
28
+
29
+ if filename =~ /^.*\.md$/ or filename =~ /^.*\.markdown$/
30
+ open(File.join(@config['input_dir'], filename)) do |fd|
31
+ title = fd.gets.chomp
32
+ @entries[title] = filename
33
+ end
34
+ end
35
+ end
36
+
37
+ tx = Tx::Builder.new
38
+ tx.add_all(@entries.keys)
39
+ tx.build(INDEX_FILE)
40
+ @index = Tx::Index.open(INDEX_FILE)
41
+
42
+ FileUtils.rm_r(@config['output_dir']) if Dir.exist?(@config['output_dir'])
43
+ Dir.mkdir(@config['output_dir'])
44
+
45
+ @pre_content = nil
46
+ open(File.join(@config['template_dir'], @config['pre_content']), 'rb') do |fd|
47
+ @pre_content = fd.read
48
+ end
49
+
50
+ @post_content = nil
51
+ open(File.join(@config['template_dir'], @config['post_content']), 'rb') do |fd|
52
+ @post_content = fd.read
53
+ end
54
+
55
+ if not @config['combination_page_file'].nil?
56
+ @combination = ""
57
+ end
58
+ end
59
+
60
+ def link_to_entries(text)
61
+ @index.gsub(text) do |s, i|
62
+ link_to = @entries[s].gsub(/(.*)\.(md|markdown)$/, '\1.html')
63
+ "<a href=\"./#{CGI.escape(link_to)}\">#{CGI.escape_html(s)}</a>"
64
+ end
65
+ end
66
+
67
+ def render_template(text, title)
68
+ liquid = Liquid::Template.parse(text)
69
+ liquid.render({'title' => title})
70
+ 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
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)
89
+ if not @config['combination_page_file'].nil?
90
+ @combination += body
91
+ end
92
+ page = @pre_content + body + @post_content
93
+ page = render_template(page, title)
94
+ end
95
+
96
+ def build_entries
97
+ @entries.each do |page_title, filename|
98
+ output_filename = nil
99
+ open(File.join(@config['input_dir'], filename), 'rb') do |fd|
100
+ fd.gets
101
+ body = fd.read
102
+ if not filename =~ /#{@config['expect_title']}\.(md|markdown)/
103
+ title = page_title + " - " + @config['title']
104
+ else
105
+ title = page_title
106
+ end
107
+ page = build_a_entry(body, title)
108
+ output_filename = filename.gsub(/(.*)\.(md|markdown)$/, '\1.html')
109
+ open(File.join(@config['output_dir'], output_filename), 'w') do |output_fd|
110
+ output_fd.puts page
111
+ end
112
+ end
113
+ end
114
+ 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
+
125
+ def build_combination_page
126
+ open(File.join(@config['output_dir'], @config['combination_page_file'] + '.html'), 'w') do |fd|
127
+ title = 'all - ' + @config['title']
128
+ page = @pre_content + @combination + @post_content
129
+ page = render_template(page, title)
130
+ fd.puts page
131
+ end
132
+ end
133
+
134
+ def build_list_page
135
+ 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
+ fd.puts page
148
+ end
149
+ end
150
+
151
+ def cleanup
152
+ File.unlink(INDEX_FILE)
153
+ end
154
+ end
155
+ end
156
+
@@ -0,0 +1,3 @@
1
+ module SundySilence
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sundysilence/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Code Ass (aycabta)"]
6
+ gem.email = ["aycabta@gmail.com"]
7
+ gem.description = "publish HTML site from Markdown files."
8
+ gem.summary = gem.description
9
+ gem.homepage = "https://github.com/aycabta/sundysilence"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "sundysilence"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = SundySilence::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sundysilence
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Code Ass (aycabta)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: publish HTML site from Markdown files.
15
+ email:
16
+ - aycabta@gmail.com
17
+ executables:
18
+ - sundysilence
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/sundysilence
28
+ - config.yml.sample
29
+ - lib/sundysilence.rb
30
+ - lib/sundysilence/version.rb
31
+ - sundysilence.gemspec
32
+ homepage: https://github.com/aycabta/sundysilence
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.23
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: publish HTML site from Markdown files.
56
+ test_files: []