stack 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,8 @@
1
1
  = stack
2
2
 
3
- Description goes here.
3
+ Generates a static site from template files in Liquid, Markdown and Textile, based on Jekyll and Tzatziki.
4
+
5
+ Within template files, stack allows you to use bi-directional YAML variables and include files.
4
6
 
5
7
  == Note on Patches/Pull Requests
6
8
 
data/Rakefile CHANGED
@@ -10,9 +10,15 @@ begin
10
10
  gem.email = "dev@sixones.com"
11
11
  gem.homepage = "http://github.com/sixones/stack"
12
12
  gem.authors = ["sixones"]
13
+
13
14
  gem.files = FileList['lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
15
+
14
16
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
17
+
15
18
  gem.add_dependency "liquid", ">= 1.9.0"
19
+ gem.add_dependency "RedCloth", ">= 4.2.1"
20
+ gem.add_dependency "maruku", ">= 0.5.9"
21
+ gem.add_dependency "less", ">= 1.0.0"
16
22
 
17
23
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
24
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 3
4
+ :patch: 4
data/lib/core_ext/hash.rb CHANGED
@@ -1,3 +1,9 @@
1
+ class String
2
+ def liquify(payload)
3
+ return Liquid::Template.parse(self).render(Mash.new(payload))
4
+ end
5
+ end
6
+
1
7
  class Hash
2
8
 
3
9
  # Returns a new hash just like this one, but with all the string keys expressed as symbols.
@@ -1,9 +1,21 @@
1
1
  module Stack
2
2
  class Generator
3
+ attr_accessor :parent
4
+ attr_accessor :source, :target
5
+
6
+ attr_accessor :children
3
7
  attr_accessor :layouts
4
8
  attr_accessor :pages
5
9
 
6
- def initialize
10
+ def initialize(source, target, parent = nil)
11
+ self.source = source
12
+ self.target = target
13
+ self.parent = parent
14
+
15
+ self.layouts = (parent) ? parent.layouts.dup : { }
16
+
17
+ self.children = [ ]
18
+
7
19
  # read layouts
8
20
  # read pages
9
21
  # write pages
@@ -14,24 +26,50 @@ module Stack
14
26
  def process!
15
27
  read_layouts
16
28
  read_pages
29
+
30
+ read_children
17
31
  end
18
32
 
19
33
  def read_layouts
20
- @layouts = read_pages_from_directory("_layouts", Stack::Templates::Layout)
34
+ if File.exists?(File.join(self.source, "_layouts"))
35
+ @layouts = @layouts.merge(read_pages_from_directory("_layouts", Stack::Templates::Layout))
36
+ end
21
37
  end
22
38
 
23
39
  def read_pages
24
- @pages = read_pages_from_directory(Stack::runner.configuration.source, Stack::Templates::Page)
40
+ @pages = read_pages_from_directory(self.source, Stack::Templates::Page)
41
+ end
42
+
43
+ def read_children
44
+ entries = Dir.entries(self.source)
45
+ directories = entries.select { |e| File.directory?(File.join(self.source, e)) }
46
+ directories = directories.reject { |d| d[0..0]=~/\.|_/ or d[-1..-1]=="~" }
47
+ directories.each do |dir|
48
+ self.children.push(Stack::Generator.new(File.join(self.source, dir), File.join(self.target, dir), self))
49
+ end
25
50
  end
26
51
 
27
52
  def transform!
28
- puts @layouts
29
- puts @pages
30
-
31
53
  self.pages.each do |name, page|
32
- puts "Page -> #{name} #{page}"
33
54
  page.write!
34
55
  end
56
+
57
+ transform_assets
58
+
59
+ self.children.each { |c| c.transform! }
60
+ end
61
+
62
+ def transform_assets
63
+ files = Dir.entries(self.source)
64
+ files = files.reject { |e| File.directory?(File.join(self.source, e)) }
65
+ files = files.reject { |e| e[0..0]=~/\.|_/ or e[-1..-1]=="~" }
66
+ files = files.reject { |e| (%w(.yaml .yml)+Stack::EXTENSIONS).include?(File.extname(e)) } # Exception cases
67
+
68
+ FileUtils.mkdir_p(self.target)
69
+
70
+ files.each do |f|
71
+ FileUtils.cp(File.join(self.source, File.basename(f)), File.join(self.target, File.basename(f)))
72
+ end
35
73
  end
36
74
 
37
75
  def to_hash
@@ -45,16 +83,18 @@ module Stack
45
83
  pages = { }
46
84
 
47
85
  begin
48
- path = (folder == Stack::runner.configuration.source) ? folder : File.join(Stack::runner.configuration.source, folder)
49
- entries = Dir.entries(path)
86
+ path = (folder == self.source) ? folder : File.join(self.source, folder)
87
+ folder = (folder == self.source) ? folder : ""
50
88
 
89
+ entries = Dir.entries(path)
90
+
51
91
  files = entries.reject { |e| File.directory?(File.join(path, e)) }
52
92
  files = files.reject { |e| e[0..0]=~/\.|_/ or e[-1..-1]=="~" }
53
93
  files = files.select { |e| Stack::EXTENSIONS.include?(File.extname(e)) }
54
94
 
55
95
  files.each do |f|
56
96
  trans = transformable_klass.new(File.join(path, f), self)
57
- pages[f.split(".").first] = trans
97
+ pages["#{f.split(".").first}"] = trans
58
98
  end
59
99
  rescue Errno::ENOENT => e
60
100
  # Ignore
@@ -6,12 +6,10 @@ module Stack
6
6
 
7
7
  def parse!(raw_doc = self.raw, defaults = { })
8
8
  self.data, self.raw = extract_yaml(raw_doc, nil, defaults)
9
-
10
- puts self.data
11
9
  end
12
10
 
13
11
  def payload
14
- self.data.deep_symbolize.merge(:inline_data => inline_data)
12
+ self.data.deep_symbolize.merge(:data => inline_data)
15
13
  end
16
14
 
17
15
  def extract_yaml(raw, replace = nil, defaults = { })
@@ -21,13 +19,9 @@ module Stack
21
19
  out = raw.dup
22
20
  i = -1
23
21
 
24
- puts "out -> #{out}"
25
-
26
22
  while out =~ /^(---\s*\n.*?\n?)(---.*?\n)/m
27
23
  yaml = $1.dup
28
- out = out.gsub(/#{Regexp.escape(yaml)}#{Regexp.escape($2)}/m,((i>-1) ? "{{ document.inline_data[#{i}] | render_table }}" : ""))
29
-
30
- puts "out2 -> #{out}"
24
+ out = out.gsub(/#{Regexp.escape(yaml)}#{Regexp.escape($2)}/m,((i>-1) ? "{{ document.data[#{i}] | render_table }}" : ""))
31
25
 
32
26
  d = YAML.load(yaml)
33
27
 
data/lib/stack/runner.rb CHANGED
@@ -37,7 +37,7 @@ module Stack
37
37
 
38
38
  # Runs the specified command
39
39
  def run_command
40
- @generator = Stack::Generator.new
40
+ @generator = Stack::Generator.new(Stack::runner.configuration.source, Stack::runner.configuration.target)
41
41
  @generator.transform!
42
42
  end
43
43
  end
@@ -4,15 +4,25 @@ module Stack
4
4
 
5
5
  attr_accessor :basename
6
6
  attr_accessor :path
7
+ attr_accessor :original_extension
8
+ attr_accessor :extension
7
9
 
8
10
  attr_accessor :raw
9
11
 
10
12
  def initialize(path, generator = nil)
11
13
  self.generator = generator
12
14
  self.path = path
15
+ self.original_extension = "html"
13
16
 
14
17
  if File.file?(path)
15
18
  self.basename = File.basename(path)
19
+ ext = File.extname(path)
20
+
21
+ self.original_extension = ext[1, ext.length]
22
+ self.extension = self.original_extension
23
+
24
+ puts self.original_extension
25
+ puts self.extension
16
26
 
17
27
  read
18
28
  end
@@ -26,15 +36,33 @@ module Stack
26
36
 
27
37
  def render(_payload = { }, do_layout = true)
28
38
  _payload = template_payload.deep_merge(_payload)
29
-
30
- content = Liquid::Template.parse(self.raw).render(_payload)
39
+
40
+ layout_name = _payload[:layout]
41
+
42
+ if (layout_name and do_layout)
43
+ puts "has layout! #{layout_name}"
44
+
45
+ # get layout
46
+ _tpl_payload = self.generator.layouts[layout_name].template_payload
47
+ _tpl_payload.delete(:layout)
48
+
49
+ puts _tpl_payload.inspect
50
+ puts "\n"
51
+
52
+ _payload = _payload.merge(_tpl_payload)
53
+ end
54
+
55
+ puts _payload.inspect
56
+ puts "\n\n"
57
+
58
+ content = Liquid::Template.parse(self.raw).render(Mash.new(_payload))
31
59
  content = self.transform(content)
32
60
 
33
- if (layout_name = _payload[:layout]) and (do_layout)
61
+ if (layout_name and do_layout)
34
62
  _payload.delete(:layout)
35
63
  begin
36
- _payload = _payload.deep_merge({ "content" => content })
37
- puts _payload
64
+ _payload = _payload.merge({ :content => content })
65
+
38
66
  content = self.generator.layouts[layout_name].render(_payload)
39
67
  rescue => e
40
68
  STDERR.puts e.to_str
@@ -46,6 +74,7 @@ module Stack
46
74
 
47
75
  def template_payload
48
76
  {
77
+ :template => self.to_hash,
49
78
  :generator => self.generator.to_hash
50
79
  }.merge(self.payload)
51
80
  end
@@ -54,20 +83,31 @@ module Stack
54
83
  raise InterfaceNotProvided
55
84
  end
56
85
 
86
+ def to_hash
87
+ {
88
+
89
+ }.merge(self.payload)
90
+ end
91
+
57
92
  def transform(content = self.raw)
58
93
  case self.basename
59
94
  when /\.textile/
95
+ self.extension = "html"
60
96
  RedCloth.new(content).to_html
61
- when /\.(mdown|markdown)/
97
+ when /\.(mdown|markdown|mkdn|md)/
98
+ self.extension = "html"
62
99
  Maruku.new(content).to_html
100
+ when /\.(less)/
101
+ self.extension = "css"
102
+ Less::Engine.new(content).to_css
103
+ when /\.(liquid|liq)/
104
+ self.extension = "html"
63
105
  else
64
106
  content
65
107
  end
66
108
  end
67
109
 
68
110
  def write!(content = self.render)
69
- puts write_path
70
-
71
111
  FileUtils.mkdir_p(File.dirname(write_path))
72
112
  out = File.open(write_path, "w+")
73
113
  out.rewind
@@ -76,20 +116,19 @@ module Stack
76
116
  end
77
117
 
78
118
  def write_path
79
- File.join(Stack::runner.configuration.target, self.write_filename)
119
+ File.join(self.generator.target, self.write_filename)
80
120
  end
81
121
 
82
122
  def write_basename
83
- if basename
84
- ext = File.extname(basename)
85
- basename[0..(basename.length - ext.length - 1)]
123
+ if self.basename
124
+ self.basename.gsub(".#{self.original_extension}", "")
86
125
  else
87
126
  @write_basename ||= Digest::MD5.hexdigest(self.raw)
88
127
  end
89
128
  end
90
129
 
91
130
  def write_filename
92
- "#{write_basename}.html"
131
+ "#{write_basename}.#{self.extension}"
93
132
  end
94
133
  end
95
134
  end
@@ -9,6 +9,10 @@ module Stack
9
9
 
10
10
  parse!
11
11
  end
12
+
13
+ def payload
14
+ super
15
+ end
12
16
  end
13
17
  end
14
18
  end
data/lib/stack.rb CHANGED
@@ -1,7 +1,13 @@
1
1
  # rubygems
2
2
  require 'rubygems'
3
+
3
4
  require 'optparse'
5
+
4
6
  require 'liquid'
7
+ require 'maruku'
8
+ require 'mash'
9
+ require 'RedCloth'
10
+ require 'less'
5
11
 
6
12
  require 'core_ext/hash'
7
13
 
@@ -25,8 +31,8 @@ module Stack
25
31
  # Array of valid commands stack can use
26
32
  COMMANDS = %w(create generate server)
27
33
 
28
- # Array of valid extensions
29
- EXTENSIONS = %w(.html .markdown .mdown)
34
+ # Array of transformable extensions (these extensions go through the liquid transformer)
35
+ EXTENSIONS = %w(.html .markdown .mdown .mkdn .md .textile .js .css)
30
36
 
31
37
  class << self
32
38
  attr_accessor :runner
@@ -48,7 +54,7 @@ module Stack
48
54
  opts.on("-t", "--target [DIR]", "Directory to use as the target directory") do |l| config[:target] = l unless l.nil? end
49
55
 
50
56
  opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
51
- opts.on_tail("-v", "--version" "Show version") do puts "stack #{Stack::version}"; exit; end
57
+ opts.on_tail("-v", "--version", "Show version") do puts "stack #{Stack::version}"; exit; end
52
58
  end
53
59
 
54
60
  parser.parse! argv
@@ -61,7 +67,7 @@ module Stack
61
67
  # Merges the configuration from YAML file, command line and defaults
62
68
  def self.configuration(override)
63
69
  config = { }
64
- source = File.join(override['source'] || Stack::DEFAULTS[:source])
70
+ source = File.join(override[:source] || Stack::DEFAULTS[:source])
65
71
 
66
72
  config_file = File.join(source, "_stack.yml")
67
73
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sixones
@@ -32,6 +32,36 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.9.0
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: RedCloth
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 4.2.1
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: maruku
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.5.9
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: less
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.0.0
64
+ version:
35
65
  description: Generates a static site from template files in Liquid, Markdown and Textile.
36
66
  email: dev@sixones.com
37
67
  executables: