smallcage 0.1.4 → 0.1.5

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/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 0.1.5 2009-08-15
2
+
3
+ * use @erbout for ERB output buffer variable name.
4
+ * add ERB capture method to base_helper.rb.
5
+ * add get directory config method to base_helper.rb.
6
+ * add NKF helper to nkf project template.
7
+ * avoid error when filter config is empty.
8
+ * add statistics line to update command.
9
+ * do not abort auto update server when ERB error occurred.
10
+
1
11
  == 0.1.4 2009-07-27
2
12
 
3
13
  * add cache control filter and rake task (for CDN, etag, etc.).
data/README.rdoc ADDED
@@ -0,0 +1,74 @@
1
+ = SmallCage -- Lightweigt CMS Package.
2
+
3
+
4
+ == Installation
5
+
6
+ $ sudo gem install smallcage
7
+
8
+
9
+ == Usage
10
+
11
+ If successfully installed, smc command will be available.
12
+
13
+ $ smc
14
+ Usage: smc <subcommand> [options]
15
+ SmallCage 0.1.5 - Lightweight CMS Package.
16
+ Subcommands are:
17
+ update [path] Build smc contents.
18
+ clean [path] Remove files generated from *.smc source.
19
+ server [path] [port] Start HTTP server.
20
+ auto [path] [port] Start auto update daemon.
21
+ import [name|uri] Import project.
22
+ export [path] [outputpath] Export project.
23
+ manifest [path] Generate Manifest.html file.
24
+
25
+ Options are:
26
+
27
+ -h, --help Show this help message.
28
+ -v, --version Show version info.
29
+
30
+ Create document root.
31
+
32
+ $ mkdir htdocs
33
+ $ cd htdocs
34
+
35
+ Import default project.
36
+
37
+ $ smc import
38
+ Import: base
39
+ Create:
40
+ /_smc
41
+ /_smc/helpers
42
+ /_smc/helpers/base_helper.rb
43
+ /_smc/helpers/site_helper.rb
44
+ /_smc/templates
45
+ /_smc/templates/default.rhtml
46
+ /_smc/templates/footer.rhtml
47
+ /_smc/templates/header.rhtml
48
+
49
+ Import these files?[Yn]: y
50
+ A /_smc
51
+ A /_smc/helpers
52
+ A /_smc/helpers/base_helper.rb
53
+ A /_smc/helpers/site_helper.rb
54
+ A /_smc/templates
55
+ A /_smc/templates/default.rhtml
56
+ A /_smc/templates/footer.rhtml
57
+ A /_smc/templates/header.rhtml
58
+ :
59
+
60
+ Publish all smc files.
61
+
62
+ $ smc update
63
+ A /index.html
64
+ A /sample/index.html
65
+ A /sample/redirect.html
66
+ A /sample/sub/contents.html
67
+ A /sample/sub/index.html
68
+
69
+ Start HTTP server.
70
+
71
+ $ smc server . 8080
72
+
73
+ ...and access http://localhost:8080
74
+
data/Rakefile CHANGED
@@ -29,11 +29,11 @@ RDOC_OPTS = [
29
29
  "--charset", "utf-8",
30
30
  "--opname", "index.html",
31
31
  "--line-numbers",
32
- "--main", "README.txt",
32
+ "--main", "README.rdoc",
33
33
  "--inline-source",
34
34
  ]
35
35
 
36
- SRC_FILES = FileList.new(%w{Rakefile README.txt History.txt License.txt})
36
+ SRC_FILES = FileList.new(%w{Rakefile README.rdoc History.txt License.txt})
37
37
  SRC_FILES.include("{bin,doc,lib,test,project,spec}/**/*")
38
38
  SRC_FILES.exclude(/~$/)
39
39
 
@@ -42,7 +42,7 @@ spec = Gem::Specification.new do |s|
42
42
  s.version = VERS
43
43
  s.platform = Gem::Platform::RUBY
44
44
  s.has_rdoc = true
45
- s.extra_rdoc_files = ["README.txt", "History.txt"]
45
+ s.extra_rdoc_files = ["README.rdoc", "History.txt"]
46
46
  s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
47
47
  s.summary = DESCRIPTION
48
48
  s.description = DESCRIPTION
@@ -82,14 +82,14 @@ end
82
82
 
83
83
 
84
84
  Rake::RDocTask.new do |rdoc|
85
- rdoc.rdoc_dir = 'html'
85
+ rdoc.rdoc_dir = 'pkg/htdocs'
86
86
  rdoc.options += RDOC_OPTS
87
- rdoc.template = "resh"
87
+ #rdoc.template = "resh"
88
88
  #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
89
89
  if ENV['DOC_FILES']
90
90
  rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
91
91
  else
92
- rdoc.rdoc_files.include('README.txt', 'History.txt')
92
+ rdoc.rdoc_files.include('README.rdoc', 'History.txt')
93
93
  rdoc.rdoc_files.include('lib/**/*.rb')
94
94
  rdoc.rdoc_files.include('ext/**/*.c')
95
95
  end
@@ -43,7 +43,7 @@ Subcommands are:
43
43
  update [path] Build smc contents.
44
44
  clean [path] Remove files generated from *.smc source.
45
45
  server [path] [port] Start HTTP server.
46
- auto [path] [port] Start auto update daemon.
46
+ auto [path] [port] Start auto update server.
47
47
  import [name|uri] Import project.
48
48
  export [path] [outputpath] Export project.
49
49
  manifest [path] Generate Manifest.html file.
@@ -68,7 +68,13 @@ module SmallCage::Commands
68
68
  target_files = modified_files
69
69
 
70
70
  runner = SmallCage::Runner.new({ :path => @target })
71
- runner.update
71
+ begin
72
+ runner.update
73
+ rescue Exception => e
74
+ STDERR.puts e.to_s
75
+ STDERR.puts $@[0..4].join("\n")
76
+ STDERR.puts ":"
77
+ end
72
78
 
73
79
  update_http_server(target_files)
74
80
  puts_line
@@ -101,6 +107,12 @@ module SmallCage::Commands
101
107
  update_http_server(target_files)
102
108
  end
103
109
  puts_line
110
+ rescue Exception => e
111
+ STDERR.puts e.to_s
112
+ STDERR.puts $@[0..4].join("\n")
113
+ STDERR.puts ":"
114
+ print "\a" unless quiet? # Bell
115
+ puts_line
104
116
  end
105
117
  private :update_modified_files
106
118
 
@@ -9,6 +9,7 @@ module SmallCage::Commands
9
9
  end
10
10
 
11
11
  def execute
12
+ start = Time.now
12
13
  target = Pathname.new(@opts[:path])
13
14
  unless target.exist?
14
15
  raise "target directory or file does not exist.: " + target.to_s
@@ -18,10 +19,14 @@ module SmallCage::Commands
18
19
  @renderer = SmallCage::Renderer.new(@loader)
19
20
 
20
21
  urilist = render_smc_files
22
+ rendered = urilist.length
21
23
  if list_file.exist?
22
24
  urilist = delete_expired_files(urilist)
23
25
  end
24
26
  save_list(urilist)
27
+ elapsed = Time.now - start
28
+
29
+ puts "-- #{rendered} files. #{"%.3f" % elapsed} sec. #{"%.3f" % (elapsed/rendered)} sec/file."
25
30
  end
26
31
 
27
32
  def render_smc_files
@@ -245,13 +245,12 @@ module SmallCage
245
245
  result = {}
246
246
  return {} unless @filters_dir.directory?
247
247
 
248
- filters = load_anonymous(@filters_dir, %r{([^/]+_filter)\.rb$})
248
+ filter_modules = load_anonymous(@filters_dir, %r{([^/]+_filter)\.rb$})
249
+ smc_module = filter_modules[:module].const_get("SmallCage")
249
250
 
250
- config = load_filters_config
251
- config.each do |filter_type,filter_list|
251
+ load_filters_config.each do |filter_type,filter_list|
252
252
  result[filter_type] = []
253
- smc_module = filters[:module].const_get("SmallCage")
254
- filter_list.each do |fc|
253
+ filter_list.to_a.each do |fc|
255
254
  fc = { "name" => fc } if fc.is_a? String
256
255
  filter_class = smc_module.const_get(fc["name"].camelize)
257
256
  result[filter_type] << filter_class.new(fc)
@@ -264,7 +263,7 @@ module SmallCage
264
263
  def load_filters_config
265
264
  path = @filters_dir.join("filters.yml")
266
265
  return {} unless path.file?
267
- return YAML.load(path.read())
266
+ return YAML.load(path.read()) || {}
268
267
  end
269
268
  private :load_filters_config
270
269
 
@@ -11,14 +11,11 @@ class SmallCage::Renderer
11
11
  end
12
12
 
13
13
  def render_string(str, obj)
14
- begin
15
- erb_class = ERB.new(str, nil, '-').def_class(@loader.erb_base, "erb")
16
- result = erb_class.new(@loader, self, obj).erb
17
- rescue => e
18
- STDERR.puts "Can't render: #{obj["uri"]}"
19
- raise e
20
- end
21
- return result
14
+ erb_class = ERB.new(str, nil, '-', '@erbout').def_class(@loader.erb_base, "erb")
15
+ return erb_class.new(@loader, self, obj).erb
16
+ rescue => e
17
+ STDERR.puts "Can't render: #{obj["uri"]}"
18
+ raise e
22
19
  end
23
20
 
24
21
  end
@@ -2,7 +2,7 @@ module SmallCage #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -2,6 +2,7 @@ module SmallCage
2
2
  module BaseHelper
3
3
  include ERB::Util
4
4
 
5
+ # Glob files with regular expression.
5
6
  def _glob(path, rex)
6
7
  base_dir = nil
7
8
  if path.to_s[0] == ?/
@@ -15,26 +16,76 @@ module SmallCage
15
16
  entries = Dir.glob("#{base_dir}/**/*")
16
17
 
17
18
  result = []
18
- entries.each do |path|
19
- result << path if path.to_s =~ rex
19
+ entries.each do |entry|
20
+ result << entry if entry.to_s =~ rex
20
21
  end
21
22
  return result.sort
22
23
  end
23
24
 
24
- def _with(o)
25
- tmpobj = @obj
26
- @obj = o
25
+ # Switch current smc object and execute block.
26
+ #
27
+ # <%- docroot = dirs.first["path"]
28
+ # _with(_load(docroot + "/company_001.html.smc")) do -%>
29
+ # name: <%= name %><br />
30
+ # address: <%= address %>
31
+ # <%- end -%>
32
+ #
33
+ def _with(new_obj)
34
+ @obj, old_obj = new_obj, @obj
27
35
  yield
28
- @obj = tmpobj
36
+ ensure
37
+ @obj = old_obj
29
38
  end
30
39
 
40
+ # Load smc file.
41
+ #
42
+ # docroot = dirs.first["path"]
43
+ # item = _load(docroot + "/items/001.html.smc")
44
+ #
31
45
  def _load(path)
32
46
  path = Pathname.new(path)
33
47
  @loader.load(path)
34
48
  end
35
49
 
36
- def _erb(body)
37
- @renderer.render_string(body, @obj)
50
+ # Evaluate ERB source.
51
+ def _erb(source)
52
+ @renderer.render_string(source, @obj)
53
+ end
54
+
55
+ # Capture ERB output.
56
+ #
57
+ # def cdata(&block)
58
+ # src = _capture(&block)
59
+ # @erbout << "<![CDATA[" + src.gsub(/\]\]>/,"]]]]><![CDATA[>") + "]]>"
60
+ # end
61
+ #
62
+ # <%- cdata do -%>
63
+ # <<< Here is CDATA section. >>>
64
+ # <%- end -%>
65
+ #
66
+ def _capture(*args, &block)
67
+ @erbout, old_erbout = "", @erbout
68
+ block.call(*args)
69
+ return @erbout
70
+ ensure
71
+ @erbout = old_erbout
72
+ end
73
+
74
+ # Get value of
75
+ # - smc object
76
+ # - or directory config (_dir.smc)
77
+ # - or nil
78
+ def _get(name, obj = @obj)
79
+ return obj[name] if obj[name]
80
+ return _dir(name, obj)
81
+ end
82
+
83
+ # Return nearest parent directory config(_dir.smc) value.
84
+ def _dir(name, obj = @obj)
85
+ obj["dirs"].reverse.each do |dir|
86
+ return dir[name] if dir[name]
87
+ end
88
+ return nil
38
89
  end
39
90
 
40
91
  end
@@ -1,3 +1,2 @@
1
1
  after_rendering_filters:
2
2
  - name: nkf_filter
3
- args: "-W -s" # UTF-8 to SJIS
@@ -1,14 +1,42 @@
1
+ require "nkf"
2
+
1
3
  module SmallCage
2
- require "nkf"
3
-
4
+
5
+ # In _dir.smc or other *.smc, set charset like this:
6
+ #
7
+ # charset: Shift_JIS
8
+ #
4
9
  class NkfFilter
5
10
 
6
11
  def initialize(opts)
7
- @args = opts["args"]
8
12
  end
9
13
 
10
14
  def after_rendering_filter(obj, str)
11
- return NKF.nkf(@args, str)
15
+ charset = ""
16
+ if obj["charset"]
17
+ charset = obj["charset"]
18
+ else
19
+ obj["dirs"].reverse.each do |dir|
20
+ if dir["charset"]
21
+ charset = dir["charset"]
22
+ break
23
+ end
24
+ end
25
+ end
26
+
27
+ opt = ""
28
+ if charset =~ /^euc-jp$/i
29
+ opt = "-Wem0"
30
+ elsif charset =~ /^iso-2022-jp$/i
31
+ opt = "-Wjm0"
32
+ elsif charset =~ /^shift_jis$/i
33
+ opt = "-Wsm0"
34
+ else
35
+ STDERR.puts "Unknown charset: #{charset}" unless charset.empty?
36
+ return str
37
+ end
38
+
39
+ return NKF.nkf(opt, str)
12
40
  end
13
41
 
14
42
  end
@@ -0,0 +1,60 @@
1
+ require "nkf"
2
+
3
+ module SmallCage
4
+ module NkfHelper
5
+
6
+ def shift_jis(&block)
7
+ nkf("-Wsm0", &block)
8
+ end
9
+
10
+ def iso_2022_jp(&block)
11
+ nkf("-Wjm0", &block)
12
+ end
13
+
14
+ def euc_jp(&block)
15
+ nkf("-Wem0", &block)
16
+ end
17
+
18
+ def nkf(opt, &block)
19
+ src = _capture(&block)
20
+ @erbout << NKF.nkf(opt, src)
21
+ end
22
+
23
+ def charset
24
+ return _get("charset") || "UTF-8"
25
+ end
26
+
27
+ # Convert charset inside of block.
28
+ #
29
+ # <%- set_charset do -%>
30
+ # <%= header %>
31
+ # <%= body %>
32
+ # <%= footer %>
33
+ # <%- end -%>
34
+ #
35
+ # In _dir.smc or other *.smc:
36
+ #
37
+ # charset: Shift_JIS
38
+ #
39
+ # In header.rhtml:
40
+ #
41
+ # <meta http-equiv="Content-Type" content="text/html; charset=<%= charset %>">
42
+ #
43
+ # If you have to edit all templates to call set_charset method,
44
+ # you should use nkf_filter.rb instead.
45
+ #
46
+ def set_charset(&block)
47
+ c = charset()
48
+ if c =~ /^euc-jp$/i
49
+ euc_jp(&block)
50
+ elsif c =~ /^iso-2022-jp$/i
51
+ iso_2022_jp(&block)
52
+ elsif c =~ /^shift_jis$/i
53
+ shift_jis(&block)
54
+ else
55
+ yield
56
+ end
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1 @@
1
+ after_rendering_filters:
File without changes
@@ -20,6 +20,8 @@ describe "SmallCage::Commands::Manifest" do
20
20
  contents = <<'EOT'.split(/\n/)
21
21
  <li><a href="./_dir.smc">./_dir.smc</a></li>
22
22
  <li><a href="./_smc/">./_smc/</a></li>
23
+ <li><a href="./_smc/filters/">./_smc/filters/</a></li>
24
+ <li><a href="./_smc/filters/filters.yml">./_smc/filters/filters.yml</a></li>
23
25
  <li><a href="./a/">./a/</a></li>
24
26
  <li><a href="./a/b/">./a/b/</a></li>
25
27
  <li><a href="./a/b/c/">./a/b/c/</a></li>
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - SAITO Toshihiro
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-07-27 00:00:00 +09:00
14
+ date: 2009-08-15 00:00:00 +09:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -22,11 +22,11 @@ executables:
22
22
  extensions: []
23
23
 
24
24
  extra_rdoc_files:
25
- - README.txt
25
+ - README.rdoc
26
26
  - History.txt
27
27
  files:
28
28
  - Rakefile
29
- - README.txt
29
+ - README.rdoc
30
30
  - History.txt
31
31
  - License.txt
32
32
  - bin/smc
@@ -65,6 +65,7 @@ files:
65
65
  - project/news/_smc/helpers/news_helper.rb
66
66
  - project/nkf/_smc/filters/filters.yml
67
67
  - project/nkf/_smc/filters/nkf_filter.rb
68
+ - project/nkf/_smc/helpers/nkf_helper.rb
68
69
  - project/rake/_smc/Rakefile
69
70
  - project/rake/_smc/rakelib/csv.rake
70
71
  - project/rake/_smc/rakelib/svn.rake
@@ -107,7 +108,9 @@ files:
107
108
  - project/tutorial2/tutorial2/priorities.txt.smc
108
109
  - project/tutorial2/tutorial2/vars.txt.smc
109
110
  - spec/data/htdocs1/_dir.smc
111
+ - spec/data/htdocs1/_smc/filters/filters.yml
110
112
  - spec/data/htdocs1/a/b/c/index.html.smc
113
+ - spec/data/htdocs2/_smc/filters/filters.yml
111
114
  - spec/data/htdocs2/_smc/templates/dummy.rhtml
112
115
  - spec/data/htdocs2/a/b/c/test.html
113
116
  - spec/data/htdocs2/a/b/test.html
@@ -135,7 +138,7 @@ rdoc_options:
135
138
  - index.html
136
139
  - --line-numbers
137
140
  - --main
138
- - README.txt
141
+ - README.rdoc
139
142
  - --inline-source
140
143
  - --exclude
141
144
  - ^(examples|extras)/
data/README.txt DELETED
@@ -1,61 +0,0 @@
1
-
2
- SmallCage - Lightweigt CMS Package.
3
-
4
-
5
- INSTALL
6
-
7
- $ sudo gem install smallcage
8
-
9
-
10
- USAGE
11
-
12
- $ smc help
13
-
14
- Usage: smc <subcommand> [options]
15
- SmallCage 0.1.3 - Lightweight CMS Package.
16
- Subcommands are:
17
- update [path] Build smc contents.
18
- clean [path] Remove files generated from *.smc source.
19
- server [path] [port] Start HTTP server.
20
- auto [path] [port] Start auto update daemon.
21
- import [name|uri] Import project.
22
- export [path] [outputpath] Export project.
23
- manifest [path] Generate Manifest.html file.
24
-
25
- Options are:
26
-
27
- -h, --help Show this help message.
28
- -v, --version Show version info.
29
-
30
- $ mkdir htdocs
31
- $ cd htdocs
32
- $ smc import
33
- Import: base
34
- Create:
35
- /_smc
36
- /_smc/helpers
37
- /_smc/helpers/base_helper.rb
38
- /_smc/helpers/site_helper.rb
39
- /_smc/templates
40
- /_smc/templates/default.rhtml
41
- /_smc/templates/footer.rhtml
42
- /_smc/templates/header.rhtml
43
-
44
- Import these files?[yN]: y
45
- A /_smc
46
- A /_smc/helpers
47
- A /_smc/helpers/base_helper.rb
48
- :
49
-
50
- $ smc update
51
- A /index.html
52
- A /sample/index.html
53
- A /sample/redirect.html
54
- A /sample/sub/contents.html
55
- A /sample/sub/index.html
56
-
57
- $ smc server . 8080
58
- :
59
- ...and access
60
- http://localhost:8080/
61
-