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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ad7bbcd44506f55c13dcc5ad1b3d2754ead6932
4
- data.tar.gz: 66f25db1788a3bcd5d9bb515f8b8231414c70c5e
3
+ metadata.gz: 1d4e39821ab781b82410d564e334910a830ea243
4
+ data.tar.gz: e23a8193b48e32a9011fb36fb0f3f96c8ad94c8b
5
5
  SHA512:
6
- metadata.gz: b606ad1888543d91369361ea4e79aee979ea606e04006d5be0a2da2e1f43aa5eb79a4036887aa93e1528c6e4107b8a691b5c1b7aae674f2b078976f73bd29e5e
7
- data.tar.gz: 67e7d4dd3f7ba5effc36718c2077759372e78d61ee4cfd39552194046c483b5531447067ad2bf697380c52a5831795a8b04d37aa6b9e2c993f7969739e7432c2
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 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"
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
- 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
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
- def child
21
- @child
22
- end
21
+ def child
22
+ @child
23
+ end
23
24
 
24
- def content
25
- c = self
26
- while !c.child.nil?
27
- c = c.child
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
- def dir
33
- File.dirname @file_path
34
- end
33
+ def dir
34
+ File.dirname @file_path
35
+ end
35
36
 
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
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
- def raw_content
47
- @plain_content
48
- end
47
+ def raw_content
48
+ @plain_content
49
+ end
49
50
 
50
- def url= url
51
- @url = url
52
- end
51
+ def url= url
52
+ @url = url
53
+ end
53
54
 
54
- def url
55
- @url ||= ''
56
- end
55
+ def url
56
+ @url ||= ''
57
+ end
57
58
 
58
- def datas
59
- @datas
60
- end
59
+ def datas
60
+ @datas
61
+ end
61
62
 
62
- def gravatar?
63
- email?
64
- end
63
+ def gravatar?
64
+ email?
65
+ end
65
66
 
66
- def gravatar
67
- hash = Digest::MD5.hexdigest(email)
68
- "http://www.gravatar.com/avatar/#{hash}"
69
- end
67
+ def gravatar
68
+ hash = Digest::MD5.hexdigest(email)
69
+ "http://www.gravatar.com/avatar/#{hash}"
70
+ end
70
71
 
71
- def account? name
72
- return false unless config.has_key? "accounts"
73
- return config["accounts"].has_key? name
74
- end
72
+ def account? name
73
+ return false unless config.has_key? "accounts"
74
+ return config["accounts"].has_key? name
75
+ end
75
76
 
76
- def account name
77
- return nil unless account? name
78
- return config["accounts"][name]
79
- end
77
+ def account name
78
+ return nil unless account? name
79
+ return config["accounts"][name]
80
+ end
80
81
 
81
- protected
82
+ protected
82
83
 
83
- def default_links_path
84
- "#{config['path']}/links.md"
85
- end
84
+ def default_links_path
85
+ "#{config['path']}/links.md"
86
+ end
86
87
 
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
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
@@ -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
- class HamlContent < Content
5
- def initialize file_path, child = nil, sub_content = ''
6
- super file_path, child
7
- @sub_content = sub_content
8
- end
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
- def sub_content
11
- @sub_content
12
- end
11
+ def sub_content
12
+ @sub_content
13
+ end
13
14
 
14
- def deep_content
15
- c = self
16
- while !c.child.nil? && !c.child.child.nil?
17
- c = c.child
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
- class HamlRenderer < Renderer
7
- protected
6
+ module Wst
7
+ class HamlRenderer < Renderer
8
+ protected
8
9
 
9
- def render_layout
10
- hamlcontent = HamlContent.new layout_path, @content, render_content
11
- renderer = HamlRenderer.new hamlcontent
12
- renderer.render
13
- end
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
- def render_content
16
- haml_engine.render(@content) do
17
- @content.sub_content
16
+ def render_content
17
+ haml_engine.render(@content) do
18
+ @content.sub_content
19
+ end
18
20
  end
19
- end
20
21
 
21
- def haml_engine
22
- Haml::Engine.new @content.raw_content
22
+ def haml_engine
23
+ Haml::Engine.new @content.raw_content
24
+ end
23
25
  end
24
26
  end
@@ -1,8 +1,10 @@
1
1
  # encoding: utf-8
2
2
  require 'pygments'
3
3
 
4
- class HTMLwithPygments < Redcarpet::Render::XHTML
5
- def block_code(code, language)
6
- Pygments.highlight(code, :lexer => language)
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
@@ -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 Logging
5
- def logger
6
- Logging.logger
7
- end
4
+ module Wst
5
+ module Logging
6
+ def logger
7
+ Logging.logger
8
+ end
8
9
 
9
- def self.logger
10
- @logger ||= Logger.new(STDOUT)
11
- end
10
+ def self.logger
11
+ @logger ||= Logger.new(STDOUT)
12
+ end
12
13
 
13
- def self.logger= logger
14
- @logger = logger
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
- 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
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
- def date
19
- @date
20
- end
19
+ def date
20
+ @date
21
+ end
21
22
 
22
- def raw_content
23
- if useDefaultLinks?
24
- content_with_links
25
- else
26
- @plain_content
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
- def self.matcher
31
- @@matcher
32
- end
31
+ def self.matcher
32
+ @@matcher
33
+ end
33
34
 
34
- protected
35
+ protected
35
36
 
36
- def content_with_links
37
- @plain_content + defaultLinks
38
- end
37
+ def content_with_links
38
+ @plain_content + defaultLinks
39
+ end
39
40
 
40
- def useDefaultLinks?
41
- if @datas.has_key? 'nolinks'
42
- @datas['nolinks'] == 'true'
43
- else
44
- true
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
- class MdRenderer < Renderer
8
- protected
7
+ module Wst
8
+ class MdRenderer < Renderer
9
+ protected
9
10
 
10
- def render_layout
11
- hamlcontent = HamlContent.new layout_path, @content, render_content
12
- renderer = RendererFactory.for hamlcontent
13
- renderer.render
14
- end
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
- def render_content
17
- markdown_renderer.render @content.raw_content
18
- end
17
+ def render_content
18
+ markdown_renderer.render @content.raw_content
19
+ end
19
20
 
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)
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 PageComparison
7
- def <=> obj
8
- return url <=> obj.url
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
- include PageComparison
13
+ class HamlPage < HamlContent
14
+ include PageComparison
14
15
 
15
- @@matcher = /^(.+\/)*(.*)(\.[^.]+)$/
16
+ @@matcher = /^(.+\/)*(.*)(\.[^.]+)$/
16
17
 
17
- def initialize file_path
18
- super file_path
18
+ def initialize file_path
19
+ super file_path
19
20
 
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
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
- def url
28
- "#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.html"
29
- end
28
+ def url
29
+ "#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.html"
30
+ end
30
31
 
31
- def self.matcher
32
- @@matcher
32
+ def self.matcher
33
+ @@matcher
34
+ end
33
35
  end
34
- end
35
36
 
36
- class MdPage < MdContent
37
- include PageComparison
37
+ class MdPage < MdContent
38
+ include PageComparison
38
39
 
39
- def initialize file_path
40
- super file_path
40
+ def initialize file_path
41
+ super file_path
41
42
 
42
- base_path = File.join(Configuration.config['path'], '_pages') + '/'
43
- @cats = @cats.gsub(base_path, '') if !@cats.nil?
44
- @cats.chomp!('/')
45
- end
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
- def url
48
- "#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.html"
48
+ def url
49
+ "#{@cats + '/' if @cats != ''}#{CGI.escape @slug}.html"
50
+ end
49
51
  end
50
- end
51
52
 
52
- class Page
53
- @@glob_md = '*.{md,mkd,markdown}'
54
- @@glob_haml = '*.haml'
53
+ class Page
54
+ @@glob_md = '*.{md,mkd,markdown}'
55
+ @@glob_haml = '*.haml'
55
56
 
56
- class << self
57
- def all
58
- (haml_pages + md_pages).sort
59
- end
57
+ class << self
58
+ def all
59
+ (haml_pages + md_pages).sort
60
+ end
60
61
 
61
- private
62
+ private
62
63
 
63
- def haml_pages
64
- page_files(@@glob_haml, HamlPage.matcher).inject([]) { |pages, file| pages << HamlPage.new(file) }
65
- end
64
+ def haml_pages
65
+ page_files(@@glob_haml, HamlPage.matcher).inject([]) { |pages, file| pages << HamlPage.new(file) }
66
+ end
66
67
 
67
- def md_pages
68
- page_files(@@glob_md, MdContent.matcher).inject([]) { |pages, file| pages << MdPage.new(file) }
69
- end
68
+ def md_pages
69
+ page_files(@@glob_md, MdContent.matcher).inject([]) { |pages, file| pages << MdPage.new(file) }
70
+ end
70
71
 
71
- def page_files glob, matcher
72
- select_match all_files(glob), matcher
73
- end
72
+ def page_files glob, matcher
73
+ select_match all_files(glob), matcher
74
+ end
74
75
 
75
- def select_match files, matcher
76
- files.select { |file| file =~ matcher }
77
- end
76
+ def select_match files, matcher
77
+ files.select { |file| file =~ matcher }
78
+ end
78
79
 
79
- def all_files glob
80
- Dir.glob glob_path glob
81
- end
80
+ def all_files glob
81
+ Dir.glob glob_path glob
82
+ end
82
83
 
83
- def glob_path glob
84
- File.join "#{Configuration.config['path']}/_pages", '**', glob
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
- class Post < MdContent
5
- @@glob = "*.{md,mkd,markdown}"
4
+ module Wst
5
+ class Post < MdContent
6
+ @@glob = "*.{md,mkd,markdown}"
6
7
 
7
- def initialize file_path
8
- super file_path
8
+ def initialize file_path
9
+ super file_path
9
10
 
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
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
- class << self
29
- def all
30
- post_files.inject([]) { |posts, file| posts << Post.new(file) }
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
- private
29
+ class << self
30
+ def all
31
+ post_files.inject([]) { |posts, file| posts << Post.new(file) }
32
+ end
34
33
 
35
- def glob_path
36
- File.join "#{Configuration.config['path']}/_posts", '**', @@glob
37
- end
34
+ private
38
35
 
39
- def all_files
40
- Dir.glob glob_path
41
- end
36
+ def glob_path
37
+ File.join "#{Configuration.config['path']}/_posts", '**', @@glob
38
+ end
42
39
 
43
- def select_match files
44
- files.select { |file| file =~ @@matcher }
45
- end
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
- def post_files
48
- select_match(all_files).sort
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
- class Renderer
7
- include Configuration
6
+ module Wst
7
+ class Renderer
8
+ include Configuration
8
9
 
9
- def initialize content
10
- @content = content
11
- end
10
+ def initialize content
11
+ @content = content
12
+ end
12
13
 
13
- def render
14
- if has_layout?
15
- render_layout
16
- else
17
- render_content
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
- 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
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
- protected
28
+ protected
28
29
 
29
- def write_to out
30
- File.open(out, 'w') { |f| f.write render }
31
- end
30
+ def write_to out
31
+ File.open(out, 'w') { |f| f.write render }
32
+ end
32
33
 
33
- def render_layout
34
- end
34
+ def render_layout
35
+ end
35
36
 
36
- def render_content
37
- @content.raw_content
38
- end
37
+ def render_content
38
+ @content.raw_content
39
+ end
39
40
 
40
- def has_layout?
41
- @content.layout? && layout_exists?
42
- end
41
+ def has_layout?
42
+ @content.layout? && layout_exists?
43
+ end
43
44
 
44
- def layout_path
45
- "#{config['path']}/_layouts/#{@content.layout}.haml"
46
- end
45
+ def layout_path
46
+ "#{config['path']}/_layouts/#{@content.layout}.haml"
47
+ end
47
48
 
48
- def layout_exists?
49
- File.exists? layout_path
49
+ def layout_exists?
50
+ File.exists? layout_path
51
+ end
50
52
  end
51
53
  end
@@ -5,27 +5,29 @@ require 'haml_content'
5
5
  require 'md_renderer'
6
6
  require 'haml_renderer'
7
7
 
8
- module RendererFactory
9
- module_function
8
+ module Wst
9
+ module RendererFactory
10
+ module_function
10
11
 
11
- def for content
12
- send content.class.name.downcase.to_sym, content
13
- end
12
+ def for content
13
+ send content.class.name.split('::').last.downcase.to_sym, content
14
+ end
14
15
 
15
- def post content
16
- MdRenderer.new content
17
- end
16
+ def post content
17
+ MdRenderer.new content
18
+ end
18
19
 
19
- def mdpage content
20
- MdRenderer.new content
21
- end
20
+ def mdpage content
21
+ MdRenderer.new content
22
+ end
22
23
 
23
- def hamlpage content
24
- HamlRenderer.new content
25
- end
24
+ def hamlpage content
25
+ HamlRenderer.new content
26
+ end
26
27
 
27
- def hamlcontent content
28
- HamlRenderer.new content
29
- end
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
- class Wst
13
- include Logging
14
- include Configuration
13
+ module Wst
14
+ class Wst
15
+ include Logging
16
+ include Configuration
15
17
 
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
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
- logger.info "KSS".blue
52
- cssconf.each do |cssname|
53
- logger.info " #{cssname}"
54
- compile_css_expanded cssname
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
- logger.info "Js".blue
65
- jsconf.each do |jsname|
66
- logger.info " #{jsname}"
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
- 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
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
- 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
43
+ # Compile all js files
44
+ def js
45
+ @js_renderer.generate_all
98
46
  end
99
- end
100
47
 
101
- def pub
102
- logger.info "Pub".blue
103
- FileUtils.cp_r File.join(config['path'], '_pub', '.') , File.join(config['path'], '_site')
104
- end
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
- def contents all
107
- return all_content if all
108
- all_content.select { |c| c.published }
109
- end
54
+ private
110
55
 
111
- def all_content
112
- [Post.all, Page.all].flatten
113
- end
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
- 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
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
- File.open("#{config['path']}/_site/#{cssname.split('/').last}.css", "w") { |f| f.write(css) }
122
- end
85
+ def pub
86
+ logger.info 'Pub'.blue
123
87
 
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
88
+ out_dir = File.join(config['path'], '_site')
89
+ in_dir = File.join(config['path'], '_pub', '.')
129
90
 
130
- File.open("#{config['path']}/_kss/#{cssname.split('/').last}.css", "w") { |f| f.write(css) }
131
- end
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
- def get_css cssname
134
- Dir.glob(File.join(config['path'], '_css', "#{cssname}.*")).first
135
- end
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
- def sass_syntax css
138
- File.extname(css).delete('.').to_sym
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.0
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