smallcage 0.2.4 → 0.2.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.
Files changed (67) hide show
  1. data/.gitignore +1 -0
  2. data/.rubocop.yml +8 -0
  3. data/.travis.yml +1 -1
  4. data/Gemfile +16 -5
  5. data/Guardfile +4 -0
  6. data/History.rdoc +9 -5
  7. data/README.rdoc +3 -3
  8. data/Rakefile +1 -1
  9. data/bin/smc +4 -12
  10. data/lib/smallcage.rb +4 -1
  11. data/lib/smallcage/anonymous_loader.rb +32 -0
  12. data/lib/smallcage/application.rb +4 -5
  13. data/lib/smallcage/commands/auto.rb +16 -17
  14. data/lib/smallcage/commands/base.rb +4 -5
  15. data/lib/smallcage/commands/clean.rb +5 -5
  16. data/lib/smallcage/commands/export.rb +5 -5
  17. data/lib/smallcage/commands/import.rb +25 -27
  18. data/lib/smallcage/commands/manifest.rb +4 -4
  19. data/lib/smallcage/commands/server.rb +4 -4
  20. data/lib/smallcage/commands/update.rb +4 -5
  21. data/lib/smallcage/commands/uri.rb +3 -5
  22. data/lib/smallcage/document_path.rb +6 -9
  23. data/lib/smallcage/http_server.rb +9 -10
  24. data/lib/smallcage/loader.rb +19 -49
  25. data/lib/smallcage/misc.rb +1 -1
  26. data/lib/smallcage/renderer.rb +1 -1
  27. data/lib/smallcage/resources/auto.html +7 -7
  28. data/lib/smallcage/runner.rb +6 -6
  29. data/lib/smallcage/update_list.rb +2 -3
  30. data/lib/smallcage/version.rb +1 -1
  31. data/project/base/_smc/helpers/base_helper.rb +8 -9
  32. data/project/bluecloth/_smc/helpers/blue_cloth_helper.rb +2 -3
  33. data/project/cache/_smc/filters/cache_filter.rb +10 -12
  34. data/project/cache/_smc/rakelib/cache.rake +7 -8
  35. data/project/gdata/_smc/rakelib/gdata.rake +3 -5
  36. data/project/lang/_smc/helpers/lang_helper.rb +3 -3
  37. data/project/news/_smc/helpers/news_helper.rb +3 -4
  38. data/project/nkf/_smc/filters/nkf_filter.rb +6 -6
  39. data/project/nkf/_smc/helpers/nkf_helper.rb +8 -9
  40. data/project/rake/_smc/rakelib/svn.rake +5 -6
  41. data/project/redcloth/_smc/helpers/red_cloth_helper.rb +3 -3
  42. data/project/standard/_smc/helpers/menu_helper.rb +4 -5
  43. data/project/standard/_smc/templates/redirect.rhtml +1 -1
  44. data/spec/data/anonymous_loader/1/error1.rb +1 -0
  45. data/spec/data/anonymous_loader/1/error2.rb +1 -0
  46. data/spec/data/anonymous_loader/1/test1.rb +1 -0
  47. data/spec/data/anonymous_loader/1/test2.rb +1 -0
  48. data/spec/lib/smallcage/anonymous_loader_spec.rb +37 -0
  49. data/spec/lib/smallcage/application_spec.rb +271 -0
  50. data/spec/{smallcage → lib/smallcage}/commands/auto_spec.rb +0 -0
  51. data/spec/{export_spec.rb → lib/smallcage/commands/export_spec.rb} +8 -10
  52. data/spec/{import_spec.rb → lib/smallcage/commands/import_spec.rb} +5 -6
  53. data/spec/{manifest_spec.rb → lib/smallcage/commands/manifest_spec.rb} +4 -3
  54. data/spec/{smallcage → lib/smallcage}/commands/server_spec.rb +0 -0
  55. data/spec/{update_spec.rb → lib/smallcage/commands/update_spec.rb} +15 -19
  56. data/spec/{uri_spec.rb → lib/smallcage/commands/uri_spec.rb} +3 -4
  57. data/spec/{document_path_spec.rb → lib/smallcage/document_path_spec.rb} +19 -31
  58. data/spec/{loader_spec.rb → lib/smallcage/loader_spec.rb} +16 -18
  59. data/spec/lib/smallcage/misc_spec.rb +18 -0
  60. data/spec/{update_list_spec.rb → lib/smallcage/update_list_spec.rb} +18 -21
  61. data/spec/{smallcage_spec.rb → lib/smallcage_spec.rb} +1 -1
  62. data/spec/spec_helper.rb +5 -4
  63. metadata +85 -55
  64. checksums.yaml +0 -7
  65. data/Gemfile.lock +0 -32
  66. data/spec/misc_spec.rb +0 -25
  67. data/spec/smallcage/application_spec.rb +0 -271
@@ -1,5 +1,5 @@
1
1
 
2
- # From active-support/inflector.rb
2
+ # From active-support/inflector.rb
3
3
  class String
4
4
  def camelize(first_letter_in_uppercase = true)
5
5
  s = self
@@ -11,7 +11,7 @@ class SmallCage::Renderer
11
11
  @current_template = path
12
12
  return render_string(path.read, obj)
13
13
  end
14
-
14
+
15
15
  def render_string(str, obj)
16
16
  erb_class = ERB.new(str, nil, '-', '@erbout').def_class(@loader.erb_base, "erb")
17
17
  return erb_class.new(@loader, self, obj).erb
@@ -24,7 +24,7 @@ function getTransport() {
24
24
  function getSource(uri, loaded, failed) {
25
25
  var transport = getTransport();
26
26
  transport.open("GET", uri, true);
27
-
27
+
28
28
  transport.onreadystatechange=function() {
29
29
  if (transport.readyState == 4) {
30
30
  if (transport.status == 200) {
@@ -51,12 +51,12 @@ function checkUpdate() {
51
51
  if (loading) {
52
52
  return false;
53
53
  }
54
-
54
+
55
55
  if (scrollWait) {
56
56
  targetWindow.scrollBy(scrollWait.x, scrollWait.y);
57
57
  scrollWait = null;
58
58
  }
59
-
59
+
60
60
  var success = function(src) {
61
61
  loading = false;
62
62
  if (currentSrc == src) {
@@ -67,13 +67,13 @@ function checkUpdate() {
67
67
  lines = src.split("\n")
68
68
  var uri = lines[0];
69
69
  showPage(uri);
70
- document.getElementById("main").innerHTML =
70
+ document.getElementById("main").innerHTML =
71
71
  "<p>Latest Updated Page: <a href=\"" + uri + "\" target=\"smcauto\">" + uri + "</a></p><p>" + lines[1] + "</p>";
72
72
  };
73
73
  var failed = function(src) {
74
74
  document.getElementById("main").innerHTML = "<p>Load error</p>";
75
75
  };
76
-
76
+
77
77
  getSource("/_smc/update_uri", success, failed);
78
78
  loading = true;
79
79
  }
@@ -95,7 +95,7 @@ function showPage(uri) {
95
95
 
96
96
  var x = targetWindow.scrollX;
97
97
  var y = targetWindow.scrollY;
98
-
98
+
99
99
  targetWindow.location = realuri;
100
100
  if (currentUri == realuri) {
101
101
  scrollWait = {"x": x, "y":y};
@@ -112,7 +112,7 @@ function showPage(uri) {
112
112
  <body onLoad="initTimer(1000)">
113
113
 
114
114
  <div id="main">
115
- Latest Updated Page:
115
+ Latest Updated Page:
116
116
  </div>
117
117
 
118
118
  </body>
@@ -8,17 +8,17 @@ module SmallCage
8
8
  @opts = opts
9
9
  require_command "base"
10
10
  end
11
-
11
+
12
12
  def update
13
13
  require_command "update"
14
14
  SmallCage::Commands::Update.execute(@opts)
15
15
  end
16
-
16
+
17
17
  def clean
18
18
  require_command "clean"
19
19
  SmallCage::Commands::Clean.execute(@opts)
20
20
  end
21
-
21
+
22
22
  def server
23
23
  require_command "server"
24
24
  SmallCage::Commands::Server.execute(@opts)
@@ -28,17 +28,17 @@ module SmallCage
28
28
  require_command "auto"
29
29
  SmallCage::Commands::Auto.execute(@opts)
30
30
  end
31
-
31
+
32
32
  def import
33
33
  require_command "import"
34
34
  SmallCage::Commands::Import.execute(@opts)
35
35
  end
36
-
36
+
37
37
  def manifest
38
38
  require_command "manifest"
39
39
  SmallCage::Commands::Manifest.execute(@opts)
40
40
  end
41
-
41
+
42
42
  def export
43
43
  require_command "export"
44
44
  SmallCage::Commands::Export.execute(@opts)
@@ -1,6 +1,6 @@
1
1
  module SmallCage
2
2
 
3
- # Updated files list model.
3
+ # Updated files list model.
4
4
  # Do not access File system except list.yml.
5
5
  class UpdateList
6
6
  attr_reader :update_count
@@ -96,7 +96,7 @@ module SmallCage
96
96
  @data["list"] << item
97
97
  end
98
98
  private :add_list_item
99
-
99
+
100
100
  def stop_expiration(srcuri, dsturi)
101
101
  @expired_src.delete(srcuri)
102
102
  @expired_dst[dsturi] = [false, srcuri]
@@ -138,6 +138,5 @@ module SmallCage
138
138
  return result
139
139
  end
140
140
  private :expire_dst
141
-
142
141
  end
143
142
  end
@@ -1,3 +1,3 @@
1
1
  module SmallCage #:nodoc:
2
- VERSION = "0.2.4"
2
+ VERSION = '0.2.5'
3
3
  end
@@ -14,7 +14,7 @@ module SmallCage
14
14
  end
15
15
 
16
16
  entries = Dir.glob("#{base_dir}/**/*")
17
-
17
+
18
18
  result = []
19
19
  entries.each do |entry|
20
20
  result << entry if entry.to_s =~ rex
@@ -29,14 +29,14 @@ module SmallCage
29
29
  # name: <%= name %><br />
30
30
  # address: <%= address %>
31
31
  # <%- end -%>
32
- #
32
+ #
33
33
  def _with(new_obj)
34
34
  @obj, old_obj = new_obj, @obj
35
35
  yield
36
36
  ensure
37
37
  @obj = old_obj
38
38
  end
39
-
39
+
40
40
  # Load smc file.
41
41
  #
42
42
  # docroot = dirs.first["path"]
@@ -46,17 +46,17 @@ module SmallCage
46
46
  path = Pathname.new(path)
47
47
  @loader.load(path)
48
48
  end
49
-
49
+
50
50
  # Evaluate ERB source.
51
51
  def _erb(source)
52
52
  @renderer.render_string(source, @obj)
53
53
  end
54
-
54
+
55
55
  # Capture ERB output.
56
56
  #
57
57
  # def cdata(&block)
58
58
  # src = _capture(&block)
59
- # @erbout << "<![CDATA[" + src.gsub(/\]\]>/,"]]]]><![CDATA[>") + "]]>"
59
+ # @erbout << "<![CDATA[" + src.gsub(/\]\]>/,"]]]]><![CDATA[>") + "]]>"
60
60
  # end
61
61
  #
62
62
  # <%- cdata do -%>
@@ -70,7 +70,7 @@ module SmallCage
70
70
  ensure
71
71
  @erbout = old_erbout
72
72
  end
73
-
73
+
74
74
  # Get value of
75
75
  # - smc object
76
76
  # - or directory config (_dir.smc)
@@ -80,13 +80,12 @@ module SmallCage
80
80
  return _dir(name, obj)
81
81
  end
82
82
 
83
- # Return nearest parent directory config(_dir.smc) value.
83
+ # Return nearest parent directory config(_dir.smc) value.
84
84
  def _dir(name, obj = @obj)
85
85
  obj["dirs"].reverse.each do |dir|
86
86
  return dir[name] if dir[name]
87
87
  end
88
88
  return nil
89
89
  end
90
-
91
90
  end
92
91
  end
@@ -1,10 +1,9 @@
1
1
  module SmallCage
2
2
  module BlueClothHelper
3
3
  require "bluecloth"
4
-
4
+
5
5
  def render_markdown(str)
6
6
  BlueCloth.new(str).to_html
7
7
  end
8
-
9
8
  end
10
- end
9
+ end
@@ -1,4 +1,4 @@
1
- require "rexml/document"
1
+ require "rexml/document"
2
2
 
3
3
  module SmallCage
4
4
  class CacheFilter
@@ -22,7 +22,7 @@ module SmallCage
22
22
  def find_latest(dir, path)
23
23
  relpath = path[0] == ?/ ? path[1..-1] : path
24
24
  return path unless (dir + relpath).exist?
25
-
25
+
26
26
  rex = /^(.+)--latest(\.[^.]+)$/
27
27
  pattern = relpath.to_s.sub(rex, '\1-*\2')
28
28
  pre = $1
@@ -42,18 +42,18 @@ module SmallCage
42
42
  entry = files.sort{|a,b| a[1] <=> b[1] }.last.to_a[0]
43
43
  end
44
44
  return path unless entry
45
-
46
- entry = "/" + entry if path[0] == ?/
45
+
46
+ entry = "/" + entry if path[0] == ?/
47
47
  return entry
48
48
  end
49
49
  private :find_latest
50
50
 
51
-
51
+
52
52
  # Get svn revision of file path + ".smc" or path
53
53
  def self.get_revision(path)
54
54
  smcpath = Pathname.new(path.to_s + ".smc")
55
55
  path = smcpath if smcpath.file?
56
-
56
+
57
57
  src = %x{svn info --xml #{path}}
58
58
  begin
59
59
  doc = REXML::Document.new(src)
@@ -62,9 +62,9 @@ module SmallCage
62
62
  rescue
63
63
  puts "Can't get revision number: #{path}"
64
64
  return "0"
65
- end
65
+ end
66
66
  end
67
-
67
+
68
68
  def self.outfiles(srcfile, outfiles)
69
69
  r = srcfile.rindex("--latest")
70
70
  prefix = srcfile[0..r]
@@ -80,12 +80,12 @@ module SmallCage
80
80
  end
81
81
  return result.sort {|a,b| a[1] <=> b[1]}
82
82
  end
83
-
83
+
84
84
  def self.create_cache(list, dryrun, quiet = false)
85
85
  list.each do |path|
86
86
  revision = SmallCage::CacheFilter.get_revision(path)
87
87
  to = path.pathmap("%{--latest$,-#{revision}}X%x")
88
- puts File.exist?(to) ? "(cache)U #{to}" : "(cache)A #{to}" unless quiet
88
+ puts File.exist?(to) ? "(cache)U #{to}" : "(cache)A #{to}" unless quiet
89
89
  begin
90
90
  FileUtils.copy(path,to) unless dryrun
91
91
  rescue => e
@@ -93,7 +93,5 @@ module SmallCage
93
93
  end
94
94
  end
95
95
  end
96
-
97
96
  end
98
-
99
97
  end
@@ -1,5 +1,5 @@
1
1
  namespace :cache do
2
-
2
+
3
3
  desc "Delete all cache files."
4
4
  task :clean => :require do
5
5
  pat = SmallCage::CacheFilter::TARGET_PATTERN
@@ -14,7 +14,7 @@ namespace :cache do
14
14
  end
15
15
  end
16
16
  end
17
-
17
+
18
18
  desc "Delete old cache files."
19
19
  task :delete_old => :require do
20
20
  pat = SmallCage::CacheFilter::TARGET_PATTERN
@@ -30,27 +30,26 @@ namespace :cache do
30
30
  end
31
31
  end
32
32
  end
33
-
33
+
34
34
  task :require do
35
35
  require File.dirname(__FILE__) + "/../filters/cache_filter.rb"
36
36
  end
37
-
37
+
38
38
  desc "Update *--latest.* files."
39
39
  task :update => [:require] do
40
40
  pat = SmallCage::CacheFilter::TARGET_PATTERN
41
-
41
+
42
42
  # Fix filenames. (site--latest.css.smc -> site--latest.css -> site-123.css)
43
43
  smclist = FileList["#{pat}.smc"]
44
44
  system "smc update" unless smclist.empty?
45
45
  list = FileList[pat]
46
46
  SmallCage::CacheFilter.create_cache(list, ENV["DRYRUN"])
47
-
47
+
48
48
  # Apply cache filter. Rewrite links. (site--latest.css.smc -> site--latest.css)
49
49
  system "smc update"
50
-
50
+
51
51
  # Copy updated file (site--latest.css -> site-123.css)
52
52
  smclist = smclist.map {|f| f[0 .. -5]}
53
53
  SmallCage::CacheFilter.create_cache(smclist, ENV["DRYRUN"])
54
54
  end
55
-
56
55
  end
@@ -42,7 +42,7 @@ class GDataExporter
42
42
  Configulation sample (add these lines to _dir.smc):
43
43
  ----------------------------------------------------------------
44
44
  gdata_auth: default
45
- gdata_files:
45
+ gdata_files:
46
46
  - key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
47
47
  file: _smc/data/sample1.csv
48
48
  - key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@@ -99,7 +99,7 @@ EOT
99
99
  puts "ERROR: auth file doesn't exist. execute gdata:login task.: #{afile}"
100
100
  end
101
101
  end
102
-
102
+
103
103
  def login
104
104
  umask_close { _login }
105
105
  end
@@ -125,7 +125,7 @@ EOT
125
125
  auth["doclist"] = c.clientlogin(email, pass)
126
126
  c = GData::Client::Spreadsheets.new
127
127
  auth["spreadsheets"] = c.clientlogin(email, pass)
128
-
128
+
129
129
  open(auth_file, "w") do |io|
130
130
  io << auth.to_yaml
131
131
  end
@@ -227,6 +227,4 @@ namespace :gdata do
227
227
  exporter = GDataExporter.new
228
228
  exporter.export
229
229
  end
230
-
231
-
232
230
  end
@@ -3,11 +3,11 @@ module SmallCage
3
3
 
4
4
  def lang
5
5
  return @obj["lang"] unless @obj["lang"].nil?
6
-
6
+
7
7
  if @obj["uri"] =~ %r{^/(ja|en)/}
8
8
  return $1
9
9
  end
10
-
10
+
11
11
  return nil
12
12
  end
13
13
 
@@ -16,4 +16,4 @@ module SmallCage
16
16
  end
17
17
 
18
18
  end
19
- end
19
+ end
@@ -12,7 +12,7 @@ module SmallCage
12
12
  break if amount <= i
13
13
  end
14
14
  end
15
-
15
+
16
16
  def each_archived_news(&block)
17
17
  date = @obj["uri"].match(%r{/(\d{4})(\d{2})?(\d{2})?\.html$}).to_a
18
18
  date.shift
@@ -27,10 +27,9 @@ module SmallCage
27
27
  date.shift
28
28
  return Time.local(*date)
29
29
  end
30
-
30
+
31
31
  def news_ftime(format = "%Y-%m-%d")
32
32
  news_time().strftime(format)
33
33
  end
34
-
35
34
  end
36
- end
35
+ end
@@ -3,9 +3,9 @@ require "nkf"
3
3
  module SmallCage
4
4
 
5
5
  # In _dir.smc or other *.smc, set charset like this:
6
- #
6
+ #
7
7
  # charset: Shift_JIS
8
- #
8
+ #
9
9
  class NkfFilter
10
10
 
11
11
  def initialize(opts)
@@ -32,12 +32,12 @@ module SmallCage
32
32
  elsif charset =~ /^shift_jis$/i
33
33
  opt = "-Wsm0"
34
34
  else
35
- STDERR.puts "Unknown charset: #{charset}" unless charset.empty?
35
+ STDERR.puts "Unknown charset: #{charset}" unless charset.empty?
36
36
  return str
37
- end
38
-
37
+ end
38
+
39
39
  return NKF.nkf(opt, str)
40
40
  end
41
41
 
42
42
  end
43
- end
43
+ end