stack 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 7
4
+ :patch: 8
@@ -5,6 +5,7 @@ module Stack
5
5
 
6
6
  attr_accessor :children
7
7
  attr_accessor :layouts
8
+ attr_accessor :articles
8
9
  attr_accessor :pages
9
10
 
10
11
  attr_accessor :remove_first
@@ -19,6 +20,7 @@ module Stack
19
20
  self.remove_first = false
20
21
 
21
22
  self.layouts = (parent) ? parent.layouts.dup : { }
23
+ self.articles = (parent) ? parent.articles.dup : { }
22
24
 
23
25
  self.children = [ ]
24
26
 
@@ -32,6 +34,7 @@ module Stack
32
34
  def process!
33
35
  self.processed_at = Time.now
34
36
 
37
+ read_articles
35
38
  read_layouts
36
39
  read_pages
37
40
 
@@ -44,6 +47,12 @@ module Stack
44
47
  end
45
48
  end
46
49
 
50
+ def read_articles
51
+ if File.exists?(File.join(self.source, "_articles"))
52
+ @articles = @articles.merge(read_pages_from_directory("_articles", Stack::Templates::Article))
53
+ end
54
+ end
55
+
47
56
  def read_pages
48
57
  @pages = read_pages_from_directory(self.source, Stack::Templates::Page)
49
58
  end
@@ -53,24 +62,46 @@ module Stack
53
62
  directories = entries.select { |e| File.directory?(File.join(self.source, e)) }
54
63
  directories = directories.reject { |d| d[0..0]=~/\.|_/ or d[-1..-1]=="~" }
55
64
  directories.each do |dir|
56
- self.children.push(Stack::Generator.new(File.join(self.source, dir), File.join(self.target, dir), self))
65
+ gen = Stack::Generator.new(File.join(self.source, dir), File.join(self.target, dir), self)
66
+ #gen.process!
67
+ self.children.push(gen)
57
68
  end
58
69
  end
59
70
 
60
- def transform!
71
+ def transform!(match_only = nil)
61
72
  if self.remove_first
62
73
  FileUtils.rm_r self.target
63
74
  end
64
75
 
65
76
  self.transformed_at = Time.now
66
77
 
78
+ self.articles.each do |name, article|
79
+ if (match_only)
80
+ match_only.each { |m|
81
+ if File.dirname(m.path) == File.dirname(article.path) && File.basename(m.path) == article.basename
82
+ article.write!
83
+ end
84
+ }
85
+ else
86
+ article.write!
87
+ end
88
+ end
89
+
67
90
  self.pages.each do |name, page|
68
- page.write!
91
+ if (match_only)
92
+ match_only.each { |m|
93
+ if File.dirname(m.path) == File.dirname(page.path) && File.basename(m.path) == page.basename
94
+ page.write!
95
+ end
96
+ }
97
+ else
98
+ page.write!
99
+ end
69
100
  end
70
101
 
71
102
  transform_assets
72
103
 
73
- self.children.each { |c| c.transform! }
104
+ self.children.each { |c| c.transform!(match_only) }
74
105
  end
75
106
 
76
107
  def transform_assets
@@ -90,8 +121,20 @@ module Stack
90
121
  {
91
122
  :processed_at => self.processed_at,
92
123
  :transformed_at => self.transformed_at,
93
- :time => Time.now
124
+ :time => Time.now,
125
+ :articles => self.articles_payload
126
+ }
127
+ end
128
+
129
+ def articles_payload
130
+ a = Array.new
131
+
132
+ self.articles.each { |name, article|
133
+ article.inspect
134
+ a.push(article.payload)
94
135
  }
136
+
137
+ a
95
138
  end
96
139
 
97
140
  private
data/lib/stack/runner.rb CHANGED
@@ -7,6 +7,7 @@ module Stack
7
7
 
8
8
  def initialize(argv)
9
9
  @argv = argv
10
+
10
11
  @options = { }
11
12
 
12
13
  parse!
@@ -48,6 +49,8 @@ module Stack
48
49
  watcher = Stack::Watcher.new(@generator)
49
50
  watcher.keep_alive = false
50
51
  watcher.observe
52
+ else
53
+ #@generator.transform!
51
54
  end
52
55
  # and a server
53
56
  server = Stack::Server.new(@generator)
data/lib/stack/server.rb CHANGED
@@ -21,6 +21,8 @@ module Stack
21
21
  self.http_server.start
22
22
  }
23
23
 
24
+ trap("INT") { self.http_server.shutdown }
25
+
24
26
  self.thread.join()
25
27
  end
26
28
  end
@@ -37,6 +37,11 @@ module Stack
37
37
  layout_name = _payload[:layout]
38
38
 
39
39
  if (layout_name and do_layout)
40
+ if !self.generator.layouts[layout_name]
41
+ puts "The layout `#{layout_name}` does not exist in `_layouts`."
42
+ exit
43
+ end
44
+
40
45
  # get layout
41
46
  _tpl_payload = self.generator.layouts[layout_name].template_payload
42
47
  _tpl_payload.delete(:layout)
@@ -49,6 +54,14 @@ module Stack
49
54
  _payload = _payload.merge(_tpl_payload)
50
55
  end
51
56
 
57
+ # here we have the payload
58
+ # look for the permalink?
59
+ permalink = _payload[:permalink]
60
+
61
+ if (permalink)
62
+ self.path = permalink
63
+ end
64
+
52
65
  #puts _payload.inspect
53
66
  #puts "\n\n"
54
67
 
@@ -0,0 +1,32 @@
1
+ module Stack
2
+ module Templates
3
+ class Article
4
+ include Template
5
+ include Parsable
6
+
7
+ attr_accessor :content
8
+
9
+ def initialize(*args)
10
+ super
11
+
12
+ parse!
13
+ end
14
+
15
+ def write!(*args)
16
+ super
17
+ end
18
+
19
+ def transform(content = self.raw)
20
+ self.content = super
21
+
22
+ self.content
23
+ end
24
+
25
+ def payload
26
+ super.merge({
27
+ :content => self.content
28
+ })
29
+ end
30
+ end
31
+ end
32
+ end
data/lib/stack/watcher.rb CHANGED
@@ -3,7 +3,8 @@ module Stack
3
3
  attr_accessor :source, :target
4
4
  attr_accessor :generator
5
5
  attr_accessor :directory_watcher
6
- attr_accessor :keep_alive
6
+ attr_accessor :keep_alive, :is_first_observe
7
+ attr_accessor :thread
7
8
 
8
9
  def initialize(generator)
9
10
  self.generator = generator
@@ -11,6 +12,8 @@ module Stack
11
12
  self.target = self.generator.target
12
13
 
13
14
  self.keep_alive = true
15
+
16
+ require 'directory_watcher'
14
17
  end
15
18
 
16
19
  def observe
@@ -28,20 +31,33 @@ module Stack
28
31
  self.directory_watcher.glob = dirs
29
32
 
30
33
  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."
33
- self.generator.process!
34
- self.generator.transform!
34
+ if self.is_first_observe
35
+ self.is_first_observe = false
36
+ else
37
+ time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
38
+ puts "[#{time}] #{args.size} files changed."
39
+ self.generator.process!
40
+
41
+ self.generator.transform!
35
42
 
36
- time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
37
- puts "[#{time}] #{args.size} files processed."
43
+ time = Time.now.strftime("%Y-%m-%d %H:%M:%S")
44
+ puts "[#{time}] #{args.size} files processed."
45
+ end
38
46
  end
39
47
 
40
- self.directory_watcher.start
48
+ #self.directory_watcher.start
41
49
 
42
- if self.keep_alive
43
- loop { sleep 1000 }
44
- end
50
+ self.thread = Thread.new {
51
+ self.directory_watcher.start
52
+ }
53
+
54
+ trap("INT") { self.directory_watcher.stop }
55
+
56
+ self.thread.join()
57
+
58
+ #if self.keep_alive
59
+ # loop { sleep 1000 }
60
+ #end
45
61
  end
46
62
  end
47
63
  end
data/lib/stack.rb CHANGED
@@ -2,7 +2,6 @@
2
2
  require 'rubygems'
3
3
 
4
4
  require 'optparse'
5
- require 'directory_watcher'
6
5
  require 'liquid'
7
6
  require 'maruku'
8
7
  require 'mash'
@@ -29,6 +28,7 @@ require 'stack/filters/datetime'
29
28
  require 'stack/filters/string'
30
29
 
31
30
  require 'stack/templates/page'
31
+ require 'stack/templates/article'
32
32
  require 'stack/templates/layout'
33
33
 
34
34
  require 'stack/utils/standard'
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.7
4
+ version: 0.0.8
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-11-01 00:00:00 +00:00
12
+ date: 2009-11-02 00:00:00 +00:00
13
13
  default_executable: stack
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -111,6 +111,7 @@ files:
111
111
  - lib/stack/runner.rb
112
112
  - lib/stack/server.rb
113
113
  - lib/stack/template.rb
114
+ - lib/stack/templates/article.rb
114
115
  - lib/stack/templates/layout.rb
115
116
  - lib/stack/templates/page.rb
116
117
  - lib/stack/utils/standard.rb