smallcage 0.1.3 → 0.1.4
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 +13 -0
- data/License.txt +1 -1
- data/README.txt +61 -1
- data/Rakefile +85 -81
- data/lib/smallcage/commands/import.rb +1 -1
- data/lib/smallcage/erb_base.rb +0 -1
- data/lib/smallcage/loader.rb +9 -3
- data/lib/smallcage/renderer.rb +7 -2
- data/lib/smallcage/version.rb +1 -1
- data/project/cache/_smc/filters/cache_filter.rb +35 -0
- data/project/cache/_smc/filters/filters.yml +2 -0
- data/project/cache/_smc/rakelib/cache.rake +34 -0
- data/project/rake/_smc/Rakefile +2 -57
- data/project/rake/_smc/rakelib/csv.rake +52 -0
- data/project/rake/_smc/rakelib/svn.rake +64 -0
- data/project/tutorial/_smc/helpers/sample_helper.rb +7 -0
- data/project/tutorial/_smc/templates/default.rhtml +6 -0
- data/project/tutorial/_smc/templates/include1.rhtml +1 -0
- data/project/tutorial/_smc/templates/include2.rhtml +1 -0
- data/project/tutorial/sample.txt.smc +7 -0
- data/project/tutorial/sample2.txt.smc +1 -0
- data/project/tutorial2/_smc/helpers/priority_sample_helper.rb +7 -0
- data/project/tutorial2/_smc/templates/priorities.rhtml +5 -0
- data/project/tutorial2/_smc/templates/priority1.rhtml +1 -0
- data/project/tutorial2/_smc/templates/priority2.rhtml +1 -0
- data/project/tutorial2/_smc/templates/priority3.rhtml +1 -0
- data/project/tutorial2/_smc/templates/smc_variables.rhtml +29 -0
- data/project/tutorial2/tutorial2/_dir.smc +2 -0
- data/project/tutorial2/tutorial2/priorities.txt.smc +4 -0
- data/project/tutorial2/tutorial2/vars.txt.smc +26 -0
- data/spec/data/htdocs1/_dir.smc +3 -0
- data/spec/loader_spec.rb +35 -1
- data/spec/manifest_spec.rb +9 -9
- data/spec/spec_helper.rb +2 -7
- metadata +34 -57
- data/test/test_helper.rb +0 -2
- data/test/test_smallcage.rb +0 -11
data/History.txt
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
+
== 0.1.4 2009-07-27
|
2
|
+
|
3
|
+
* add cache control filter and rake task (for CDN, etag, etc.).
|
4
|
+
* add csv rake task which creates smc files from csv file.
|
5
|
+
* move rake tasks into *.rake files.
|
6
|
+
* switch 'smc import' default answer to 'Yes'.
|
7
|
+
* add the most primitive project template: tutorial.
|
8
|
+
* add project template to explain smc object and template: tutorial2.
|
9
|
+
* added 'body' to default smc object keys.
|
10
|
+
* avoid error when helper directory doesn't exist.
|
11
|
+
* show smc filename when template error occurs.
|
12
|
+
|
1
13
|
== 0.1.3 2009-05-01
|
2
14
|
|
15
|
+
* moved to github.
|
3
16
|
* stop using newgem and generate Rakefile using cutagem.
|
4
17
|
* fix svnignore_reset bug.
|
5
18
|
|
data/License.txt
CHANGED
data/README.txt
CHANGED
@@ -1 +1,61 @@
|
|
1
|
-
|
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
|
+
|
data/Rakefile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/clean'
|
4
|
-
require 'rake/testtask'
|
5
4
|
require 'rake/packagetask'
|
6
5
|
require 'rake/gempackagetask'
|
7
6
|
require 'rake/rdoctask'
|
@@ -9,6 +8,9 @@ require 'rake/contrib/rubyforgepublisher'
|
|
9
8
|
require 'rake/contrib/sshpublisher'
|
10
9
|
require 'fileutils'
|
11
10
|
require 'lib/smallcage'
|
11
|
+
require 'spec'
|
12
|
+
require 'spec/rake/spectask'
|
13
|
+
|
12
14
|
include FileUtils
|
13
15
|
|
14
16
|
NAME = "smallcage"
|
@@ -23,118 +25,120 @@ VERS = SmallCage::VERSION::STRING
|
|
23
25
|
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
24
26
|
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
25
27
|
RDOC_OPTS = [
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
'--title', "#{NAME} documentation",
|
29
|
+
"--charset", "utf-8",
|
30
|
+
"--opname", "index.html",
|
31
|
+
"--line-numbers",
|
32
|
+
"--main", "README.txt",
|
33
|
+
"--inline-source",
|
32
34
|
]
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Rake::TestTask.new("test") do |t|
|
38
|
-
t.libs << "test"
|
39
|
-
t.pattern = "test/**/*_test.rb"
|
40
|
-
t.verbose = true
|
41
|
-
end
|
36
|
+
SRC_FILES = FileList.new(%w{Rakefile README.txt History.txt License.txt})
|
37
|
+
SRC_FILES.include("{bin,doc,lib,test,project,spec}/**/*")
|
38
|
+
SRC_FILES.exclude(/~$/)
|
42
39
|
|
43
40
|
spec = Gem::Specification.new do |s|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
Dir.glob("{bin,doc,lib,test,project,spec}/**/*")
|
67
|
-
|
68
|
-
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
41
|
+
s.name = NAME
|
42
|
+
s.version = VERS
|
43
|
+
s.platform = Gem::Platform::RUBY
|
44
|
+
s.has_rdoc = true
|
45
|
+
s.extra_rdoc_files = ["README.txt", "History.txt"]
|
46
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
47
|
+
s.summary = DESCRIPTION
|
48
|
+
s.description = DESCRIPTION
|
49
|
+
s.authors = AUTHORS
|
50
|
+
s.email = EMAIL
|
51
|
+
s.homepage = HOMEPATH
|
52
|
+
s.executables = BIN_FILES
|
53
|
+
s.rubyforge_project = RUBYFORGE_PROJECT
|
54
|
+
s.bindir = "bin"
|
55
|
+
s.require_path = "lib"
|
56
|
+
s.test_files = Dir["spec/*_spec.rb"]
|
57
|
+
s.files = SRC_FILES
|
58
|
+
|
59
|
+
#s.autorequire = ""
|
60
|
+
#s.add_dependency('activesupport', '>=1.3.1')
|
61
|
+
#s.required_ruby_version = '>= 1.8.2'
|
62
|
+
#s.extensions = FileList["ext/**/extconf.rb"].to_a
|
69
63
|
end
|
70
64
|
|
65
|
+
task :default => [:spec]
|
66
|
+
task :package => [:clean]
|
67
|
+
|
71
68
|
Rake::GemPackageTask.new(spec) do |p|
|
72
|
-
|
73
|
-
|
69
|
+
p.need_tar = true
|
70
|
+
p.gem_spec = spec
|
74
71
|
end
|
75
72
|
|
76
73
|
task :install do
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
name = "#{NAME}-#{VERS}.gem"
|
75
|
+
sh %{rake package}
|
76
|
+
sh %{sudo gem install pkg/#{name}}
|
80
77
|
end
|
81
78
|
|
82
79
|
task :uninstall => [:clean] do
|
83
|
-
|
80
|
+
sh %{sudo gem uninstall #{NAME}}
|
84
81
|
end
|
85
82
|
|
86
83
|
|
87
84
|
Rake::RDocTask.new do |rdoc|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
85
|
+
rdoc.rdoc_dir = 'html'
|
86
|
+
rdoc.options += RDOC_OPTS
|
87
|
+
rdoc.template = "resh"
|
88
|
+
#rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
89
|
+
if ENV['DOC_FILES']
|
90
|
+
rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
91
|
+
else
|
92
|
+
rdoc.rdoc_files.include('README.txt', 'History.txt')
|
93
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
94
|
+
rdoc.rdoc_files.include('ext/**/*.c')
|
95
|
+
end
|
99
96
|
end
|
100
97
|
|
101
98
|
desc "Publish to RubyForge"
|
102
99
|
task :rubyforge => [:rdoc, :package] do
|
103
|
-
|
104
|
-
|
100
|
+
require 'rubyforge'
|
101
|
+
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'bluemark').upload
|
105
102
|
end
|
106
103
|
|
107
104
|
desc 'Package and upload the release to rubyforge.'
|
108
105
|
task :release => [:clean, :package] do |t|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
#
|
120
|
-
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
106
|
+
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
107
|
+
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
|
108
|
+
pkg = "pkg/#{NAME}-#{VERS}"
|
109
|
+
|
110
|
+
require 'rubyforge'
|
111
|
+
rf = RubyForge.new.configure
|
112
|
+
puts "Logging in"
|
113
|
+
rf.login
|
114
|
+
|
115
|
+
c = rf.userconfig
|
116
|
+
# c["release_notes"] = description if description
|
117
|
+
# c["release_changes"] = changes if changes
|
118
|
+
c["preformatted"] = true
|
119
|
+
|
120
|
+
files = [
|
121
|
+
"#{pkg}.tgz",
|
122
|
+
"#{pkg}.gem"
|
123
|
+
].compact
|
124
|
+
|
125
|
+
puts "Releasing #{NAME} v. #{VERS}"
|
126
|
+
rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
|
130
127
|
end
|
131
128
|
|
132
129
|
desc 'Show information about the gem.'
|
133
130
|
task :debug_gem do
|
134
|
-
|
131
|
+
puts spec.to_ruby
|
135
132
|
end
|
136
133
|
|
137
134
|
desc 'Update gem spec'
|
138
135
|
task :gemspec do
|
139
136
|
open("#{NAME}.gemspec", 'w').write spec.to_ruby
|
140
137
|
end
|
138
|
+
|
139
|
+
desc "Run the specs under ./spec/"
|
140
|
+
Spec::Rake::SpecTask.new do |t|
|
141
|
+
t.libs << "lib"
|
142
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
143
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
144
|
+
end
|
data/lib/smallcage/erb_base.rb
CHANGED
data/lib/smallcage/loader.rb
CHANGED
@@ -87,6 +87,7 @@ module SmallCage
|
|
87
87
|
result["uri"] = uri_out
|
88
88
|
result["arrays"] = []
|
89
89
|
result["strings"] = []
|
90
|
+
result["body"] = nil
|
90
91
|
|
91
92
|
# target is directory and _dir.smc is not exist.
|
92
93
|
return result unless source_path.exist?
|
@@ -110,6 +111,8 @@ module SmallCage
|
|
110
111
|
result["strings"] << o.to_s
|
111
112
|
end
|
112
113
|
end
|
114
|
+
|
115
|
+
result["body"] = result["strings"][0] if result["body"].nil?
|
113
116
|
|
114
117
|
return result
|
115
118
|
end
|
@@ -205,8 +208,11 @@ module SmallCage
|
|
205
208
|
|
206
209
|
def load_anonymous(dir, rex)
|
207
210
|
module_names = []
|
208
|
-
|
209
211
|
mod = Module.new
|
212
|
+
result = { :module => mod, :names => module_names }
|
213
|
+
|
214
|
+
return result unless File.exist?(dir)
|
215
|
+
|
210
216
|
Dir.entries(dir).sort.each do |h|
|
211
217
|
next unless h =~ rex
|
212
218
|
|
@@ -217,14 +223,14 @@ module SmallCage
|
|
217
223
|
begin
|
218
224
|
mod.module_eval(src, "#{dir}/#{h}")
|
219
225
|
rescue => ex
|
220
|
-
|
226
|
+
STDERR << ex.to_s # TODO show error
|
221
227
|
load("#{dir}/#{h}", true) # try to know error line number.
|
222
228
|
raise "Can't load #{dir}/#{h} / line# unknown"
|
223
229
|
end
|
224
230
|
module_names << module_name
|
225
231
|
end
|
226
232
|
|
227
|
-
return
|
233
|
+
return result
|
228
234
|
end
|
229
235
|
private :load_anonymous
|
230
236
|
|
data/lib/smallcage/renderer.rb
CHANGED
@@ -11,8 +11,13 @@ class SmallCage::Renderer
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def render_string(str, obj)
|
14
|
-
|
15
|
-
|
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
|
16
21
|
return result
|
17
22
|
end
|
18
23
|
|
data/lib/smallcage/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module SmallCage
|
2
|
+
class CacheFilter
|
3
|
+
|
4
|
+
def initialize(opts)
|
5
|
+
end
|
6
|
+
|
7
|
+
def after_rendering_filter(obj, str)
|
8
|
+
str.gsub %r{(\s(?:src|href)=["'])(?!https?://)([^"']+--latest\.(?:css|js|png|gif|jpg))(["'])} do
|
9
|
+
pre = $1
|
10
|
+
path = $2
|
11
|
+
pro = $3
|
12
|
+
dir = obj["dirs"][path[0] == ?/ ? 0 : -1]["path"]
|
13
|
+
pre + find_latest(dir, path) + pro
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_latest(dir, path)
|
18
|
+
relpath = path[0] == ?/ ? path[1..-1] : path
|
19
|
+
return path unless (dir + relpath).exist?
|
20
|
+
|
21
|
+
rex = /^(.+)--latest(\.[^.]+)$/
|
22
|
+
pattern = relpath.to_s.sub(rex, '\1-*\2')
|
23
|
+
|
24
|
+
entry = nil
|
25
|
+
Dir.chdir(dir) do
|
26
|
+
entry = Dir.glob(pattern).reject {|f| f == relpath }.sort.last
|
27
|
+
end
|
28
|
+
return path unless entry
|
29
|
+
|
30
|
+
entry = "/" + entry if path[0] == ?/
|
31
|
+
return entry
|
32
|
+
end
|
33
|
+
private :find_latest
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
namespace :cache do
|
3
|
+
|
4
|
+
task :update do
|
5
|
+
require "rexml/document"
|
6
|
+
list = FileList["**/*--latest.{css,js,png,gif,jpg}"]
|
7
|
+
|
8
|
+
list.each do |path|
|
9
|
+
src = %x{svn info --xml #{path}}
|
10
|
+
begin
|
11
|
+
doc = REXML::Document.new(src)
|
12
|
+
revision = doc.elements['/info/entry/commit/@revision'].value
|
13
|
+
rescue
|
14
|
+
puts "Can't get revision number: #{path}"
|
15
|
+
end
|
16
|
+
to = path.pathmap("%{--latest$,-#{revision}}X%x")
|
17
|
+
if File.exist?(to)
|
18
|
+
puts " SKIP(exists): #{path} -> #{to}"
|
19
|
+
next
|
20
|
+
else
|
21
|
+
puts " COPY: #{path} -> #{to}"
|
22
|
+
end
|
23
|
+
unless ENV["DRYRUN"]
|
24
|
+
next if File.exist?(to)
|
25
|
+
begin
|
26
|
+
FileUtils.copy(path,to)
|
27
|
+
rescue => e
|
28
|
+
puts " ERROR: #{e} #{path} -> #{to}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/project/rake/_smc/Rakefile
CHANGED
@@ -4,65 +4,10 @@ require 'pathname'
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'smallcage'
|
6
6
|
|
7
|
+
FileList["_smc/rakelib/*.rake"].each {|f| load f }
|
8
|
+
|
7
9
|
task :default => :smcupdate
|
8
10
|
|
9
11
|
task :smcupdate do
|
10
12
|
system "smc update"
|
11
13
|
end
|
12
|
-
|
13
|
-
def load_svnignores(loader, path)
|
14
|
-
dirs = loader.load_dirs(Pathname.new(path) + "child_dummy") # TODO
|
15
|
-
ignores = []
|
16
|
-
dirs.reverse.each do |d|
|
17
|
-
data = d["svnignore"]
|
18
|
-
ignores << data unless data.to_s.empty?
|
19
|
-
break if d["svnignore_reset"]
|
20
|
-
end
|
21
|
-
data = dirs.last["svnignore_current"]
|
22
|
-
unless data.to_s.empty?
|
23
|
-
ignores << data
|
24
|
-
end
|
25
|
-
|
26
|
-
ignores.flatten!
|
27
|
-
ignores.uniq!
|
28
|
-
ignores.sort!
|
29
|
-
return ignores
|
30
|
-
end
|
31
|
-
|
32
|
-
def set_svnignore(dryrun = false)
|
33
|
-
loader = SmallCage::Loader.new(".")
|
34
|
-
|
35
|
-
exec_svn(loader, ".", dryrun)
|
36
|
-
Dir.glob("**/") do |f|
|
37
|
-
exec_svn(loader, f, dryrun)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def exec_svn(loader, f, dryrun)
|
42
|
-
return if f =~ %r{^_smc/}
|
43
|
-
svnignores = load_svnignores(loader, f).join("\n")
|
44
|
-
return if svnignores.empty?
|
45
|
-
cmd = "svn propset svn:ignore '#{svnignores}' #{f}"
|
46
|
-
puts cmd
|
47
|
-
return if dryrun
|
48
|
-
puts "FAILED: #{cmd}" unless system cmd
|
49
|
-
end
|
50
|
-
|
51
|
-
# _dir.smc
|
52
|
-
# svnignore: *.html # set recursively.
|
53
|
-
# svnignore_current: .project # add only current dir.
|
54
|
-
# svnignore_reset: true # ignore parent directory settings.
|
55
|
-
#
|
56
|
-
# You can use list.
|
57
|
-
# svnignore:
|
58
|
-
# - *.html
|
59
|
-
# - *.xml
|
60
|
-
desc "svn propset svn:ignore ..."
|
61
|
-
task :svnignore do
|
62
|
-
set_svnignore
|
63
|
-
end
|
64
|
-
|
65
|
-
desc "confirm svn commands."
|
66
|
-
task :svnignore_dryrun do
|
67
|
-
set_svnignore(true)
|
68
|
-
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
namespace :csv do
|
3
|
+
|
4
|
+
task :require do
|
5
|
+
require "csv"
|
6
|
+
require "yaml"
|
7
|
+
end
|
8
|
+
|
9
|
+
# csv_to_smc sample task.
|
10
|
+
task :update_samples => [:require] do
|
11
|
+
|
12
|
+
# By default, csv rows are saved as array.
|
13
|
+
csv_to_smc("_smc/samples.csv") {|data,rownum| "samples/#{"%04d" % rownum}.html.smc" }
|
14
|
+
|
15
|
+
# You can create hash using label_row/skip_rows parameters.
|
16
|
+
# csv_to_smc("_smc/samples.csv", 1, 0) {|data,rownum| "samples/#{"%04d" % rownum}.html.smc" }
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def csv_to_smc(csv_file, skip_rows = nil, label_row = nil)
|
24
|
+
labels = nil
|
25
|
+
skip_rows ||= 0
|
26
|
+
label_row ||= -1
|
27
|
+
|
28
|
+
rownum = -1
|
29
|
+
CSV.foreach(csv_file) do |row|
|
30
|
+
rownum += 1
|
31
|
+
labels = row.map{|cell| cell.to_s } if label_row == rownum
|
32
|
+
next if rownum < skip_rows
|
33
|
+
|
34
|
+
if labels
|
35
|
+
data = {}
|
36
|
+
labels.each_with_index do |label,i|
|
37
|
+
data[label] = row[i].to_s
|
38
|
+
end
|
39
|
+
else
|
40
|
+
data = row.map {|cell| cell.to_s }
|
41
|
+
end
|
42
|
+
if block_given?
|
43
|
+
fname = yield(data,rownum)
|
44
|
+
else
|
45
|
+
fname = data[0]
|
46
|
+
end
|
47
|
+
File.open(fname, "w") do |io|
|
48
|
+
io << data.to_yaml
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
namespace :svn do
|
3
|
+
|
4
|
+
# _dir.smc
|
5
|
+
# svnignore: *.html # set recursively.
|
6
|
+
# svnignore_current: .project # add only current dir.
|
7
|
+
# svnignore_reset: true # ignore parent directory settings.
|
8
|
+
#
|
9
|
+
# You can use list.
|
10
|
+
# svnignore:
|
11
|
+
# - *.html
|
12
|
+
# - *.xml
|
13
|
+
desc "svn propset svn:ignore ..."
|
14
|
+
task :ignore do
|
15
|
+
set_svnignore
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "confirm svn commands."
|
19
|
+
task :ignore_dryrun do
|
20
|
+
set_svnignore(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
def load_svnignores(loader, path)
|
28
|
+
dirs = loader.load_dirs(Pathname.new(path) + "child_dummy") # XXX
|
29
|
+
ignores = []
|
30
|
+
dirs.reverse.each do |d|
|
31
|
+
data = d["svnignore"]
|
32
|
+
ignores << data unless data.to_s.empty?
|
33
|
+
break if d["svnignore_reset"]
|
34
|
+
end
|
35
|
+
data = dirs.last["svnignore_current"]
|
36
|
+
unless data.to_s.empty?
|
37
|
+
ignores << data
|
38
|
+
end
|
39
|
+
|
40
|
+
ignores.flatten!
|
41
|
+
ignores.uniq!
|
42
|
+
ignores.sort!
|
43
|
+
return ignores
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_svnignore(dryrun = false)
|
47
|
+
loader = SmallCage::Loader.new(".")
|
48
|
+
|
49
|
+
exec_svn(loader, ".", dryrun)
|
50
|
+
Dir.glob("**/") do |f|
|
51
|
+
exec_svn(loader, f, dryrun)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def exec_svn(loader, f, dryrun)
|
56
|
+
return if f =~ %r{^_smc/}
|
57
|
+
svnignores = load_svnignores(loader, f).join("\n")
|
58
|
+
return if svnignores.empty?
|
59
|
+
cmd = "svn propset svn:ignore '#{svnignores}' #{f}"
|
60
|
+
puts cmd
|
61
|
+
return if dryrun
|
62
|
+
puts "FAILED: #{cmd}" unless system cmd
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
----------------------------------------------------------------
|
@@ -0,0 +1 @@
|
|
1
|
+
================================================================
|
@@ -0,0 +1 @@
|
|
1
|
+
template: include2
|
@@ -0,0 +1 @@
|
|
1
|
+
template
|
@@ -0,0 +1 @@
|
|
1
|
+
template
|
@@ -0,0 +1 @@
|
|
1
|
+
template
|
@@ -0,0 +1,29 @@
|
|
1
|
+
=== vars ===
|
2
|
+
|
3
|
+
<%- (@obj.keys - %w{template uri path strings arrays body dirs}).sort.each do |key| -%>
|
4
|
+
* <%= key %> <%= @obj[key].inspect %>
|
5
|
+
<%- end -%>
|
6
|
+
|
7
|
+
=== special variables ===
|
8
|
+
|
9
|
+
* template <%= template.inspect %>
|
10
|
+
* uri <%= uri.inspect %>
|
11
|
+
* uri.smc <%= uri.smc.inspect %>
|
12
|
+
* path <%= path.inspect %>
|
13
|
+
* path.smc <%= path.smc.inspect %>
|
14
|
+
* strings <%= strings.inspect %>
|
15
|
+
* arrays <%= arrays.inspect %>
|
16
|
+
* body <%= body.inspect %>
|
17
|
+
|
18
|
+
=== directory info ===
|
19
|
+
|
20
|
+
<%- dirs.each_with_index do |dir,i| -%>
|
21
|
+
* dirs[<%= i %>]
|
22
|
+
<%- dir.keys.sort.each do |k| -%>
|
23
|
+
* dirs[<%= i %>]["<%= k %>"] <%= dir[k].inspect %>
|
24
|
+
<%- end %>
|
25
|
+
<%- end -%>
|
26
|
+
=== smc object ===
|
27
|
+
|
28
|
+
* @obj.class.name <%= @obj.class.name %>
|
29
|
+
* @obj.keys.inspect <%= @obj.keys.inspect %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
template: smc_variables
|
2
|
+
title: How smc file convert into smc object.
|
3
|
+
array_sample:
|
4
|
+
- item1
|
5
|
+
- item2
|
6
|
+
overwrite: OVER
|
7
|
+
--- |
|
8
|
+
text part 1.
|
9
|
+
foo bar
|
10
|
+
---
|
11
|
+
- AAA
|
12
|
+
- BBB
|
13
|
+
- CCC
|
14
|
+
---
|
15
|
+
- 111
|
16
|
+
- 222
|
17
|
+
- 333
|
18
|
+
--- |
|
19
|
+
text part 2.
|
20
|
+
baz baz
|
21
|
+
---
|
22
|
+
hash_sample:
|
23
|
+
key1: value-A
|
24
|
+
key2: value-B
|
25
|
+
note: All YAML hash documents gather into one hash value.
|
26
|
+
overwrite: WRITE
|
data/spec/data/htdocs1/_dir.smc
CHANGED
data/spec/loader_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe SmallCage::Loader do
|
|
7
7
|
@docroot = Pathname.new(File.dirname(__FILE__) + "/data/htdocs1")
|
8
8
|
end
|
9
9
|
|
10
|
-
it "should load path value which
|
10
|
+
it "should load path value which is instance of Pathname" do
|
11
11
|
ldr = SmallCage::Loader.new(@docroot)
|
12
12
|
obj = ldr.load(@docroot + "a/b/c/index.html.smc")
|
13
13
|
|
@@ -52,4 +52,38 @@ describe SmallCage::Loader do
|
|
52
52
|
end
|
53
53
|
objects[0]["strings"][0].should == "abc\ndef\n\nghi"
|
54
54
|
end
|
55
|
+
|
56
|
+
it "should load body value which equals strings[0]" do
|
57
|
+
ldr = SmallCage::Loader.new(@docroot)
|
58
|
+
obj = ldr.load(@docroot + "a/b/c/index.html.smc")
|
59
|
+
|
60
|
+
obj["strings"][0].should == "abc\ndef\n\nghi"
|
61
|
+
obj["body"].should == obj["strings"][0]
|
62
|
+
|
63
|
+
# same String instance
|
64
|
+
obj["strings"][0].replace("XXX")
|
65
|
+
obj["body"].should == "XXX"
|
66
|
+
|
67
|
+
obj["strings"][0] = "ABC"
|
68
|
+
obj["body"].should == "XXX"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should load dirs" do
|
72
|
+
ldr = SmallCage::Loader.new(@docroot)
|
73
|
+
obj = ldr.load(@docroot + "a/b/c/index.html.smc")
|
74
|
+
|
75
|
+
dirs = obj["dirs"]
|
76
|
+
dirs.length.should == 4
|
77
|
+
|
78
|
+
dirs[0]["uri"].should == "/"
|
79
|
+
dirs[1]["uri"].should == "/a/"
|
80
|
+
dirs[2]["uri"].should == "/a/b/"
|
81
|
+
dirs[3]["uri"].should == "/a/b/c/"
|
82
|
+
(dirs[3]["path"] + "index.html.smc").file?.should be_true
|
83
|
+
|
84
|
+
dirs[0]["var"].should == "xxx"
|
85
|
+
dirs[0]["strings"][0].should == "BODYBODYBODY"
|
86
|
+
dirs[0]["body"].should == "BODYBODYBODY"
|
87
|
+
end
|
88
|
+
|
55
89
|
end
|
data/spec/manifest_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
require 'smallcage'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
4
|
describe "SmallCage::Commands::Manifest" do
|
7
5
|
|
8
6
|
before do
|
@@ -17,18 +15,20 @@ describe "SmallCage::Commands::Manifest" do
|
|
17
15
|
@manifest_file.file?.should be_true
|
18
16
|
|
19
17
|
source = @manifest_file.read
|
20
|
-
source.
|
21
|
-
|
18
|
+
source = source.match(%r{<ul class="files">\n(.+?)\n</ul>}m)[1].split(/\n/)
|
19
|
+
|
20
|
+
contents = <<'EOT'.split(/\n/)
|
21
|
+
<li><a href="./_dir.smc">./_dir.smc</a></li>
|
22
|
+
<li><a href="./_smc/">./_smc/</a></li>
|
22
23
|
<li><a href="./a/">./a/</a></li>
|
23
24
|
<li><a href="./a/b/">./a/b/</a></li>
|
24
25
|
<li><a href="./a/b/c/">./a/b/c/</a></li>
|
25
26
|
<li><a href="./a/b/c/index.html.smc">./a/b/c/index.html.smc</a></li>
|
26
|
-
<li><a href="./_dir.smc">./_dir.smc</a></li>
|
27
|
-
<li><a href="./_smc/">./_smc/</a></li>
|
28
|
-
<li><a href="./_smc/helpers/">./_smc/helpers/</a></li>
|
29
|
-
<li><a href="./_smc/templates/">./_smc/templates/</a></li>
|
30
|
-
</ul>
|
31
27
|
EOT
|
28
|
+
|
29
|
+
source.each do |line|
|
30
|
+
contents.should include(line)
|
31
|
+
end
|
32
32
|
end
|
33
33
|
|
34
34
|
after do
|
data/spec/spec_helper.rb
CHANGED
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
|
+
version: 0.1.4
|
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-
|
14
|
+
date: 2009-07-27 00:00:00 +09:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|
@@ -30,9 +30,7 @@ files:
|
|
30
30
|
- History.txt
|
31
31
|
- License.txt
|
32
32
|
- bin/smc
|
33
|
-
- lib/smallcage
|
34
33
|
- lib/smallcage/application.rb
|
35
|
-
- lib/smallcage/commands
|
36
34
|
- lib/smallcage/commands/auto.rb
|
37
35
|
- lib/smallcage/commands/base.rb
|
38
36
|
- lib/smallcage/commands/clean.rb
|
@@ -47,65 +45,36 @@ files:
|
|
47
45
|
- lib/smallcage/loader.rb
|
48
46
|
- lib/smallcage/misc.rb
|
49
47
|
- lib/smallcage/renderer.rb
|
50
|
-
- lib/smallcage/resources
|
51
48
|
- lib/smallcage/resources/auto.html
|
52
49
|
- lib/smallcage/resources/Manifest.erb
|
53
50
|
- lib/smallcage/runner.rb
|
54
51
|
- lib/smallcage/version.rb
|
55
52
|
- lib/smallcage.rb
|
56
|
-
- test/test_helper.rb
|
57
|
-
- test/test_smallcage.rb
|
58
|
-
- project/base
|
59
|
-
- project/base/_smc
|
60
|
-
- project/base/_smc/helpers
|
61
53
|
- project/base/_smc/helpers/base_helper.rb
|
62
54
|
- project/base/_smc/helpers/site_helper.rb
|
63
|
-
- project/base/_smc/templates
|
64
55
|
- project/base/_smc/templates/default.rhtml
|
65
56
|
- project/base/_smc/templates/footer.rhtml
|
66
57
|
- project/base/_smc/templates/header.rhtml
|
67
|
-
- project/bluecloth
|
68
|
-
- project/bluecloth/_smc
|
69
|
-
- project/bluecloth/_smc/helpers
|
70
58
|
- project/bluecloth/_smc/helpers/blue_cloth_helper.rb
|
71
|
-
- project/bluecloth/_smc/templates
|
72
59
|
- project/bluecloth/_smc/templates/markdown.rhtml
|
73
|
-
- project/
|
74
|
-
- project/
|
75
|
-
- project/
|
60
|
+
- project/cache/_smc/filters/cache_filter.rb
|
61
|
+
- project/cache/_smc/filters/filters.yml
|
62
|
+
- project/cache/_smc/rakelib/cache.rake
|
76
63
|
- project/lang/_smc/helpers/lang_helper.rb
|
77
|
-
- project/lang/_smc/templates
|
78
64
|
- project/lang/_smc/templates/other_lang.rhtml
|
79
|
-
- project/news
|
80
|
-
- project/news/_smc
|
81
|
-
- project/news/_smc/helpers
|
82
65
|
- project/news/_smc/helpers/news_helper.rb
|
83
|
-
- project/nkf
|
84
|
-
- project/nkf/_smc
|
85
|
-
- project/nkf/_smc/filters
|
86
66
|
- project/nkf/_smc/filters/filters.yml
|
87
67
|
- project/nkf/_smc/filters/nkf_filter.rb
|
88
|
-
- project/rake
|
89
|
-
- project/rake/_smc
|
90
68
|
- project/rake/_smc/Rakefile
|
91
|
-
- project/
|
92
|
-
- project/
|
93
|
-
- project/redcloth/_smc/helpers
|
69
|
+
- project/rake/_smc/rakelib/csv.rake
|
70
|
+
- project/rake/_smc/rakelib/svn.rake
|
94
71
|
- project/redcloth/_smc/helpers/red_cloth_helper.rb
|
95
|
-
- project/redcloth/_smc/templates
|
96
72
|
- project/redcloth/_smc/templates/textile.rhtml
|
97
|
-
- project/relpath
|
98
|
-
- project/relpath/_smc
|
99
|
-
- project/relpath/_smc/filters
|
100
73
|
- project/relpath/_smc/filters/filters.yml
|
101
74
|
- project/relpath/_smc/filters/relpath_filter.rb
|
102
|
-
- project/standard
|
103
75
|
- project/standard/_dir.smc
|
104
|
-
- project/standard/_smc
|
105
|
-
- project/standard/_smc/helpers
|
106
76
|
- project/standard/_smc/helpers/base_helper.rb
|
107
77
|
- project/standard/_smc/helpers/menu_helper.rb
|
108
|
-
- project/standard/_smc/templates
|
109
78
|
- project/standard/_smc/templates/default.rhtml
|
110
79
|
- project/standard/_smc/templates/footer.rhtml
|
111
80
|
- project/standard/_smc/templates/header.rhtml
|
@@ -113,33 +82,33 @@ files:
|
|
113
82
|
- project/standard/_smc/templates/redirect.rhtml
|
114
83
|
- project/standard/_smc/templates/sidebar.rhtml
|
115
84
|
- project/standard/_smc/templates/topic_path.rhtml
|
116
|
-
- project/standard/common
|
117
|
-
- project/standard/common/css
|
118
85
|
- project/standard/common/css/default.css
|
119
86
|
- project/standard/common/css/print.css
|
120
87
|
- project/standard/index.html.smc
|
121
|
-
- project/standard/sample
|
122
88
|
- project/standard/sample/_dir.smc
|
123
89
|
- project/standard/sample/index.html.smc
|
124
90
|
- project/standard/sample/redirect.html.smc
|
125
|
-
- project/standard/sample/sub
|
126
91
|
- project/standard/sample/sub/_dir.smc
|
127
92
|
- project/standard/sample/sub/contents.html.smc
|
128
93
|
- project/standard/sample/sub/index.html.smc
|
129
|
-
-
|
130
|
-
-
|
94
|
+
- project/tutorial/_smc/helpers/sample_helper.rb
|
95
|
+
- project/tutorial/_smc/templates/default.rhtml
|
96
|
+
- project/tutorial/_smc/templates/include1.rhtml
|
97
|
+
- project/tutorial/_smc/templates/include2.rhtml
|
98
|
+
- project/tutorial/sample.txt.smc
|
99
|
+
- project/tutorial/sample2.txt.smc
|
100
|
+
- project/tutorial2/_smc/helpers/priority_sample_helper.rb
|
101
|
+
- project/tutorial2/_smc/templates/priorities.rhtml
|
102
|
+
- project/tutorial2/_smc/templates/priority1.rhtml
|
103
|
+
- project/tutorial2/_smc/templates/priority2.rhtml
|
104
|
+
- project/tutorial2/_smc/templates/priority3.rhtml
|
105
|
+
- project/tutorial2/_smc/templates/smc_variables.rhtml
|
106
|
+
- project/tutorial2/tutorial2/_dir.smc
|
107
|
+
- project/tutorial2/tutorial2/priorities.txt.smc
|
108
|
+
- project/tutorial2/tutorial2/vars.txt.smc
|
131
109
|
- spec/data/htdocs1/_dir.smc
|
132
|
-
- spec/data/htdocs1/a
|
133
|
-
- spec/data/htdocs1/a/b
|
134
|
-
- spec/data/htdocs1/a/b/c
|
135
110
|
- spec/data/htdocs1/a/b/c/index.html.smc
|
136
|
-
- spec/data/htdocs2
|
137
|
-
- spec/data/htdocs2/_smc
|
138
|
-
- spec/data/htdocs2/_smc/templates
|
139
111
|
- spec/data/htdocs2/_smc/templates/dummy.rhtml
|
140
|
-
- spec/data/htdocs2/a
|
141
|
-
- spec/data/htdocs2/a/b
|
142
|
-
- spec/data/htdocs2/a/b/c
|
143
112
|
- spec/data/htdocs2/a/b/c/test.html
|
144
113
|
- spec/data/htdocs2/a/b/test.html
|
145
114
|
- spec/data/htdocs2/a/test.html.smc
|
@@ -154,6 +123,8 @@ files:
|
|
154
123
|
- spec/spec_helper.rb
|
155
124
|
has_rdoc: true
|
156
125
|
homepage: http://www.smallcage.org
|
126
|
+
licenses: []
|
127
|
+
|
157
128
|
post_install_message:
|
158
129
|
rdoc_options:
|
159
130
|
- --title
|
@@ -185,9 +156,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
156
|
requirements: []
|
186
157
|
|
187
158
|
rubyforge_project: smallcage
|
188
|
-
rubygems_version: 1.3.
|
159
|
+
rubygems_version: 1.3.3
|
189
160
|
signing_key:
|
190
|
-
specification_version:
|
161
|
+
specification_version: 3
|
191
162
|
summary: Lightweight CMS package.
|
192
|
-
test_files:
|
193
|
-
|
163
|
+
test_files:
|
164
|
+
- spec/document_path_spec.rb
|
165
|
+
- spec/export_spec.rb
|
166
|
+
- spec/import_spec.rb
|
167
|
+
- spec/loader_spec.rb
|
168
|
+
- spec/manifest_spec.rb
|
169
|
+
- spec/misc_spec.rb
|
170
|
+
- spec/smallcage_spec.rb
|
data/test/test_helper.rb
DELETED