wst 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/wst +12 -0
- data/bin/wst-serve +17 -0
- data/lib/.editorconfig +12 -0
- data/lib/colored.rb +31 -0
- data/lib/configuration.rb +48 -0
- data/lib/content.rb +98 -0
- data/lib/haml_content.rb +21 -0
- data/lib/haml_helpers_wlt_extensions.rb +86 -0
- data/lib/haml_renderer.rb +24 -0
- data/lib/html_with_pygments.rb +8 -0
- data/lib/logging.rb +16 -0
- data/lib/md_content.rb +47 -0
- data/lib/md_renderer.rb +29 -0
- data/lib/page.rb +87 -0
- data/lib/post.rb +51 -0
- data/lib/renderer.rb +51 -0
- data/lib/renderer_factory.rb +31 -0
- data/lib/wst.rb +140 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ad7bbcd44506f55c13dcc5ad1b3d2754ead6932
|
4
|
+
data.tar.gz: 66f25db1788a3bcd5d9bb515f8b8231414c70c5e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b606ad1888543d91369361ea4e79aee979ea606e04006d5be0a2da2e1f43aa5eb79a4036887aa93e1528c6e4107b8a691b5c1b7aae674f2b078976f73bd29e5e
|
7
|
+
data.tar.gz: 67e7d4dd3f7ba5effc36718c2077759372e78d61ee4cfd39552194046c483b5531447067ad2bf697380c52a5831795a8b04d37aa6b9e2c993f7969739e7432c2
|
data/bin/wst
ADDED
data/bin/wst-serve
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'serve'
|
4
|
+
require 'serve/application'
|
5
|
+
|
6
|
+
require 'wst'
|
7
|
+
|
8
|
+
dir = ARGV[0] || Dir.pwd
|
9
|
+
|
10
|
+
Logging.logger.formatter = proc do |severity, datetime, progname, msg|
|
11
|
+
"#{msg}\n"
|
12
|
+
end
|
13
|
+
Configuration.read_config dir, false
|
14
|
+
|
15
|
+
Wst.new.generate
|
16
|
+
|
17
|
+
Serve::Application.run ["_site"]
|
data/lib/.editorconfig
ADDED
data/lib/colored.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class String
|
4
|
+
def colorize(color_code)
|
5
|
+
"\e[#{color_code}m#{self}\e[0m"
|
6
|
+
end
|
7
|
+
|
8
|
+
def red
|
9
|
+
colorize(31)
|
10
|
+
end
|
11
|
+
|
12
|
+
def green
|
13
|
+
colorize(32)
|
14
|
+
end
|
15
|
+
|
16
|
+
def yellow
|
17
|
+
colorize(33)
|
18
|
+
end
|
19
|
+
|
20
|
+
def blue
|
21
|
+
colorize(34)
|
22
|
+
end
|
23
|
+
|
24
|
+
def pink
|
25
|
+
colorize(35)
|
26
|
+
end
|
27
|
+
|
28
|
+
def cyan
|
29
|
+
colorize(36)
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Configuration
|
4
|
+
def config
|
5
|
+
Configuration.config
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.config
|
9
|
+
@config
|
10
|
+
end
|
11
|
+
|
12
|
+
def defaultLinks
|
13
|
+
Configuration.defaultLinks
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.defaultLinks
|
17
|
+
@defaultLinks
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.read_config location, local
|
21
|
+
Configuration.read_configuration location, local
|
22
|
+
Configuration.read_default_links
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.read_configuration location, local
|
26
|
+
raise "Not a valid Web Log Today location" unless self.valid_location? location
|
27
|
+
@config = YAML.load File.open(File.join(location, 'config.yaml'), 'r:utf-8').read
|
28
|
+
@config["__site_url__"] = @config["site_url"]
|
29
|
+
@config["site_url"] = "http://localhost:4000" if local
|
30
|
+
@config["path"] = location
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.read_default_links
|
34
|
+
@defaultLinks = if File.exists? self.links_file_path then "\n" + File.open(self.links_file_path, "r:utf-8").read else "" end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.valid_location? location
|
38
|
+
return false unless File.exists? File.join location, "config.yaml"
|
39
|
+
return false unless File.directory? File.join location, "_posts"
|
40
|
+
return false unless File.directory? File.join location, "_pages"
|
41
|
+
return false unless File.directory? File.join location, "_layouts"
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.links_file_path
|
46
|
+
File.join config['path'], "links.md"
|
47
|
+
end
|
48
|
+
end
|
data/lib/content.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'yaml'
|
3
|
+
require 'configuration'
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
class Content
|
7
|
+
include Configuration
|
8
|
+
|
9
|
+
def initialize file_path, child = nil
|
10
|
+
@file_path = file_path
|
11
|
+
@plain_content = ""
|
12
|
+
@datas = Hash.new
|
13
|
+
@cats = ""
|
14
|
+
@child = child
|
15
|
+
@content = content
|
16
|
+
|
17
|
+
read_content
|
18
|
+
end
|
19
|
+
|
20
|
+
def child
|
21
|
+
@child
|
22
|
+
end
|
23
|
+
|
24
|
+
def content
|
25
|
+
c = self
|
26
|
+
while !c.child.nil?
|
27
|
+
c = c.child
|
28
|
+
end
|
29
|
+
c
|
30
|
+
end
|
31
|
+
|
32
|
+
def dir
|
33
|
+
File.dirname @file_path
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing(m, *args, &block)
|
37
|
+
if m =~ /^(.*)\?$/
|
38
|
+
return @datas.has_key? $1
|
39
|
+
elsif @datas.has_key? m.to_s
|
40
|
+
return @datas[m.to_s]
|
41
|
+
else
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def raw_content
|
47
|
+
@plain_content
|
48
|
+
end
|
49
|
+
|
50
|
+
def url= url
|
51
|
+
@url = url
|
52
|
+
end
|
53
|
+
|
54
|
+
def url
|
55
|
+
@url ||= ''
|
56
|
+
end
|
57
|
+
|
58
|
+
def datas
|
59
|
+
@datas
|
60
|
+
end
|
61
|
+
|
62
|
+
def gravatar?
|
63
|
+
email?
|
64
|
+
end
|
65
|
+
|
66
|
+
def gravatar
|
67
|
+
hash = Digest::MD5.hexdigest(email)
|
68
|
+
"http://www.gravatar.com/avatar/#{hash}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def account? name
|
72
|
+
return false unless config.has_key? "accounts"
|
73
|
+
return config["accounts"].has_key? name
|
74
|
+
end
|
75
|
+
|
76
|
+
def account name
|
77
|
+
return nil unless account? name
|
78
|
+
return config["accounts"][name]
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
|
83
|
+
def default_links_path
|
84
|
+
"#{config['path']}/links.md"
|
85
|
+
end
|
86
|
+
|
87
|
+
def read_content
|
88
|
+
@plain_content = File.open(@file_path, "r:utf-8").read
|
89
|
+
begin
|
90
|
+
if @plain_content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
91
|
+
@plain_content = $'
|
92
|
+
@datas = YAML.load $1
|
93
|
+
end
|
94
|
+
rescue => e
|
95
|
+
puts "YAML Exception reading #{@file_path}: #{e.message}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/haml_content.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'content'
|
3
|
+
|
4
|
+
class HamlContent < Content
|
5
|
+
def initialize file_path, child = nil, sub_content = ''
|
6
|
+
super file_path, child
|
7
|
+
@sub_content = sub_content
|
8
|
+
end
|
9
|
+
|
10
|
+
def sub_content
|
11
|
+
@sub_content
|
12
|
+
end
|
13
|
+
|
14
|
+
def deep_content
|
15
|
+
c = self
|
16
|
+
while !c.child.nil? && !c.child.child.nil?
|
17
|
+
c = c.child
|
18
|
+
end
|
19
|
+
c
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'haml'
|
3
|
+
require 'haml_content'
|
4
|
+
require 'configuration'
|
5
|
+
require 'time'
|
6
|
+
require 'html_truncator'
|
7
|
+
|
8
|
+
module Haml
|
9
|
+
module Helpers
|
10
|
+
@@wlt_extensions_defined = true
|
11
|
+
|
12
|
+
module WltExtensions
|
13
|
+
include Configuration
|
14
|
+
|
15
|
+
def link_to name, content, ext = 'html'
|
16
|
+
"<a href='#{url_for(content, ext)}'>#{name}</a>"
|
17
|
+
end
|
18
|
+
|
19
|
+
#def link_to_if condition, name, content, ext = 'html'
|
20
|
+
# link_to_unless !condition, name, content, ext
|
21
|
+
#end
|
22
|
+
|
23
|
+
#def link_to_unless condition, name, content, ext = 'html'
|
24
|
+
# if condition
|
25
|
+
# if block_given?
|
26
|
+
# capture_haml &block
|
27
|
+
# else
|
28
|
+
# CGI.escape name
|
29
|
+
# end
|
30
|
+
# else
|
31
|
+
# link_to name, content, ext
|
32
|
+
# end
|
33
|
+
#end
|
34
|
+
|
35
|
+
def url content, ext = 'html'
|
36
|
+
if content.is_a? String
|
37
|
+
url_for_string content, ext
|
38
|
+
else
|
39
|
+
url_for_string content.url, ext
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render opts = {}
|
44
|
+
engine = Haml::Engine.new partial_haml_content(opts[:partial]).raw_content
|
45
|
+
engine.render self
|
46
|
+
end
|
47
|
+
|
48
|
+
def formated_date date
|
49
|
+
date.strftime("%d/%m/%Y")
|
50
|
+
end
|
51
|
+
|
52
|
+
def spanify str
|
53
|
+
str.gsub(/./) {|c| "<span>#{c}</span>"}
|
54
|
+
end
|
55
|
+
|
56
|
+
def excerpt striphtml = false, length = 30, ellipsis = "…"
|
57
|
+
truncate = HTML_Truncator.truncate deep_content.sub_content, length, :ellipsis => ellipsis
|
58
|
+
if striphtml
|
59
|
+
truncate.gsub(/<[^>]+>/, '')
|
60
|
+
else
|
61
|
+
truncate.gsub(/<\/?img[^>]*>/, '')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def partial_path partial
|
69
|
+
default_path = File.join config['path'], '_layouts', "#{partial}.haml"
|
70
|
+
File.join File.dirname(default_path), "_#{File.basename(default_path)}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def partial_haml_content partial
|
74
|
+
HamlContent.new partial_path(partial), content
|
75
|
+
end
|
76
|
+
|
77
|
+
def url_for_string url, ext
|
78
|
+
path = url
|
79
|
+
path += ".#{ext}" if !url.empty? && File.extname(url).empty?
|
80
|
+
"#{config['site_url']}/#{path}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
include WltExtensions
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'renderer'
|
3
|
+
require 'haml'
|
4
|
+
require 'configuration'
|
5
|
+
|
6
|
+
class HamlRenderer < Renderer
|
7
|
+
protected
|
8
|
+
|
9
|
+
def render_layout
|
10
|
+
hamlcontent = HamlContent.new layout_path, @content, render_content
|
11
|
+
renderer = HamlRenderer.new hamlcontent
|
12
|
+
renderer.render
|
13
|
+
end
|
14
|
+
|
15
|
+
def render_content
|
16
|
+
haml_engine.render(@content) do
|
17
|
+
@content.sub_content
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def haml_engine
|
22
|
+
Haml::Engine.new @content.raw_content
|
23
|
+
end
|
24
|
+
end
|
data/lib/logging.rb
ADDED
data/lib/md_content.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'content'
|
3
|
+
require 'configuration'
|
4
|
+
|
5
|
+
class MdContent < Content
|
6
|
+
@@matcher = /^(.+\/)*(\d+-\d+-\d+)?-?(.*)(\.[^.]+)$/
|
7
|
+
|
8
|
+
def initialize file_path
|
9
|
+
super file_path
|
10
|
+
|
11
|
+
m, cats, date, slug, ext = *file_path.match(@@matcher)
|
12
|
+
@cats = cats
|
13
|
+
@date = Time.parse(date) if date
|
14
|
+
@slug = slug
|
15
|
+
@ext = ext
|
16
|
+
end
|
17
|
+
|
18
|
+
def date
|
19
|
+
@date
|
20
|
+
end
|
21
|
+
|
22
|
+
def raw_content
|
23
|
+
if useDefaultLinks?
|
24
|
+
content_with_links
|
25
|
+
else
|
26
|
+
@plain_content
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.matcher
|
31
|
+
@@matcher
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def content_with_links
|
37
|
+
@plain_content + defaultLinks
|
38
|
+
end
|
39
|
+
|
40
|
+
def useDefaultLinks?
|
41
|
+
if @datas.has_key? 'nolinks'
|
42
|
+
@datas['nolinks'] == 'true'
|
43
|
+
else
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/md_renderer.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'renderer'
|
3
|
+
require 'renderer_factory'
|
4
|
+
require 'redcarpet'
|
5
|
+
require 'html_with_pygments'
|
6
|
+
|
7
|
+
class MdRenderer < Renderer
|
8
|
+
protected
|
9
|
+
|
10
|
+
def render_layout
|
11
|
+
hamlcontent = HamlContent.new layout_path, @content, render_content
|
12
|
+
renderer = RendererFactory.for hamlcontent
|
13
|
+
renderer.render
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_content
|
17
|
+
markdown_renderer.render @content.raw_content
|
18
|
+
end
|
19
|
+
|
20
|
+
def markdown_renderer
|
21
|
+
Redcarpet::Markdown.new(HTMLwithPygments,
|
22
|
+
:with_toc_data => true,
|
23
|
+
:fenced_code_blocks => true,
|
24
|
+
:strikethrough => true,
|
25
|
+
:autolink => true,
|
26
|
+
:no_intra_emphasis => true,
|
27
|
+
:tables => true)
|
28
|
+
end
|
29
|
+
end
|
data/lib/page.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'md_content'
|
3
|
+
require 'haml_content'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module PageComparison
|
7
|
+
def <=> obj
|
8
|
+
return url <=> obj.url
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class HamlPage < HamlContent
|
13
|
+
include PageComparison
|
14
|
+
|
15
|
+
@@matcher = /^(.+\/)*(.*)(\.[^.]+)$/
|
16
|
+
|
17
|
+
def initialize file_path
|
18
|
+
super file_path
|
19
|
+
|
20
|
+
m, cats, slug, ext = *file_path.match(@@matcher)
|
21
|
+
base_path = File.join(Configuration.config['path'], '_pages') + '/'
|
22
|
+
@cats = cats.gsub(base_path, '').chomp('/') if !cats.nil? && cats != base_path
|
23
|
+
@slug = slug
|
24
|
+
@ext = ext
|
25
|
+
end
|
26
|
+
|
27
|
+
def url
|
28
|
+
"#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.html"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.matcher
|
32
|
+
@@matcher
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class MdPage < MdContent
|
37
|
+
include PageComparison
|
38
|
+
|
39
|
+
def initialize file_path
|
40
|
+
super file_path
|
41
|
+
|
42
|
+
base_path = File.join(Configuration.config['path'], '_pages') + '/'
|
43
|
+
@cats = @cats.gsub(base_path, '') if !@cats.nil?
|
44
|
+
@cats.chomp!('/')
|
45
|
+
end
|
46
|
+
|
47
|
+
def url
|
48
|
+
"#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.html"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Page
|
53
|
+
@@glob_md = '*.{md,mkd,markdown}'
|
54
|
+
@@glob_haml = '*.haml'
|
55
|
+
|
56
|
+
class << self
|
57
|
+
def all
|
58
|
+
(haml_pages + md_pages).sort
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def haml_pages
|
64
|
+
page_files(@@glob_haml, HamlPage.matcher).inject([]) { |pages, file| pages << HamlPage.new(file) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def md_pages
|
68
|
+
page_files(@@glob_md, MdContent.matcher).inject([]) { |pages, file| pages << MdPage.new(file) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def page_files glob, matcher
|
72
|
+
select_match all_files(glob), matcher
|
73
|
+
end
|
74
|
+
|
75
|
+
def select_match files, matcher
|
76
|
+
files.select { |file| file =~ matcher }
|
77
|
+
end
|
78
|
+
|
79
|
+
def all_files glob
|
80
|
+
Dir.glob glob_path glob
|
81
|
+
end
|
82
|
+
|
83
|
+
def glob_path glob
|
84
|
+
File.join "#{Configuration.config['path']}/_pages", '**', glob
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/post.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'md_content'
|
3
|
+
|
4
|
+
class Post < MdContent
|
5
|
+
@@glob = "*.{md,mkd,markdown}"
|
6
|
+
|
7
|
+
def initialize file_path
|
8
|
+
super file_path
|
9
|
+
|
10
|
+
base_path = File.join(Configuration.config['path'], '_posts') + '/'
|
11
|
+
@cats = @cats.gsub(base_path, '') if !@cats.nil?
|
12
|
+
@cats.chomp!('/')
|
13
|
+
end
|
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
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def all
|
30
|
+
post_files.inject([]) { |posts, file| posts << Post.new(file) }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def glob_path
|
36
|
+
File.join "#{Configuration.config['path']}/_posts", '**', @@glob
|
37
|
+
end
|
38
|
+
|
39
|
+
def all_files
|
40
|
+
Dir.glob glob_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def select_match files
|
44
|
+
files.select { |file| file =~ @@matcher }
|
45
|
+
end
|
46
|
+
|
47
|
+
def post_files
|
48
|
+
select_match(all_files).sort
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/renderer.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'configuration'
|
3
|
+
require 'haml_content'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
class Renderer
|
7
|
+
include Configuration
|
8
|
+
|
9
|
+
def initialize content
|
10
|
+
@content = content
|
11
|
+
end
|
12
|
+
|
13
|
+
def render
|
14
|
+
if has_layout?
|
15
|
+
render_layout
|
16
|
+
else
|
17
|
+
render_content
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def write_to_site
|
22
|
+
out = File.join config['path'], '_site', @content.url
|
23
|
+
FileUtils.mkdir_p File.dirname out
|
24
|
+
write_to out
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def write_to out
|
30
|
+
File.open(out, 'w') { |f| f.write render }
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_layout
|
34
|
+
end
|
35
|
+
|
36
|
+
def render_content
|
37
|
+
@content.raw_content
|
38
|
+
end
|
39
|
+
|
40
|
+
def has_layout?
|
41
|
+
@content.layout? && layout_exists?
|
42
|
+
end
|
43
|
+
|
44
|
+
def layout_path
|
45
|
+
"#{config['path']}/_layouts/#{@content.layout}.haml"
|
46
|
+
end
|
47
|
+
|
48
|
+
def layout_exists?
|
49
|
+
File.exists? layout_path
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'post'
|
3
|
+
require 'page'
|
4
|
+
require 'haml_content'
|
5
|
+
require 'md_renderer'
|
6
|
+
require 'haml_renderer'
|
7
|
+
|
8
|
+
module RendererFactory
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def for content
|
12
|
+
send content.class.name.downcase.to_sym, content
|
13
|
+
end
|
14
|
+
|
15
|
+
def post content
|
16
|
+
MdRenderer.new content
|
17
|
+
end
|
18
|
+
|
19
|
+
def mdpage content
|
20
|
+
MdRenderer.new content
|
21
|
+
end
|
22
|
+
|
23
|
+
def hamlpage content
|
24
|
+
HamlRenderer.new content
|
25
|
+
end
|
26
|
+
|
27
|
+
def hamlcontent content
|
28
|
+
HamlRenderer.new content
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/wst.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'haml_helpers_wlt_extensions'
|
3
|
+
require 'post'
|
4
|
+
require 'page'
|
5
|
+
require 'renderer_factory'
|
6
|
+
require 'configuration'
|
7
|
+
require "sass"
|
8
|
+
require 'logging'
|
9
|
+
require 'colored'
|
10
|
+
require 'uglifier'
|
11
|
+
|
12
|
+
class Wst
|
13
|
+
include Logging
|
14
|
+
include Configuration
|
15
|
+
|
16
|
+
def generate all = false
|
17
|
+
init
|
18
|
+
css
|
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
|
42
|
+
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
|
+
|
51
|
+
logger.info "KSS".blue
|
52
|
+
cssconf.each do |cssname|
|
53
|
+
logger.info " #{cssname}"
|
54
|
+
compile_css_expanded cssname
|
55
|
+
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
|
+
|
64
|
+
logger.info "Js".blue
|
65
|
+
jsconf.each do |jsname|
|
66
|
+
logger.info " #{jsname}"
|
67
|
+
compile_js jsname
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def compile_js jsname
|
72
|
+
lines = read_and_expand jsname
|
73
|
+
js = lines.flatten.join
|
74
|
+
#compiled = Uglifier.compile js
|
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
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def content all
|
93
|
+
logger.info "Content".blue
|
94
|
+
contents(all).each do |doc|
|
95
|
+
logger.info " #{doc.url}"
|
96
|
+
renderer = RendererFactory.for doc
|
97
|
+
renderer.write_to_site
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def pub
|
102
|
+
logger.info "Pub".blue
|
103
|
+
FileUtils.cp_r File.join(config['path'], '_pub', '.') , File.join(config['path'], '_site')
|
104
|
+
end
|
105
|
+
|
106
|
+
def contents all
|
107
|
+
return all_content if all
|
108
|
+
all_content.select { |c| c.published }
|
109
|
+
end
|
110
|
+
|
111
|
+
def all_content
|
112
|
+
[Post.all, Page.all].flatten
|
113
|
+
end
|
114
|
+
|
115
|
+
def compile_css cssname
|
116
|
+
cssfile = get_css cssname
|
117
|
+
return if cssfile.nil?
|
118
|
+
sassengine = Sass::Engine.for_file(cssfile, :syntax => sass_syntax(cssfile), :style => :compressed)
|
119
|
+
css = sassengine.render
|
120
|
+
|
121
|
+
File.open("#{config['path']}/_site/#{cssname.split('/').last}.css", "w") { |f| f.write(css) }
|
122
|
+
end
|
123
|
+
|
124
|
+
def compile_css_expanded cssname
|
125
|
+
cssfile = get_css cssname
|
126
|
+
return if cssfile.nil?
|
127
|
+
sassengine = Sass::Engine.for_file(cssfile, :syntax => sass_syntax(cssfile), :style => :expanded)
|
128
|
+
css = sassengine.render
|
129
|
+
|
130
|
+
File.open("#{config['path']}/_kss/#{cssname.split('/').last}.css", "w") { |f| f.write(css) }
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_css cssname
|
134
|
+
Dir.glob(File.join(config['path'], '_css', "#{cssname}.*")).first
|
135
|
+
end
|
136
|
+
|
137
|
+
def sass_syntax css
|
138
|
+
File.extname(css).delete('.').to_sym
|
139
|
+
end
|
140
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wst
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yves Brissaud
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: haml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sass
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coffee-script
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: redcarpet
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pygments.rb
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.6'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: html_truncator
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: uglifier
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.4'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: serve
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.5'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.5'
|
125
|
+
description: A nice web site generator
|
126
|
+
email: yves.brissaud@gmail.com
|
127
|
+
executables:
|
128
|
+
- wst
|
129
|
+
- wst-serve
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- bin/wst
|
134
|
+
- bin/wst-serve
|
135
|
+
- lib/.editorconfig
|
136
|
+
- lib/colored.rb
|
137
|
+
- lib/configuration.rb
|
138
|
+
- lib/content.rb
|
139
|
+
- lib/haml_content.rb
|
140
|
+
- lib/haml_helpers_wlt_extensions.rb
|
141
|
+
- lib/haml_renderer.rb
|
142
|
+
- lib/html_with_pygments.rb
|
143
|
+
- lib/logging.rb
|
144
|
+
- lib/md_content.rb
|
145
|
+
- lib/md_renderer.rb
|
146
|
+
- lib/page.rb
|
147
|
+
- lib/post.rb
|
148
|
+
- lib/renderer.rb
|
149
|
+
- lib/renderer_factory.rb
|
150
|
+
- lib/wst.rb
|
151
|
+
homepage: https://github.com/eunomie/wst
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.2.2
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Web Site Today
|
175
|
+
test_files: []
|