wst 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/wst +3 -3
- data/bin/wst-serve +3 -3
- data/lib/configuration.rb +47 -44
- data/lib/content.rb +74 -72
- data/lib/css_renderer.rb +67 -0
- data/lib/haml_content.rb +15 -13
- data/lib/haml_helpers_wlt_extensions.rb +2 -2
- data/lib/haml_renderer.rb +15 -13
- data/lib/html_with_pygments.rb +5 -3
- data/lib/js_renderer.rb +59 -0
- data/lib/logging.rb +11 -9
- data/lib/md_content.rb +35 -33
- data/lib/md_renderer.rb +20 -18
- data/lib/page.rb +59 -57
- data/lib/post.rb +38 -36
- data/lib/renderer.rb +35 -33
- data/lib/renderer_factory.rb +19 -17
- data/lib/wst.rb +79 -109
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d4e39821ab781b82410d564e334910a830ea243
|
4
|
+
data.tar.gz: e23a8193b48e32a9011fb36fb0f3f96c8ad94c8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5df0d135f7cba7a499d7b5e6cb6206dd356a93a687e83839fe2d869a868c574ae139144920241f0646ce1fe6a3b6b24e549431a98ee8d97348b82d28c9f7ee01
|
7
|
+
data.tar.gz: f52fe27732d41d984585f8d910c0a193878460c62de4399f73b22a553c12c62fd3cbce6c31856e5efe708b81797e59c7debf4990eb4a82689146cb0cef4b5fab
|
data/bin/wst
CHANGED
@@ -4,9 +4,9 @@ require 'wst'
|
|
4
4
|
|
5
5
|
dir = ARGV[0] || Dir.pwd
|
6
6
|
|
7
|
-
Logging.logger.formatter = proc do |severity, datetime, progname, msg|
|
7
|
+
Wst::Logging.logger.formatter = proc do |severity, datetime, progname, msg|
|
8
8
|
"#{msg}\n"
|
9
9
|
end
|
10
|
-
Configuration.read_config dir, false
|
10
|
+
Wst::Configuration.read_config dir, false
|
11
11
|
|
12
|
-
Wst.new.generate
|
12
|
+
Wst::Wst.new.generate
|
data/bin/wst-serve
CHANGED
@@ -7,11 +7,11 @@ require 'wst'
|
|
7
7
|
|
8
8
|
dir = ARGV[0] || Dir.pwd
|
9
9
|
|
10
|
-
Logging.logger.formatter = proc do |severity, datetime, progname, msg|
|
10
|
+
Wst::Logging.logger.formatter = proc do |severity, datetime, progname, msg|
|
11
11
|
"#{msg}\n"
|
12
12
|
end
|
13
|
-
Configuration.read_config dir, false
|
13
|
+
Wst::Configuration.read_config dir, false
|
14
14
|
|
15
|
-
Wst.new.generate
|
15
|
+
Wst::Wst.new.generate
|
16
16
|
|
17
17
|
Serve::Application.run ["_site"]
|
data/lib/configuration.rb
CHANGED
@@ -1,48 +1,51 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
3
|
+
module Wst
|
4
|
+
module Configuration
|
5
|
+
def config
|
6
|
+
Configuration.config
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.config
|
10
|
+
@config
|
11
|
+
end
|
12
|
+
|
13
|
+
def defaultLinks
|
14
|
+
Configuration.defaultLinks
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.defaultLinks
|
18
|
+
@defaultLinks
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.read_config location, local
|
22
|
+
Configuration.read_configuration location, local
|
23
|
+
Configuration.read_default_links
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.read_configuration location, local
|
27
|
+
raise "Not a valid Web Log Today location" unless self.valid_location? location
|
28
|
+
@config = YAML.load File.open(File.join(location, 'config.yaml'), 'r:utf-8').read
|
29
|
+
@config["__site_url__"] = @config["site_url"]
|
30
|
+
@config["site_url"] = "http://localhost:4000" if local
|
31
|
+
@config["path"] = location
|
32
|
+
@config["debug"] = ENV['WST_ENV'] != nil && ENV['WST_ENV'].casecmp('debug').zero?
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.read_default_links
|
36
|
+
@defaultLinks = if File.exists? self.links_file_path then "\n" + File.open(self.links_file_path, "r:utf-8").read else "" end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.valid_location? location
|
40
|
+
return false unless File.exists? File.join location, "config.yaml"
|
41
|
+
return false unless File.directory? File.join location, "_posts"
|
42
|
+
return false unless File.directory? File.join location, "_pages"
|
43
|
+
return false unless File.directory? File.join location, "_layouts"
|
44
|
+
return true
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.links_file_path
|
48
|
+
File.join config['path'], "links.md"
|
49
|
+
end
|
47
50
|
end
|
48
51
|
end
|
data/lib/content.rb
CHANGED
@@ -3,96 +3,98 @@ require 'yaml'
|
|
3
3
|
require 'configuration'
|
4
4
|
require 'digest/md5'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
module Wst
|
7
|
+
class Content
|
8
|
+
include Configuration
|
9
|
+
|
10
|
+
def initialize file_path, child = nil
|
11
|
+
@file_path = file_path
|
12
|
+
@plain_content = ""
|
13
|
+
@datas = Hash.new
|
14
|
+
@cats = ""
|
15
|
+
@child = child
|
16
|
+
@content = content
|
17
|
+
|
18
|
+
read_content
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def child
|
22
|
+
@child
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def content
|
26
|
+
c = self
|
27
|
+
while !c.child.nil?
|
28
|
+
c = c.child
|
29
|
+
end
|
30
|
+
c
|
28
31
|
end
|
29
|
-
c
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def dir
|
34
|
+
File.dirname @file_path
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
def method_missing(m, *args, &block)
|
38
|
+
if m =~ /^(.*)\?$/
|
39
|
+
return @datas.has_key? $1
|
40
|
+
elsif @datas.has_key? m.to_s
|
41
|
+
return @datas[m.to_s]
|
42
|
+
else
|
43
|
+
return nil
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
def raw_content
|
48
|
+
@plain_content
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def url= url
|
52
|
+
@url = url
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def url
|
56
|
+
@url ||= ''
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def datas
|
60
|
+
@datas
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def gravatar?
|
64
|
+
email?
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
def gravatar
|
68
|
+
hash = Digest::MD5.hexdigest(email)
|
69
|
+
"http://www.gravatar.com/avatar/#{hash}"
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
def account? name
|
73
|
+
return false unless config.has_key? "accounts"
|
74
|
+
return config["accounts"].has_key? name
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
def account name
|
78
|
+
return nil unless account? name
|
79
|
+
return config["accounts"][name]
|
80
|
+
end
|
80
81
|
|
81
|
-
|
82
|
+
protected
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
def default_links_path
|
85
|
+
"#{config['path']}/links.md"
|
86
|
+
end
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
def read_content
|
89
|
+
@plain_content = File.open(@file_path, "r:utf-8").read
|
90
|
+
begin
|
91
|
+
if @plain_content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
92
|
+
@plain_content = $'
|
93
|
+
@datas = YAML.load $1
|
94
|
+
end
|
95
|
+
rescue => e
|
96
|
+
puts "YAML Exception reading #{@file_path}: #{e.message}"
|
93
97
|
end
|
94
|
-
rescue => e
|
95
|
-
puts "YAML Exception reading #{@file_path}: #{e.message}"
|
96
98
|
end
|
97
99
|
end
|
98
100
|
end
|
data/lib/css_renderer.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'configuration'
|
3
|
+
require 'logging'
|
4
|
+
require 'sass'
|
5
|
+
|
6
|
+
module Wst
|
7
|
+
class CssRenderer
|
8
|
+
include Logging
|
9
|
+
include Configuration
|
10
|
+
|
11
|
+
def generate_all
|
12
|
+
logger.info 'Css'.blue
|
13
|
+
css_conf.each do |css_name|
|
14
|
+
logger.info " #{css_name}"
|
15
|
+
compile css_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [String] css_name Name of the css to compile
|
20
|
+
def compile(css_name)
|
21
|
+
css_file = get_css css_name
|
22
|
+
return if css_file.nil?
|
23
|
+
sass_style = unless config['debug'] then
|
24
|
+
:compressed
|
25
|
+
else
|
26
|
+
:expanded
|
27
|
+
end
|
28
|
+
output_file = "#{config['path']}/_site/#{css_name.split('/').last}.css"
|
29
|
+
File.open(output_file, 'w') do |f|
|
30
|
+
f.write css(css_file, sass_style)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
# @return [Array<String>] Array of css configurations.
|
36
|
+
def css_conf
|
37
|
+
if config.has_key?('assets') &&
|
38
|
+
config['assets'].has_key?('css') &&
|
39
|
+
config['assets']['css'].kind_of?(Array)
|
40
|
+
config['assets']['css']
|
41
|
+
else
|
42
|
+
[]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param [String] css_file css file to compile
|
47
|
+
# @param [Symbol] sass_style Style for Sass
|
48
|
+
def css(css_file, sass_style)
|
49
|
+
sass_engine = Sass::Engine.for_file(css_file, :syntax => sass_syntax(css_file), :style => sass_style)
|
50
|
+
sass_engine.render
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get the css file path.
|
54
|
+
# @param [String] css_name Name of the css relatively to _css directory
|
55
|
+
# @return [String] Name of the css relatively to _css directory
|
56
|
+
def get_css(css_name)
|
57
|
+
Dir.glob(File.join(config['path'], '_css', "#{css_name}.*")).first
|
58
|
+
end
|
59
|
+
|
60
|
+
# Get syntax (sass or scss) for a file
|
61
|
+
# @param [String] css Name of the file
|
62
|
+
# @return [symbol] :sass or :scss
|
63
|
+
def sass_syntax(css)
|
64
|
+
File.extname(css).delete('.').to_sym
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/haml_content.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'content'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Wst
|
5
|
+
class HamlContent < Content
|
6
|
+
def initialize file_path, child = nil, sub_content = ''
|
7
|
+
super file_path, child
|
8
|
+
@sub_content = sub_content
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def sub_content
|
12
|
+
@sub_content
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def deep_content
|
16
|
+
c = self
|
17
|
+
while !c.child.nil? && !c.child.child.nil?
|
18
|
+
c = c.child
|
19
|
+
end
|
20
|
+
c
|
18
21
|
end
|
19
|
-
c
|
20
22
|
end
|
21
23
|
end
|
@@ -10,7 +10,7 @@ module Haml
|
|
10
10
|
@@wlt_extensions_defined = true
|
11
11
|
|
12
12
|
module WltExtensions
|
13
|
-
include Configuration
|
13
|
+
include Wst::Configuration
|
14
14
|
|
15
15
|
def link_to name, content, ext = 'html'
|
16
16
|
"<a href='#{url_for(content, ext)}'>#{name}</a>"
|
@@ -71,7 +71,7 @@ module Haml
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def partial_haml_content partial
|
74
|
-
HamlContent.new partial_path(partial), content
|
74
|
+
Wst::HamlContent.new partial_path(partial), content
|
75
75
|
end
|
76
76
|
|
77
77
|
def url_for_string url, ext
|
data/lib/haml_renderer.rb
CHANGED
@@ -3,22 +3,24 @@ require 'renderer'
|
|
3
3
|
require 'haml'
|
4
4
|
require 'configuration'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module Wst
|
7
|
+
class HamlRenderer < Renderer
|
8
|
+
protected
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def render_layout
|
11
|
+
hamlcontent = HamlContent.new layout_path, @content, render_content
|
12
|
+
renderer = HamlRenderer.new hamlcontent
|
13
|
+
renderer.render
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def render_content
|
17
|
+
haml_engine.render(@content) do
|
18
|
+
@content.sub_content
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def haml_engine
|
23
|
+
Haml::Engine.new @content.raw_content
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
data/lib/html_with_pygments.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'pygments'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Wst
|
5
|
+
class HTMLwithPygments < Redcarpet::Render::XHTML
|
6
|
+
def block_code(code, language)
|
7
|
+
Pygments.highlight(code, :lexer => language)
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
data/lib/js_renderer.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'configuration'
|
3
|
+
require 'logging'
|
4
|
+
|
5
|
+
module Wst
|
6
|
+
class JsRenderer
|
7
|
+
include Logging
|
8
|
+
include Configuration
|
9
|
+
|
10
|
+
def generate_all
|
11
|
+
logger.info 'Js'.blue
|
12
|
+
js_conf.each do |js_name|
|
13
|
+
logger.info " #{js_name}"
|
14
|
+
compile js_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param [String] js_name Name of the js to compile
|
19
|
+
def compile(js_name)
|
20
|
+
lines = read_and_expand js_name
|
21
|
+
js = lines.flatten.join
|
22
|
+
compiled = unless config['debug'] then
|
23
|
+
Uglifier.compile js
|
24
|
+
else
|
25
|
+
js
|
26
|
+
end
|
27
|
+
output_file = "#{config['path']}/_site/#{js_name.split('/').last}.js"
|
28
|
+
File.open(output_file, 'w') do |f|
|
29
|
+
f.write compiled
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
# @return [Array<String>] Array of js configurations.
|
35
|
+
def js_conf
|
36
|
+
if config.has_key?('assets') &&
|
37
|
+
config['assets'].has_key?('js') &&
|
38
|
+
config['assets']['js'].kind_of?(Array)
|
39
|
+
config['assets']['js']
|
40
|
+
else
|
41
|
+
[]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [String] js_name Name of the js file to compile
|
46
|
+
def read_and_expand(js_name)
|
47
|
+
js_file = File.join File.join(config['path'], '_js', "#{js_name}.js")
|
48
|
+
return [] unless File.exists? js_file
|
49
|
+
content = File.read js_file
|
50
|
+
content.lines.inject([]) do |lines, line|
|
51
|
+
if line =~ /\/\/=\srequire\s['"](.*)['"]/
|
52
|
+
lines << read_and_expand("#{$1}")
|
53
|
+
else
|
54
|
+
lines << line
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/logging.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'logger'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Wst
|
5
|
+
module Logging
|
6
|
+
def logger
|
7
|
+
Logging.logger
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def self.logger
|
11
|
+
@logger ||= Logger.new(STDOUT)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
def self.logger= logger
|
15
|
+
@logger = logger
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/md_content.rb
CHANGED
@@ -2,46 +2,48 @@
|
|
2
2
|
require 'content'
|
3
3
|
require 'configuration'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
module Wst
|
6
|
+
class MdContent < Content
|
7
|
+
@@matcher = /^(.+\/)*(\d+-\d+-\d+)?-?(.*)(\.[^.]+)$/
|
8
|
+
|
9
|
+
def initialize file_path
|
10
|
+
super file_path
|
11
|
+
|
12
|
+
m, cats, date, slug, ext = *file_path.match(@@matcher)
|
13
|
+
@cats = cats
|
14
|
+
@date = Time.parse(date) if date
|
15
|
+
@slug = slug
|
16
|
+
@ext = ext
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def date
|
20
|
+
@date
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def raw_content
|
24
|
+
if useDefaultLinks?
|
25
|
+
content_with_links
|
26
|
+
else
|
27
|
+
@plain_content
|
28
|
+
end
|
27
29
|
end
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def self.matcher
|
32
|
+
@@matcher
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
+
protected
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def content_with_links
|
38
|
+
@plain_content + defaultLinks
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def useDefaultLinks?
|
42
|
+
if @datas.has_key? 'nolinks'
|
43
|
+
@datas['nolinks'] == 'true'
|
44
|
+
else
|
45
|
+
true
|
46
|
+
end
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
data/lib/md_renderer.rb
CHANGED
@@ -4,26 +4,28 @@ require 'renderer_factory'
|
|
4
4
|
require 'redcarpet'
|
5
5
|
require 'html_with_pygments'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
module Wst
|
8
|
+
class MdRenderer < Renderer
|
9
|
+
protected
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def render_layout
|
12
|
+
hamlcontent = HamlContent.new layout_path, @content, render_content
|
13
|
+
renderer = RendererFactory.for hamlcontent
|
14
|
+
renderer.render
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def render_content
|
18
|
+
markdown_renderer.render @content.raw_content
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
def markdown_renderer
|
22
|
+
Redcarpet::Markdown.new(HTMLwithPygments,
|
23
|
+
:with_toc_data => true,
|
24
|
+
:fenced_code_blocks => true,
|
25
|
+
:strikethrough => true,
|
26
|
+
:autolink => true,
|
27
|
+
:no_intra_emphasis => true,
|
28
|
+
:tables => true)
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
data/lib/page.rb
CHANGED
@@ -3,85 +3,87 @@ require 'md_content'
|
|
3
3
|
require 'haml_content'
|
4
4
|
require 'cgi'
|
5
5
|
|
6
|
-
module
|
7
|
-
|
8
|
-
|
6
|
+
module Wst
|
7
|
+
module PageComparison
|
8
|
+
def <=> obj
|
9
|
+
return url <=> obj.url
|
10
|
+
end
|
9
11
|
end
|
10
|
-
end
|
11
12
|
|
12
|
-
class HamlPage < HamlContent
|
13
|
-
|
13
|
+
class HamlPage < HamlContent
|
14
|
+
include PageComparison
|
14
15
|
|
15
|
-
|
16
|
+
@@matcher = /^(.+\/)*(.*)(\.[^.]+)$/
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
def initialize file_path
|
19
|
+
super file_path
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
m, cats, slug, ext = *file_path.match(@@matcher)
|
22
|
+
base_path = File.join(Configuration.config['path'], '_pages') + '/'
|
23
|
+
@cats = cats.gsub(base_path, '').chomp('/') if !cats.nil? && cats != base_path
|
24
|
+
@slug = slug
|
25
|
+
@ext = ext
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def url
|
29
|
+
"#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.html"
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
def self.matcher
|
33
|
+
@@matcher
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
class MdPage < MdContent
|
37
|
-
|
37
|
+
class MdPage < MdContent
|
38
|
+
include PageComparison
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
def initialize file_path
|
41
|
+
super file_path
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
base_path = File.join(Configuration.config['path'], '_pages') + '/'
|
44
|
+
@cats = @cats.gsub(base_path, '') if !@cats.nil?
|
45
|
+
@cats.chomp!('/')
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
def url
|
49
|
+
"#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.html"
|
50
|
+
end
|
49
51
|
end
|
50
|
-
end
|
51
52
|
|
52
|
-
class Page
|
53
|
-
|
54
|
-
|
53
|
+
class Page
|
54
|
+
@@glob_md = '*.{md,mkd,markdown}'
|
55
|
+
@@glob_haml = '*.haml'
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
class << self
|
58
|
+
def all
|
59
|
+
(haml_pages + md_pages).sort
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
+
private
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def haml_pages
|
65
|
+
page_files(@@glob_haml, HamlPage.matcher).inject([]) { |pages, file| pages << HamlPage.new(file) }
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
def md_pages
|
69
|
+
page_files(@@glob_md, MdContent.matcher).inject([]) { |pages, file| pages << MdPage.new(file) }
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def page_files glob, matcher
|
73
|
+
select_match all_files(glob), matcher
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
def select_match files, matcher
|
77
|
+
files.select { |file| file =~ matcher }
|
78
|
+
end
|
78
79
|
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
def all_files glob
|
81
|
+
Dir.glob glob_path glob
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
-
|
84
|
+
def glob_path glob
|
85
|
+
File.join "#{Configuration.config['path']}/_pages", '**', glob
|
86
|
+
end
|
85
87
|
end
|
86
88
|
end
|
87
89
|
end
|
data/lib/post.rb
CHANGED
@@ -1,51 +1,53 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'md_content'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Wst
|
5
|
+
class Post < MdContent
|
6
|
+
@@glob = "*.{md,mkd,markdown}"
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
def initialize file_path
|
9
|
+
super file_path
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def url
|
16
|
-
generate_url = {
|
17
|
-
"year" => @date.strftime("%Y"),
|
18
|
-
"month" => @date.strftime("%m"),
|
19
|
-
"day" => @date.strftime("%d"),
|
20
|
-
"title" => CGI.escape(@slug)
|
21
|
-
}.inject(":year/:month/:day/:title.html") { |result, token|
|
22
|
-
result.gsub(/:#{Regexp.escape token.first}/, token.last)
|
23
|
-
}.gsub(/\/\//, "/")
|
24
|
-
generate_url = "#{@cats}/#{generate_url}" if @cats != ''
|
25
|
-
generate_url
|
26
|
-
end
|
11
|
+
base_path = File.join(Configuration.config['path'], '_posts') + '/'
|
12
|
+
@cats = @cats.gsub(base_path, '') if !@cats.nil?
|
13
|
+
@cats.chomp!('/')
|
14
|
+
end
|
27
15
|
|
28
|
-
|
29
|
-
|
30
|
-
|
16
|
+
def url
|
17
|
+
generate_url = {
|
18
|
+
"year" => @date.strftime("%Y"),
|
19
|
+
"month" => @date.strftime("%m"),
|
20
|
+
"day" => @date.strftime("%d"),
|
21
|
+
"title" => CGI.escape(@slug)
|
22
|
+
}.inject(":year/:month/:day/:title.html") { |result, token|
|
23
|
+
result.gsub(/:#{Regexp.escape token.first}/, token.last)
|
24
|
+
}.gsub(/\/\//, "/")
|
25
|
+
generate_url = "#{@cats}/#{generate_url}" if @cats != ''
|
26
|
+
generate_url
|
31
27
|
end
|
32
28
|
|
33
|
-
|
29
|
+
class << self
|
30
|
+
def all
|
31
|
+
post_files.inject([]) { |posts, file| posts << Post.new(file) }
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
File.join "#{Configuration.config['path']}/_posts", '**', @@glob
|
37
|
-
end
|
34
|
+
private
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def glob_path
|
37
|
+
File.join "#{Configuration.config['path']}/_posts", '**', @@glob
|
38
|
+
end
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
def all_files
|
41
|
+
Dir.glob glob_path
|
42
|
+
end
|
43
|
+
|
44
|
+
def select_match files
|
45
|
+
files.select { |file| file =~ @@matcher }
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
def post_files
|
49
|
+
select_match(all_files).sort
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
data/lib/renderer.rb
CHANGED
@@ -3,49 +3,51 @@ require 'configuration'
|
|
3
3
|
require 'haml_content'
|
4
4
|
require 'fileutils'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module Wst
|
7
|
+
class Renderer
|
8
|
+
include Configuration
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def initialize content
|
11
|
+
@content = content
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def render
|
15
|
+
if has_layout?
|
16
|
+
render_layout
|
17
|
+
else
|
18
|
+
render_content
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def write_to_site
|
23
|
+
out = File.join config['path'], '_site', @content.url
|
24
|
+
FileUtils.mkdir_p File.dirname out
|
25
|
+
write_to out
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
protected
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def write_to out
|
31
|
+
File.open(out, 'w') { |f| f.write render }
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
def render_layout
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def render_content
|
38
|
+
@content.raw_content
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def has_layout?
|
42
|
+
@content.layout? && layout_exists?
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def layout_path
|
46
|
+
"#{config['path']}/_layouts/#{@content.layout}.haml"
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
def layout_exists?
|
50
|
+
File.exists? layout_path
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
data/lib/renderer_factory.rb
CHANGED
@@ -5,27 +5,29 @@ require 'haml_content'
|
|
5
5
|
require 'md_renderer'
|
6
6
|
require 'haml_renderer'
|
7
7
|
|
8
|
-
module
|
9
|
-
|
8
|
+
module Wst
|
9
|
+
module RendererFactory
|
10
|
+
module_function
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def for content
|
13
|
+
send content.class.name.split('::').last.downcase.to_sym, content
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def post content
|
17
|
+
MdRenderer.new content
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def mdpage content
|
21
|
+
MdRenderer.new content
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def hamlpage content
|
25
|
+
HamlRenderer.new content
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def hamlcontent content
|
29
|
+
HamlRenderer.new content
|
30
|
+
end
|
30
31
|
|
32
|
+
end
|
31
33
|
end
|
data/lib/wst.rb
CHANGED
@@ -3,138 +3,108 @@ require 'haml_helpers_wlt_extensions'
|
|
3
3
|
require 'post'
|
4
4
|
require 'page'
|
5
5
|
require 'renderer_factory'
|
6
|
+
require 'css_renderer'
|
7
|
+
require 'js_renderer'
|
6
8
|
require 'configuration'
|
7
|
-
require "sass"
|
8
9
|
require 'logging'
|
9
10
|
require 'colored'
|
10
11
|
require 'uglifier'
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
module Wst
|
14
|
+
class Wst
|
15
|
+
include Logging
|
16
|
+
include Configuration
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
js
|
20
|
-
content all
|
21
|
-
pub
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def init
|
27
|
-
logger.info "Clean".blue
|
28
|
-
FileUtils.mkdir_p File.join config['path'], "_site"
|
29
|
-
FileUtils.rm_rf Dir.glob File.join config['path'], "_site/*"
|
30
|
-
end
|
31
|
-
|
32
|
-
def css
|
33
|
-
return unless config.has_key? "assets"
|
34
|
-
return unless config["assets"].has_key? "css"
|
35
|
-
cssconf = config["assets"]["css"]
|
36
|
-
return unless cssconf.kind_of? Array
|
37
|
-
|
38
|
-
logger.info "Css".blue
|
39
|
-
cssconf.each do |cssname|
|
40
|
-
logger.info " #{cssname}"
|
41
|
-
compile_css cssname
|
18
|
+
def initialize
|
19
|
+
@css_renderer = CssRenderer.new
|
20
|
+
@js_renderer = JsRenderer.new
|
42
21
|
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def kss
|
46
|
-
return unless config.has_key? "assets"
|
47
|
-
return unless config["assets"].has_key? "css"
|
48
|
-
cssconf = config["assets"]["css"]
|
49
|
-
return unless cssconf.kind_of? Array
|
50
22
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
23
|
+
# @param [Boolean] all Generate all content or only published content
|
24
|
+
def generate(all = false)
|
25
|
+
init
|
26
|
+
css
|
27
|
+
js
|
28
|
+
content all
|
29
|
+
pub
|
55
30
|
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def js
|
59
|
-
return unless config.has_key? "assets"
|
60
|
-
return unless config["assets"].has_key? "js"
|
61
|
-
jsconf = config["assets"]["js"]
|
62
|
-
return unless jsconf.kind_of? Array
|
63
31
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
compile_js jsname
|
32
|
+
# Compile all css files
|
33
|
+
def css
|
34
|
+
@css_renderer.generate_all
|
68
35
|
end
|
69
|
-
end
|
70
36
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
compiled = js
|
76
|
-
File.open("#{config['path']}/_site/#{jsname.split('/').last}.js", "w") { |f| f.write(compiled) }
|
77
|
-
end
|
78
|
-
|
79
|
-
def read_and_expand jsname
|
80
|
-
jsfile = File.join File.join(config['path'], '_js', "#{jsname}.js")
|
81
|
-
return [] unless File.exists? jsfile
|
82
|
-
content = File.read jsfile
|
83
|
-
lines = content.lines.inject([]) do |lines, line|
|
84
|
-
if line =~ /\/\/=\srequire\s['"](.*)['"]/
|
85
|
-
lines << read_and_expand("#{$1}")
|
86
|
-
else
|
87
|
-
lines << line
|
88
|
-
end
|
37
|
+
# Compile a single css file
|
38
|
+
# @param [String] css_name Css name to compile
|
39
|
+
def compile_css(css_name)
|
40
|
+
@css_renderer.compile css_name
|
89
41
|
end
|
90
|
-
end
|
91
42
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
logger.info " #{doc.url}"
|
96
|
-
renderer = RendererFactory.for doc
|
97
|
-
renderer.write_to_site
|
43
|
+
# Compile all js files
|
44
|
+
def js
|
45
|
+
@js_renderer.generate_all
|
98
46
|
end
|
99
|
-
end
|
100
47
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
48
|
+
# Compile a single js file
|
49
|
+
# @param [String] js_name Js name to compile
|
50
|
+
def compile_js(js_name)
|
51
|
+
@js_renderer.compile js_name
|
52
|
+
end
|
105
53
|
|
106
|
-
|
107
|
-
return all_content if all
|
108
|
-
all_content.select { |c| c.published }
|
109
|
-
end
|
54
|
+
private
|
110
55
|
|
111
|
-
|
112
|
-
|
113
|
-
|
56
|
+
def init
|
57
|
+
logger.info 'Clean'.blue
|
58
|
+
FileUtils.mkdir_p File.join config['path'], '_site'
|
59
|
+
FileUtils.rm_rf Dir.glob File.join config['path'], '_site/*'
|
60
|
+
end
|
114
61
|
|
115
|
-
|
116
|
-
|
117
|
-
return
|
118
|
-
|
119
|
-
|
62
|
+
#def kss
|
63
|
+
# return unless config.has_key? 'assets'
|
64
|
+
# return unless config['assets'].has_key? 'css'
|
65
|
+
# css_conf = config['assets']['css']
|
66
|
+
# return unless css_conf.kind_of? Array
|
67
|
+
|
68
|
+
# logger.info 'KSS'.blue
|
69
|
+
# css_conf.each do |css_name|
|
70
|
+
# logger.info " #{css_name}"
|
71
|
+
# compile_css_expanded css_name
|
72
|
+
# end
|
73
|
+
#end
|
74
|
+
|
75
|
+
# @param [Boolean] all Generate all content or only published content
|
76
|
+
def content(all)
|
77
|
+
logger.info 'Content'.blue
|
78
|
+
contents(all).each do |doc|
|
79
|
+
logger.info " #{doc.url}"
|
80
|
+
renderer = RendererFactory.for doc
|
81
|
+
renderer.write_to_site
|
82
|
+
end
|
83
|
+
end
|
120
84
|
|
121
|
-
|
122
|
-
|
85
|
+
def pub
|
86
|
+
logger.info 'Pub'.blue
|
123
87
|
|
124
|
-
|
125
|
-
|
126
|
-
return if cssfile.nil?
|
127
|
-
sassengine = Sass::Engine.for_file(cssfile, :syntax => sass_syntax(cssfile), :style => :expanded)
|
128
|
-
css = sassengine.render
|
88
|
+
out_dir = File.join(config['path'], '_site')
|
89
|
+
in_dir = File.join(config['path'], '_pub', '.')
|
129
90
|
|
130
|
-
|
131
|
-
|
91
|
+
FileUtils.cp_r in_dir , out_dir
|
92
|
+
hidden = Dir.glob("#{in_dir}*").select do |file|
|
93
|
+
File.basename(file) != '.' && File.basename(file) != '..'
|
94
|
+
end
|
95
|
+
FileUtils.cp_r hidden , out_dir
|
96
|
+
end
|
132
97
|
|
133
|
-
|
134
|
-
|
135
|
-
|
98
|
+
# @param [Boolean] all Get all content or only published content
|
99
|
+
# @return [Array<Content>] Contents
|
100
|
+
def contents(all)
|
101
|
+
return all_content if all
|
102
|
+
all_content.select { |c| c.published }
|
103
|
+
end
|
136
104
|
|
137
|
-
|
138
|
-
|
105
|
+
# @return [Array<Content>] All post and page content
|
106
|
+
def all_content
|
107
|
+
[Post.all, Page.all].flatten
|
108
|
+
end
|
139
109
|
end
|
140
110
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wst
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yves Brissaud
|
@@ -136,10 +136,12 @@ files:
|
|
136
136
|
- lib/colored.rb
|
137
137
|
- lib/configuration.rb
|
138
138
|
- lib/content.rb
|
139
|
+
- lib/css_renderer.rb
|
139
140
|
- lib/haml_content.rb
|
140
141
|
- lib/haml_helpers_wlt_extensions.rb
|
141
142
|
- lib/haml_renderer.rb
|
142
143
|
- lib/html_with_pygments.rb
|
144
|
+
- lib/js_renderer.rb
|
143
145
|
- lib/logging.rb
|
144
146
|
- lib/md_content.rb
|
145
147
|
- lib/md_renderer.rb
|