stack 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,4 +1,4 @@
1
- Stack
1
+ stack
2
2
  =====
3
3
 
4
4
  Generates a static site from template files with YAML and Liquid. Stack supports template transformation through Markdown, Textile and Less CSS.
@@ -35,9 +35,13 @@ Usage
35
35
 
36
36
  Generate runs through the source and transforms the templates, if no source is specified the current directory will be used.
37
37
 
38
+ gen
39
+
40
+ Alias of `generate`.
41
+
38
42
  server
39
43
 
40
- Runs a web server serving the output of the transformed source, by default when running Stack in server mode your templates will be automatically transformed when changed (this can be disabled).
44
+ Runs a web server serving the output of the transformed source, by default when running stack in server mode your templates will be automatically transformed when changed (this can be disabled).
41
45
 
42
46
  watch
43
47
 
@@ -45,17 +49,24 @@ Watches a directory and re-builds whenever theres file changes.
45
49
 
46
50
  #### Options
47
51
 
48
- --source
52
+ --source [DIR]
53
+
54
+ Directory to use as the source for generating a site with stack, by default the current directory will be used.
55
+
56
+ --target [DIR]
49
57
 
50
- --target
58
+ Directory to use as the target directory, if none is specified the target will be a folder called `_stack` in the source directory.
51
59
 
52
60
  ##### Server Options
53
61
 
54
- --port
62
+ --port [PORT]
55
63
 
56
- --watches
64
+ Specifies the port number the server should use when serving content through the `server` command.
65
+
66
+ --disable-watch
67
+
68
+ Disables automatic transformation when serving content through the `server` command.
57
69
 
58
-
59
70
  ### Ruby
60
71
 
61
72
  require 'stack'
@@ -65,7 +76,7 @@ Watches a directory and re-builds whenever theres file changes.
65
76
  Templates and YAML
66
77
  ------------------
67
78
 
68
- Template files can contain YAML block's that are processed by Stack and can be used to define Liquid variables for use in your templates. A YAML block can be something like;
79
+ Template files can contain YAML block's that are processed by stack and can be used to define Liquid variables for use in your templates. A YAML block can be something like;
69
80
 
70
81
  ---
71
82
  layout: application
@@ -80,11 +91,11 @@ This specifies the layout file to use around the content, theres no need to spec
80
91
 
81
92
  generator
82
93
 
83
- This variable holds the current hash used to transform the current template. You should not override this from the YAML block.
94
+ This variable holds the current hash used to transform the current template. You should not override this from the YAML block.
84
95
 
85
96
  generator.time
86
97
 
87
- The current Time from when the Stack processed and transformed the templates.
98
+ The current Time from when the stack processed and transformed the templates.
88
99
 
89
100
  generator.processed_at
90
101
 
data/Rakefile CHANGED
@@ -20,6 +20,7 @@ begin
20
20
  gem.add_dependency "maruku", ">= 0.5.9"
21
21
  gem.add_dependency "less", ">= 1.0.0"
22
22
  gem.add_dependency "directory_watcher", ">= 1.2.0"
23
+ gem.add_dependency "mash", ">= 0.0.3"
23
24
 
24
25
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
25
26
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 6
4
+ :patch: 7
data/lib/core_ext/hash.rb CHANGED
@@ -1,9 +1,3 @@
1
- class String
2
- def liquify(payload)
3
- return Liquid::Template.parse(self).render(Mash.new(payload))
4
- end
5
- end
6
-
7
1
  class Hash
8
2
 
9
3
  # Returns a new hash just like this one, but with all the string keys expressed as symbols.
@@ -0,0 +1,5 @@
1
+ class String
2
+ def liquify(payload)
3
+ return Liquid::Template.parse(self).render(Mash.new(payload))
4
+ end
5
+ end
@@ -1,6 +1,7 @@
1
1
  module Stack
2
2
  class Configuration
3
3
  attr_accessor :source, :target
4
+ attr_accessor :server_port, :server_watch
4
5
 
5
6
  def initialize(hash = nil)
6
7
  self.from_hash(hash)
@@ -10,7 +11,20 @@ module Stack
10
11
  if (hash != nil)
11
12
  @source = hash[:source]
12
13
  @target = hash[:target]
14
+ @server_port = hash[:server][:port]
15
+ @server_watch = hash[:server][:watch]
13
16
  end
14
17
  end
18
+
19
+ def to_hash
20
+ {
21
+ :source => self.source,
22
+ :target => self.target,
23
+ :server => {
24
+ :port => self.server_port,
25
+ :watch => self.server_watch
26
+ }
27
+ }
28
+ end
15
29
  end
16
30
  end
@@ -7,6 +7,8 @@ module Stack
7
7
  attr_accessor :layouts
8
8
  attr_accessor :pages
9
9
 
10
+ attr_accessor :remove_first
11
+
10
12
  attr_accessor :processed_at, :transformed_at
11
13
 
12
14
  def initialize(source, target, parent = nil)
@@ -14,6 +16,8 @@ module Stack
14
16
  self.target = target
15
17
  self.parent = parent
16
18
 
19
+ self.remove_first = false
20
+
17
21
  self.layouts = (parent) ? parent.layouts.dup : { }
18
22
 
19
23
  self.children = [ ]
@@ -54,6 +58,10 @@ module Stack
54
58
  end
55
59
 
56
60
  def transform!
61
+ if self.remove_first
62
+ FileUtils.rm_r self.target
63
+ end
64
+
57
65
  self.transformed_at = Time.now
58
66
 
59
67
  self.pages.each do |name, page|
data/lib/stack/runner.rb CHANGED
@@ -44,9 +44,11 @@ module Stack
44
44
  @generator.transform!
45
45
  when /(server)/
46
46
  # make a watcher
47
- watcher = Stack::Watcher.new(@generator)
48
- watcher.keep_alive = false
49
- watcher.observe
47
+ if Stack::runner.configuration.server_watch
48
+ watcher = Stack::Watcher.new(@generator)
49
+ watcher.keep_alive = false
50
+ watcher.observe
51
+ end
50
52
  # and a server
51
53
  server = Stack::Server.new(@generator)
52
54
  server.observe
@@ -54,6 +56,12 @@ module Stack
54
56
  # setup a watcher
55
57
  watcher = Stack::Watcher.new(@generator)
56
58
  watcher.observe
59
+ when /(create)/
60
+ File.open("#{Stack::runner.configuration.source}/_stack.yml", "w") { |file|
61
+ YAML.dump(Stack::runner.configuration.to_hash, file)
62
+ }
63
+
64
+ puts "Created configuration file at '#{Stack::runner.configuration.source}/_stack.yml'"
57
65
  end
58
66
  end
59
67
  end
data/lib/stack/server.rb CHANGED
@@ -13,7 +13,7 @@ module Stack
13
13
 
14
14
  def observe
15
15
  self.http_server = WEBrick::HTTPServer.new(
16
- :Port => 4000,
16
+ :Port => Stack::runner.configuration.server_port,
17
17
  :DocumentRoot => self.target
18
18
  )
19
19
 
@@ -0,0 +1,7 @@
1
+ module Stack
2
+ module Utils
3
+ def self.to_path(str)
4
+ "#{self.gsub(/[\/]+$/, '')}/"
5
+ end
6
+ end
7
+ end
data/lib/stack/watcher.rb CHANGED
@@ -28,11 +28,13 @@ module Stack
28
28
  self.directory_watcher.glob = dirs
29
29
 
30
30
  self.directory_watcher.add_observer do |*args|
31
+ time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
32
+ puts "[#{time}] #{args.size} files changed."
31
33
  self.generator.process!
32
34
  self.generator.transform!
33
35
 
34
36
  time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
35
- puts "[#{time}] #{args.size} files changed and processed."
37
+ puts "[#{time}] #{args.size} files processed."
36
38
  end
37
39
 
38
40
  self.directory_watcher.start
data/lib/stack.rb CHANGED
@@ -10,6 +10,7 @@ require 'RedCloth'
10
10
  require 'less'
11
11
  require 'webrick'
12
12
 
13
+ require 'core_ext/string'
13
14
  require 'core_ext/hash'
14
15
 
15
16
  require 'stack/configuration'
@@ -21,27 +22,33 @@ require 'stack/parsable'
21
22
  require 'stack/server'
22
23
  require 'stack/watcher'
23
24
 
24
- require 'stack/templates/page'
25
- require 'stack/templates/layout'
26
-
27
25
  require 'stack/filters/register'
28
26
  require 'stack/filters/standard'
29
27
  require 'stack/filters/convertors'
30
28
  require 'stack/filters/datetime'
31
29
  require 'stack/filters/string'
32
30
 
31
+ require 'stack/templates/page'
32
+ require 'stack/templates/layout'
33
+
34
+ require 'stack/utils/standard'
35
+
33
36
  module Stack
34
37
  # Default options used by stack, overridden from the command line or YML configration file.
35
38
  DEFAULTS = {
36
39
  :source => '.',
37
- :target => File.join('.', '_stack')
40
+ :target => File.join('.', '_stack'),
41
+ :server => {
42
+ :port => 4000,
43
+ :watch => true
44
+ }
38
45
  }.freeze
39
46
 
40
47
  # Array of valid commands stack can use
41
- COMMANDS = %w(create generate server watch)
48
+ COMMANDS = %w(create generate gen server watch)
42
49
 
43
50
  # Array of transformable extensions (these extensions go through the liquid transformer)
44
- EXTENSIONS = %w(.html .markdown .mdown .mkdn .md .textile .js .css)
51
+ EXTENSIONS = %w(.html .markdown .mdown .mkdn .md .textile .js .less .css)
45
52
 
46
53
  class << self
47
54
  attr_accessor :runner
@@ -49,19 +56,31 @@ module Stack
49
56
 
50
57
  # Parses the options configuration from the command line
51
58
  def self.parse!(argv)
52
- config = { }
59
+ config = Stack::DEFAULTS.dup
53
60
 
54
61
  parser = OptionParser.new do |opts|
55
- opts.banner = "Usage: stack [options] #{Stack::COMMANDS.join('|')}"
62
+ opts.banner = "Usage: stack #{Stack::COMMANDS.join('|')} [options...]"
56
63
 
64
+ opts.separator ""
65
+ opts.separator "Generator options:"
66
+
57
67
  opts.on("-s", "--source [DIR]", "Directory to use as the source for generating a stack") do |l|
58
68
  if !l.nil?
59
69
  config[:source] = l
60
- config[:target] = "#{config[:source]}_stack"
70
+ config[:target] = File.join(config[:source], "_stack")
61
71
  end
62
72
  end
63
73
  opts.on("-t", "--target [DIR]", "Directory to use as the target directory") do |l| config[:target] = l unless l.nil? end
64
74
 
75
+ opts.separator ""
76
+ opts.separator "Server options:"
77
+
78
+ opts.on("-p", "--port [PORT]", "Port number to use when serving content") do |l| config[:server][:port] = l unless l.nil? end
79
+ opts.on("--disable-watch", "--disable-watch", "Disables automatic transformation when serving content") do |l| config[:server][:watch] = false end
80
+
81
+ opts.separator ""
82
+ opts.separator "Common options:"
83
+
65
84
  opts.on_tail("-h", "--help", "Show this message") { puts opts; exit }
66
85
  opts.on_tail("-v", "--version", "Show version") do puts "stack #{Stack::version}"; exit; end
67
86
  end
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - sixones
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-31 00:00:00 +00:00
12
+ date: 2009-11-01 00:00:00 +00:00
13
13
  default_executable: stack
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -72,6 +72,16 @@ dependencies:
72
72
  - !ruby/object:Gem::Version
73
73
  version: 1.2.0
74
74
  version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: mash
77
+ type: :runtime
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 0.0.3
84
+ version:
75
85
  description: Generates a static site from template files with YAML and Liquid. Stack supports template transformation through Markdown, Textile and Less CSS.
76
86
  email: dev@sixones.com
77
87
  executables:
@@ -88,6 +98,7 @@ files:
88
98
  - VERSION.yml
89
99
  - bin/stack
90
100
  - lib/core_ext/hash.rb
101
+ - lib/core_ext/string.rb
91
102
  - lib/stack.rb
92
103
  - lib/stack/configuration.rb
93
104
  - lib/stack/filters/convertors.rb
@@ -102,6 +113,7 @@ files:
102
113
  - lib/stack/template.rb
103
114
  - lib/stack/templates/layout.rb
104
115
  - lib/stack/templates/page.rb
116
+ - lib/stack/utils/standard.rb
105
117
  - lib/stack/watcher.rb
106
118
  - test/helper.rb
107
119
  - test/test_stack.rb