smallcage 0.2.7 → 0.2.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24a1fa9291e27aa8accda9f6a2f59110ed2e85e6
4
- data.tar.gz: eef2ad497718133501587a57a06b6444a047988f
3
+ metadata.gz: 0dffbb6fce3a9475d63031e493df9fca89882db8
4
+ data.tar.gz: d74db6f35ee176c826eca45cb4ad466a76a54f75
5
5
  SHA512:
6
- metadata.gz: 30db05e645ca960f444d8a9f23fc1e724199e053cc29ccfe1e69cb03117f4e08d1d6f02daff9bbd60cd44a77fc513e9f46b6ca2c1691c9598d899957781b8760
7
- data.tar.gz: 1c9dbed249dc5512594639aa1600721c72760186b47b3819feb5fa5b628f943090871fa261c2f9962b7818cbd9f64de95a0877ed53d2f4e75a38308b6acf7172
6
+ metadata.gz: 1bfeb6c9c749416e15a47cd3d520530aa36fd4384bb91fcfae8b317ae2f1090e79734f16523b95b256241d0090dc1f7375026268d5fe437bfabf17efcfa58463
7
+ data.tar.gz: 9106bd451c8b31d2948fcb56ce78b0cdd8987aeddd5c2fc2c4f815d6ea122362f283f20d8a755fb2e4195120010c77e0b26b618c0f9bc980e4c5ecf1f53ddb1d
@@ -47,8 +47,14 @@ module SmallCage::Commands
47
47
  private :expire_old_files
48
48
 
49
49
  def render_smc_files
50
- @loader.each_smc_obj do |obj|
51
- render_smc_obj(obj)
50
+ if @opts[:fast]
51
+ @loader.each_smc_obj_using_target_template(@list) do |obj|
52
+ render_smc_obj(obj)
53
+ end
54
+ else
55
+ @loader.each_smc_obj do |obj|
56
+ render_smc_obj(obj)
57
+ end
52
58
  end
53
59
  end
54
60
  private :render_smc_files
@@ -67,10 +73,11 @@ module SmallCage::Commands
67
73
  mark = obj['path'].exist? ? 'U ' : 'A '
68
74
  mtime ||= obj['path'].smc.stat.mtime.to_i
69
75
 
70
- if @opts[:fast]
76
+ # Do not skip if the target is file.
77
+ if @opts[:fast] && @loader.dir_target && !@loader.target_template
71
78
  last_mtime = @list.mtime(obj['uri'].smc)
72
79
  if mtime == last_mtime
73
- @list.update(obj['uri'].smc, mtime, String.new(obj['uri']))
80
+ @list.update(obj['uri'].smc, mtime, String.new(obj['uri']), obj['template'])
74
81
  return
75
82
  end
76
83
  end
@@ -81,7 +88,7 @@ module SmallCage::Commands
81
88
  puts mark + obj['uri'] unless @opts[:quiet]
82
89
 
83
90
  # create new uri String to remove smc instance-specific method.
84
- @list.update(obj['uri'].smc, mtime, String.new(obj['uri']))
91
+ @list.update(obj['uri'].smc, mtime, String.new(obj['uri']), obj['template'])
85
92
  end
86
93
  private :render_single
87
94
 
@@ -10,14 +10,18 @@ module SmallCage
10
10
  LOCAL_PROP_FILE = '_local.smc'
11
11
  MAX_DEPTH = 100
12
12
 
13
- attr_reader :root, :target, :erb_base
13
+ attr_reader :root, :target, :erb_base, :target_template, :dir_target
14
14
 
15
15
  def initialize(target)
16
- target = Pathname.new(target.to_s.strip.chomp('/'))
17
- target = real_target(target)
18
-
19
- @target = target # absolute
20
- @root = self.class.find_root(target) # absolute
16
+ target = target.to_s.strip.chomp('/')
17
+ if target.to_s =~ %r{(.*/|\A)_smc/templates/((?:.+/)?(?:[^/]+))\.rhtml\z}
18
+ target = Regexp.last_match[1]
19
+ target = '.' if target == ''
20
+ @target_template = Regexp.last_match[2]
21
+ end
22
+ @target = real_target(Pathname.new(target))
23
+ @dir_target = @target.directory?
24
+ @root = self.class.find_root(@target) # absolute
21
25
  @templates_dir = @root + '_smc/templates'
22
26
  @helpers_dir = @root + '_smc/helpers'
23
27
  @filters_dir = @root + '_smc/filters'
@@ -27,7 +31,7 @@ module SmallCage
27
31
 
28
32
  # return root dir Pathname object.
29
33
  def self.find_root(path, depth = MAX_DEPTH)
30
- fail "Not found: #{ path }" unless path.exist?
34
+ fail "Not found: #{path}" unless path.exist?
31
35
  d = path.realpath
32
36
  d = d.parent if d.file?
33
37
  loop do
@@ -35,11 +39,11 @@ module SmallCage
35
39
  break if d.root? || (depth -= 1) <= 0
36
40
  d = d.parent
37
41
  end
38
- fail "Root not found: #{ path }"
42
+ fail "Root not found: #{path}"
39
43
  end
40
44
 
41
45
  def load(path)
42
- fail "Not found: #{ path }" unless path.exist?
46
+ fail "Not found: #{path}" unless path.exist?
43
47
 
44
48
  docpath = DocumentPath.new(@root, path)
45
49
 
@@ -51,7 +55,7 @@ module SmallCage
51
55
  end
52
56
 
53
57
  def load_smc_file(docpath)
54
- fail "Path is not smc file: #{ docpath }" unless docpath.smc?
58
+ fail "Path is not smc file: #{docpath}" unless docpath.smc?
55
59
 
56
60
  result = create_base_smc_object(docpath.outfile.path, docpath.path,
57
61
  docpath.outuri, docpath.uri)
@@ -106,7 +110,7 @@ module SmallCage
106
110
  obj = YAML.load_stream(source)
107
111
  return result if obj.nil?
108
112
  rescue => e
109
- raise "Can't load file: #{ path } / #{ e }"
113
+ raise "Can't load file: #{path} / #{e}"
110
114
  end
111
115
  obj.documents.each do |o|
112
116
  case o
@@ -114,7 +118,7 @@ module SmallCage
114
118
  result.merge!(o)
115
119
  when Array
116
120
  result['arrays'] ||= []
117
- result['arrays'] << o
121
+ result['arrays'] << o
118
122
  else
119
123
  result['strings'] ||= []
120
124
  result['strings'] << o.to_s
@@ -138,7 +142,7 @@ module SmallCage
138
142
  end
139
143
 
140
144
  def template_path(name)
141
- result = @templates_dir + "#{ name }.rhtml"
145
+ result = @templates_dir + "#{name}.rhtml"
142
146
  return nil unless result.file?
143
147
  result
144
148
  end
@@ -149,6 +153,8 @@ module SmallCage
149
153
  next if path.basename.to_s == DIR_PROP_FILE
150
154
  next if path.basename.to_s == LOCAL_PROP_FILE
151
155
  obj = load(path)
156
+ next if @target_template && obj['template'] != @target_template
157
+
152
158
  yield obj
153
159
  end
154
160
  end
@@ -185,6 +191,18 @@ module SmallCage
185
191
  end
186
192
  end
187
193
 
194
+ # When the target is template, try to find source using the template.
195
+ def each_smc_obj_using_target_template(list, &block)
196
+ return each_smc_obj(&block) unless @target_template
197
+
198
+ list.filter_by_template(@target_template).each do |path|
199
+ path = @root + path[1..-1]
200
+ next unless path.file?
201
+ obj = load(path)
202
+ yield obj
203
+ end
204
+ end
205
+
188
206
  def real_target(target)
189
207
  return target.realpath if target.directory?
190
208
  return target.realpath if target.file? && target.to_s =~ /\.smc$/
@@ -208,7 +226,7 @@ module SmallCage
208
226
  end
209
227
  end
210
228
 
211
- helpers = SmallCage::AnonymousLoader.load(@helpers_dir, /([^\/]+_helper)\.rb\z/)
229
+ helpers = SmallCage::AnonymousLoader.load(@helpers_dir, %r{([^/]+_helper)\.rb\z})
212
230
  result.include_helpers(helpers[:module], helpers[:names])
213
231
 
214
232
  result
@@ -223,7 +241,7 @@ module SmallCage
223
241
  result = {}
224
242
  return {} unless @filters_dir.directory?
225
243
 
226
- filter_modules = SmallCage::AnonymousLoader.load(@filters_dir, /([^\/]+_filter)\.rb\z/)
244
+ filter_modules = SmallCage::AnonymousLoader.load(@filters_dir, %r{([^/]+_filter)\.rb\z})
227
245
  smc_module = filter_modules[:module].const_get('SmallCage')
228
246
 
229
247
  load_filters_config.each do |filter_type, filter_list|
@@ -81,28 +81,37 @@ module SmallCage
81
81
  item['mtime'].to_i
82
82
  end
83
83
 
84
- def update(srcuri, mtime, dsturi)
85
- update_list(srcuri, mtime, dsturi)
84
+ def filter_by_template(template)
85
+ result = []
86
+ @src_item_map.each do |src, item|
87
+ result << src if item['template'] == template
88
+ end
89
+ result
90
+ end
91
+
92
+ def update(srcuri, mtime, dsturi, template = nil)
93
+ update_list(srcuri, mtime, dsturi, template)
86
94
  stop_expiration(srcuri, dsturi)
87
95
  @update_count += 1
88
96
  end
89
97
 
90
- def update_list(srcuri, mtime, dsturi)
91
- add_list_item(srcuri, mtime, dsturi) unless update_list_item(srcuri, mtime, dsturi)
98
+ def update_list(srcuri, mtime, dsturi, template)
99
+ add_list_item(srcuri, mtime, dsturi, template) unless update_list_item(srcuri, mtime, dsturi, template)
92
100
  end
93
101
  private :update_list
94
102
 
95
- def update_list_item(srcuri, mtime, dsturi)
103
+ def update_list_item(srcuri, mtime, dsturi, template)
96
104
  return false unless @src_item_map[srcuri]
97
105
  item = @src_item_map[srcuri]
98
106
  item['mtime'] = mtime.to_i
107
+ item['template'] = template if template
99
108
  item['dst'] << dsturi unless item['dst'].include?(dsturi)
100
109
  true
101
110
  end
102
111
  private :update_list_item
103
112
 
104
- def add_list_item(srcuri, mtime, dsturi)
105
- item = { 'src' => srcuri, 'dst' => [dsturi], 'mtime' => mtime.to_i }
113
+ def add_list_item(srcuri, mtime, dsturi, template)
114
+ item = { 'src' => srcuri, 'dst' => [dsturi], 'mtime' => mtime.to_i, 'template' => template }
106
115
  @src_item_map[srcuri] = item
107
116
  @yaml['list'] << item
108
117
  end
@@ -1,3 +1,3 @@
1
1
  module SmallCage #:nodoc:
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smallcage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - SAITO Toshihiro
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-08-28 00:00:00.000000000 Z
13
+ date: 2015-08-31 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: SmallCage is a simple, but powerful website generator. It converts content
16
16
  and template files, which has common elements in a website, to a plain, static website.