stack 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown ADDED
@@ -0,0 +1,134 @@
1
+ Stack
2
+ =====
3
+
4
+ Generates a static site from template files with YAML and Liquid. Stack supports template transformation through Markdown, Textile and Less CSS.
5
+
6
+ Within template files, stack allows you to use bi-directional YAML variables and include files.
7
+
8
+ Dependencies
9
+ ------------
10
+
11
+ * [Liquid][] - Templating system
12
+ * [RedCloth][] - Textile transformation
13
+ * [Maruku][] - Markdown transformation
14
+ * [Less][] - CSS transformation
15
+
16
+ Install
17
+ -------
18
+
19
+ Available through [Gemcutter][].
20
+
21
+ gem install stack
22
+
23
+ Usage
24
+ -----
25
+
26
+ ### Command Line
27
+
28
+
29
+ cd /path/to/my/site
30
+ stack [command] [options]
31
+
32
+ #### Commands
33
+
34
+ generate
35
+
36
+ Generate runs through the source and transforms the templates, if no source is specified the current directory will be used.
37
+
38
+ server
39
+
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).
41
+
42
+ watch
43
+
44
+ Watches a directory and re-builds whenever theres file changes.
45
+
46
+ #### Options
47
+
48
+ --source
49
+
50
+ --target
51
+
52
+ ##### Server Options
53
+
54
+ --port
55
+
56
+ --watches
57
+
58
+
59
+ ### Ruby
60
+
61
+ require 'stack'
62
+
63
+ Stack::Generator.new("/path/to/source", "/path/to/target")
64
+
65
+ Templates and YAML
66
+ ------------------
67
+
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;
69
+
70
+ ---
71
+ layout: application
72
+ title: Page Title
73
+ ---
74
+
75
+ ### Pre-defined variables
76
+
77
+ layout
78
+
79
+ This specifies the layout file to use around the content, theres no need to specify the extension. The layout must be defined in a file inside a `_layout` folder that is within the current template scope, if you have templates defined in a sub-folder you can have a `_layout` folder that only templates in the sub-folder can access.
80
+
81
+ generator
82
+
83
+ This variable holds the current hash used to transform the current template. You should not override this from the YAML block.
84
+
85
+ generator.time
86
+
87
+ The current Time from when the Stack processed and transformed the templates.
88
+
89
+ generator.processed_at
90
+
91
+ The current Time the `generator` processed the templates.
92
+
93
+ generator.transformed_at
94
+
95
+ The current Time the `generator` transformed the templates.
96
+
97
+ ### Liquid Templates
98
+
99
+ Its out of the scope of this project's README file to describe how Liquid templating can be used, for more information see the [Liquid Wiki][].
100
+
101
+ #### Filters
102
+
103
+ {{ generator.time | date_to_xmlschema }} #=> 2009-10-31T21:16:06+00:00
104
+
105
+ Transforms a Time into a XML schema format string.
106
+
107
+ {{ generator.time | date_to_string }} #=> 31 Oct 2009
108
+
109
+ Transforms a Time into a formatted string.
110
+
111
+ {{ title | xml_escape }} #=>
112
+
113
+ Escapes the specified string for use in XML.
114
+
115
+ Contribute
116
+ ----------
117
+
118
+ * Fork the project.
119
+ * Make your feature addition or bug fix.
120
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
121
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
122
+ * Send me a pull request. Bonus points for topic branches.
123
+
124
+ License
125
+ -------
126
+
127
+ Copyright (c) 2009 Adam Livesley (sixones). See LICENSE for details.
128
+
129
+ [Liquid]: http://liquidmarkup.org/ "Liquid"
130
+ [RedCloth]: http://redcloth.org/ "RedCloth"
131
+ [Maruku]: http://maruku.rubyforge.org/ "Maruku"
132
+ [Less]: http://lesscss.org/ "Less"
133
+ [Gemcutter]: http://gemcutter.org/gems/stack "Gemcutter"
134
+ [Liquid Wiki]: http://wiki.github.com/tobi/liquid/ "Liquid Wiki"
data/Rakefile CHANGED
@@ -19,6 +19,7 @@ begin
19
19
  gem.add_dependency "RedCloth", ">= 4.2.1"
20
20
  gem.add_dependency "maruku", ">= 0.5.9"
21
21
  gem.add_dependency "less", ">= 1.0.0"
22
+ gem.add_dependency "directory_watcher", ">= 1.2.0"
22
23
 
23
24
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
24
25
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 5
4
+ :patch: 6
data/lib/stack.rb CHANGED
@@ -2,12 +2,13 @@
2
2
  require 'rubygems'
3
3
 
4
4
  require 'optparse'
5
-
5
+ require 'directory_watcher'
6
6
  require 'liquid'
7
7
  require 'maruku'
8
8
  require 'mash'
9
9
  require 'RedCloth'
10
10
  require 'less'
11
+ require 'webrick'
11
12
 
12
13
  require 'core_ext/hash'
13
14
 
@@ -17,10 +18,18 @@ require 'stack/runner'
17
18
 
18
19
  require 'stack/template'
19
20
  require 'stack/parsable'
21
+ require 'stack/server'
22
+ require 'stack/watcher'
20
23
 
21
24
  require 'stack/templates/page'
22
25
  require 'stack/templates/layout'
23
26
 
27
+ require 'stack/filters/register'
28
+ require 'stack/filters/standard'
29
+ require 'stack/filters/convertors'
30
+ require 'stack/filters/datetime'
31
+ require 'stack/filters/string'
32
+
24
33
  module Stack
25
34
  # Default options used by stack, overridden from the command line or YML configration file.
26
35
  DEFAULTS = {
@@ -29,7 +38,7 @@ module Stack
29
38
  }.freeze
30
39
 
31
40
  # Array of valid commands stack can use
32
- COMMANDS = %w(create generate server)
41
+ COMMANDS = %w(create generate server watch)
33
42
 
34
43
  # Array of transformable extensions (these extensions go through the liquid transformer)
35
44
  EXTENSIONS = %w(.html .markdown .mdown .mkdn .md .textile .js .css)
@@ -0,0 +1,19 @@
1
+ module Stack
2
+ module Filters
3
+ module Convertors
4
+ include Stack::Filters::Register
5
+
6
+ def from_markdown(content)
7
+ Maruku.new(content).to_html
8
+ end
9
+
10
+ def from_textile(content)
11
+ RedCloth.new(content).to_html
12
+ end
13
+
14
+ def from_less(content)
15
+ Less::Engine.new(content).to_css
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module Stack
2
+ module Filters
3
+ module DateTime
4
+ include Stack::Filters::Register
5
+
6
+ def date_to_string(date)
7
+ date.strftime("%d %b %Y")
8
+ end
9
+
10
+ def date_to_xmlschema(date)
11
+ date.strftime("%Y-%m-%dT%H:%M:%S%Z")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Stack
2
+ module Filters
3
+ module Register
4
+ def self.extensions; @@extensions; end
5
+
6
+ @@extensions = [ ]
7
+
8
+ def self.included(base)
9
+ @@extensions << base
10
+ end
11
+
12
+ def self.invoke_filter(name, params)
13
+ self.send(name, params)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ module Stack
2
+ module Filters
3
+ module Standard
4
+ include Stack::Filters::Register
5
+
6
+ def hello_world(input)
7
+ "Hello World!"
8
+ end
9
+
10
+ def length(input)
11
+ input.length
12
+ end
13
+
14
+ def escape(input)
15
+ CGI::escape(input)
16
+ end
17
+
18
+ def escape_html(input)
19
+ CGI::escapeHTML(input)
20
+ end
21
+
22
+ def escape_xml(input)
23
+ CGI::escapeHTML(input)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Stack
2
+ module Filters
3
+ module String
4
+ include Stack::Filters::Register
5
+
6
+ def count_words(input)
7
+ input.split.length
8
+ end
9
+ end
10
+ end
11
+ end
@@ -7,6 +7,8 @@ module Stack
7
7
  attr_accessor :layouts
8
8
  attr_accessor :pages
9
9
 
10
+ attr_accessor :processed_at, :transformed_at
11
+
10
12
  def initialize(source, target, parent = nil)
11
13
  self.source = source
12
14
  self.target = target
@@ -24,6 +26,8 @@ module Stack
24
26
  end
25
27
 
26
28
  def process!
29
+ self.processed_at = Time.now
30
+
27
31
  read_layouts
28
32
  read_pages
29
33
 
@@ -50,6 +54,8 @@ module Stack
50
54
  end
51
55
 
52
56
  def transform!
57
+ self.transformed_at = Time.now
58
+
53
59
  self.pages.each do |name, page|
54
60
  page.write!
55
61
  end
@@ -74,7 +80,9 @@ module Stack
74
80
 
75
81
  def to_hash
76
82
  {
77
-
83
+ :processed_at => self.processed_at,
84
+ :transformed_at => self.transformed_at,
85
+ :time => Time.now
78
86
  }
79
87
  end
80
88
 
data/lib/stack/runner.rb CHANGED
@@ -38,7 +38,23 @@ module Stack
38
38
  # Runs the specified command
39
39
  def run_command
40
40
  @generator = Stack::Generator.new(Stack::runner.configuration.source, Stack::runner.configuration.target)
41
- @generator.transform!
41
+
42
+ case self.command
43
+ when /(generate|gen)/
44
+ @generator.transform!
45
+ when /(server)/
46
+ # make a watcher
47
+ watcher = Stack::Watcher.new(@generator)
48
+ watcher.keep_alive = false
49
+ watcher.observe
50
+ # and a server
51
+ server = Stack::Server.new(@generator)
52
+ server.observe
53
+ when /(watch)/
54
+ # setup a watcher
55
+ watcher = Stack::Watcher.new(@generator)
56
+ watcher.observe
57
+ end
42
58
  end
43
59
  end
44
60
  end
@@ -0,0 +1,27 @@
1
+ module Stack
2
+ class Server
3
+ attr_accessor :source, :target
4
+ attr_accessor :generator
5
+ attr_accessor :http_server
6
+ attr_accessor :thread
7
+
8
+ def initialize(generator)
9
+ self.generator = generator
10
+ self.source = self.generator.source
11
+ self.target = self.generator.target
12
+ end
13
+
14
+ def observe
15
+ self.http_server = WEBrick::HTTPServer.new(
16
+ :Port => 4000,
17
+ :DocumentRoot => self.target
18
+ )
19
+
20
+ self.thread = Thread.new {
21
+ self.http_server.start
22
+ }
23
+
24
+ self.thread.join()
25
+ end
26
+ end
27
+ end
@@ -21,9 +21,6 @@ module Stack
21
21
  self.original_extension = ext[1, ext.length]
22
22
  self.extension = self.original_extension
23
23
 
24
- puts self.original_extension
25
- puts self.extension
26
-
27
24
  read
28
25
  end
29
26
  end
@@ -40,22 +37,22 @@ module Stack
40
37
  layout_name = _payload[:layout]
41
38
 
42
39
  if (layout_name and do_layout)
43
- puts "has layout! #{layout_name}"
44
-
45
40
  # get layout
46
41
  _tpl_payload = self.generator.layouts[layout_name].template_payload
47
42
  _tpl_payload.delete(:layout)
43
+ _tpl_payload.delete(:template)
44
+ _tpl_payload.delete(:generator)
48
45
 
49
- puts _tpl_payload.inspect
50
- puts "\n"
46
+ #puts _tpl_payload.inspect
47
+ #puts "\n"
51
48
 
52
49
  _payload = _payload.merge(_tpl_payload)
53
50
  end
54
51
 
55
- puts _payload.inspect
56
- puts "\n\n"
52
+ #puts _payload.inspect
53
+ #puts "\n\n"
57
54
 
58
- content = Liquid::Template.parse(self.raw).render(Mash.new(_payload))
55
+ content = Liquid::Template.parse(self.raw).render(Mash.new(_payload), Stack::Filters::Register.extensions)
59
56
  content = self.transform(content)
60
57
 
61
58
  if (layout_name and do_layout)
@@ -0,0 +1,45 @@
1
+ module Stack
2
+ class Watcher
3
+ attr_accessor :source, :target
4
+ attr_accessor :generator
5
+ attr_accessor :directory_watcher
6
+ attr_accessor :keep_alive
7
+
8
+ def initialize(generator)
9
+ self.generator = generator
10
+ self.source = self.generator.source
11
+ self.target = self.generator.target
12
+
13
+ self.keep_alive = true
14
+ end
15
+
16
+ def observe
17
+ dirs = ""
18
+
19
+ Dir.chdir(self.source) do
20
+ dirs = Dir['*'].select { |x| File.directory?(x) }
21
+ dirs -= ['_stack']
22
+ dirs = dirs.map { |x| "#{x}/**/*" }
23
+ dirs += ['*']
24
+ end
25
+
26
+ self.directory_watcher = DirectoryWatcher.new(self.source)
27
+ self.directory_watcher.interval = 1
28
+ self.directory_watcher.glob = dirs
29
+
30
+ self.directory_watcher.add_observer do |*args|
31
+ self.generator.process!
32
+ self.generator.transform!
33
+
34
+ time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
35
+ puts "[#{time}] #{args.size} files changed and processed."
36
+ end
37
+
38
+ self.directory_watcher.start
39
+
40
+ if self.keep_alive
41
+ loop { sleep 1000 }
42
+ end
43
+ end
44
+ end
45
+ 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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - sixones
@@ -62,6 +62,16 @@ dependencies:
62
62
  - !ruby/object:Gem::Version
63
63
  version: 1.0.0
64
64
  version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: directory_watcher
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.2.0
74
+ version:
65
75
  description: Generates a static site from template files with YAML and Liquid. Stack supports template transformation through Markdown, Textile and Less CSS.
66
76
  email: dev@sixones.com
67
77
  executables:
@@ -70,22 +80,29 @@ extensions: []
70
80
 
71
81
  extra_rdoc_files:
72
82
  - LICENSE
73
- - README.rdoc
83
+ - README.markdown
74
84
  files:
75
85
  - LICENSE
76
- - README.rdoc
86
+ - README.markdown
77
87
  - Rakefile
78
88
  - VERSION.yml
79
89
  - bin/stack
80
90
  - lib/core_ext/hash.rb
81
91
  - lib/stack.rb
82
92
  - lib/stack/configuration.rb
93
+ - lib/stack/filters/convertors.rb
94
+ - lib/stack/filters/datetime.rb
95
+ - lib/stack/filters/register.rb
96
+ - lib/stack/filters/standard.rb
97
+ - lib/stack/filters/string.rb
83
98
  - lib/stack/generator.rb
84
99
  - lib/stack/parsable.rb
85
100
  - lib/stack/runner.rb
101
+ - lib/stack/server.rb
86
102
  - lib/stack/template.rb
87
103
  - lib/stack/templates/layout.rb
88
104
  - lib/stack/templates/page.rb
105
+ - lib/stack/watcher.rb
89
106
  - test/helper.rb
90
107
  - test/test_stack.rb
91
108
  has_rdoc: true
data/README.rdoc DELETED
@@ -1,20 +0,0 @@
1
- = stack
2
-
3
- Generates a static site from template files with YAML and Liquid. Stack supports template transformation through Markdown, Textile and Less CSS.
4
-
5
- Within template files, stack allows you to use bi-directional YAML variables and include files.
6
-
7
- == Note on Patches/Pull Requests
8
-
9
- * Fork the project.
10
- * Make your feature addition or bug fix.
11
- * Add tests for it. This is important so I don't break it in a
12
- future version unintentionally.
13
- * Commit, do not mess with rakefile, version, or history.
14
- (if you want to have your own version, that is fine but
15
- bump version in a commit by itself I can ignore when I pull)
16
- * Send me a pull request. Bonus points for topic branches.
17
-
18
- == Copyright
19
-
20
- Copyright (c) 2009 Adam Livesley (sixones). See LICENSE for details.