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.
- data/.gitignore +1 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +1 -1
- data/Gemfile +16 -5
- data/Guardfile +4 -0
- data/History.rdoc +9 -5
- data/README.rdoc +3 -3
- data/Rakefile +1 -1
- data/bin/smc +4 -12
- data/lib/smallcage.rb +4 -1
- data/lib/smallcage/anonymous_loader.rb +32 -0
- data/lib/smallcage/application.rb +4 -5
- data/lib/smallcage/commands/auto.rb +16 -17
- data/lib/smallcage/commands/base.rb +4 -5
- data/lib/smallcage/commands/clean.rb +5 -5
- data/lib/smallcage/commands/export.rb +5 -5
- data/lib/smallcage/commands/import.rb +25 -27
- data/lib/smallcage/commands/manifest.rb +4 -4
- data/lib/smallcage/commands/server.rb +4 -4
- data/lib/smallcage/commands/update.rb +4 -5
- data/lib/smallcage/commands/uri.rb +3 -5
- data/lib/smallcage/document_path.rb +6 -9
- data/lib/smallcage/http_server.rb +9 -10
- data/lib/smallcage/loader.rb +19 -49
- data/lib/smallcage/misc.rb +1 -1
- data/lib/smallcage/renderer.rb +1 -1
- data/lib/smallcage/resources/auto.html +7 -7
- data/lib/smallcage/runner.rb +6 -6
- data/lib/smallcage/update_list.rb +2 -3
- data/lib/smallcage/version.rb +1 -1
- data/project/base/_smc/helpers/base_helper.rb +8 -9
- data/project/bluecloth/_smc/helpers/blue_cloth_helper.rb +2 -3
- data/project/cache/_smc/filters/cache_filter.rb +10 -12
- data/project/cache/_smc/rakelib/cache.rake +7 -8
- data/project/gdata/_smc/rakelib/gdata.rake +3 -5
- data/project/lang/_smc/helpers/lang_helper.rb +3 -3
- data/project/news/_smc/helpers/news_helper.rb +3 -4
- data/project/nkf/_smc/filters/nkf_filter.rb +6 -6
- data/project/nkf/_smc/helpers/nkf_helper.rb +8 -9
- data/project/rake/_smc/rakelib/svn.rake +5 -6
- data/project/redcloth/_smc/helpers/red_cloth_helper.rb +3 -3
- data/project/standard/_smc/helpers/menu_helper.rb +4 -5
- data/project/standard/_smc/templates/redirect.rhtml +1 -1
- data/spec/data/anonymous_loader/1/error1.rb +1 -0
- data/spec/data/anonymous_loader/1/error2.rb +1 -0
- data/spec/data/anonymous_loader/1/test1.rb +1 -0
- data/spec/data/anonymous_loader/1/test2.rb +1 -0
- data/spec/lib/smallcage/anonymous_loader_spec.rb +37 -0
- data/spec/lib/smallcage/application_spec.rb +271 -0
- data/spec/{smallcage → lib/smallcage}/commands/auto_spec.rb +0 -0
- data/spec/{export_spec.rb → lib/smallcage/commands/export_spec.rb} +8 -10
- data/spec/{import_spec.rb → lib/smallcage/commands/import_spec.rb} +5 -6
- data/spec/{manifest_spec.rb → lib/smallcage/commands/manifest_spec.rb} +4 -3
- data/spec/{smallcage → lib/smallcage}/commands/server_spec.rb +0 -0
- data/spec/{update_spec.rb → lib/smallcage/commands/update_spec.rb} +15 -19
- data/spec/{uri_spec.rb → lib/smallcage/commands/uri_spec.rb} +3 -4
- data/spec/{document_path_spec.rb → lib/smallcage/document_path_spec.rb} +19 -31
- data/spec/{loader_spec.rb → lib/smallcage/loader_spec.rb} +16 -18
- data/spec/lib/smallcage/misc_spec.rb +18 -0
- data/spec/{update_list_spec.rb → lib/smallcage/update_list_spec.rb} +18 -21
- data/spec/{smallcage_spec.rb → lib/smallcage_spec.rb} +1 -1
- data/spec/spec_helper.rb +5 -4
- metadata +85 -55
- checksums.yaml +0 -7
- data/Gemfile.lock +0 -32
- data/spec/misc_spec.rb +0 -25
- data/spec/smallcage/application_spec.rb +0 -271
@@ -6,15 +6,15 @@ module SmallCage
|
|
6
6
|
def shift_jis(&block)
|
7
7
|
nkf("-Wsm0", &block)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def iso_2022_jp(&block)
|
11
11
|
nkf("-Wjm0", &block)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def euc_jp(&block)
|
15
15
|
nkf("-Wem0", &block)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def nkf(opt, &block)
|
19
19
|
src = _capture(&block)
|
20
20
|
@erbout << NKF.nkf(opt, src)
|
@@ -25,15 +25,15 @@ module SmallCage
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# Convert charset inside of block.
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# <%- set_charset do -%>
|
30
30
|
# <%= header %>
|
31
31
|
# <%= body %>
|
32
32
|
# <%= footer %>
|
33
33
|
# <%- end -%>
|
34
|
-
#
|
34
|
+
#
|
35
35
|
# In _dir.smc or other *.smc:
|
36
|
-
#
|
36
|
+
#
|
37
37
|
# charset: Shift_JIS
|
38
38
|
#
|
39
39
|
# In header.rhtml:
|
@@ -42,7 +42,7 @@ module SmallCage
|
|
42
42
|
#
|
43
43
|
# If you have to edit all templates to call set_charset method,
|
44
44
|
# you should use nkf_filter.rb instead.
|
45
|
-
#
|
45
|
+
#
|
46
46
|
def set_charset(&block)
|
47
47
|
c = charset()
|
48
48
|
if c =~ /^euc-jp$/i
|
@@ -55,6 +55,5 @@ module SmallCage
|
|
55
55
|
yield
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
59
58
|
end
|
60
|
-
end
|
59
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
2
|
namespace :svn do
|
3
3
|
|
4
|
-
# _dir.smc
|
4
|
+
# _dir.smc
|
5
5
|
# svnignore: *.html # set recursively.
|
6
|
-
# svnignore_current: .project # add only current dir.
|
6
|
+
# svnignore_current: .project # add only current dir.
|
7
7
|
# svnignore_reset: true # ignore parent directory settings.
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# You can use list.
|
10
10
|
# svnignore:
|
11
11
|
# - *.html
|
@@ -36,7 +36,7 @@ def load_svnignores(loader, path)
|
|
36
36
|
unless data.to_s.empty?
|
37
37
|
ignores << data
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
ignores.flatten!
|
41
41
|
ignores.uniq!
|
42
42
|
ignores.sort!
|
@@ -45,7 +45,7 @@ end
|
|
45
45
|
|
46
46
|
def set_svnignore(dryrun = false)
|
47
47
|
loader = SmallCage::Loader.new(".")
|
48
|
-
|
48
|
+
|
49
49
|
exec_svn(loader, ".", dryrun)
|
50
50
|
Dir.glob("**/") do |f|
|
51
51
|
exec_svn(loader, f, dryrun)
|
@@ -61,4 +61,3 @@ def exec_svn(loader, f, dryrun)
|
|
61
61
|
return if dryrun
|
62
62
|
puts "FAILED: #{cmd}" unless system cmd
|
63
63
|
end
|
64
|
-
|
@@ -1,23 +1,22 @@
|
|
1
1
|
module SmallCage
|
2
2
|
module MenuHelper
|
3
|
-
|
3
|
+
|
4
4
|
def menu_active(name)
|
5
5
|
p = @obj["menu_path"]
|
6
6
|
p ||= @obj["uri"]
|
7
7
|
return p =~ %r{^/#{name}/} ? "active" : "inactive"
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def menu_active_rex(rex)
|
11
11
|
p = @obj["menu_path"]
|
12
12
|
p ||= @obj["uri"]
|
13
13
|
return p =~ rex ? "active" : "inactive"
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def topic_dirs
|
17
17
|
result = @obj["dirs"].dup
|
18
18
|
result.reject! {|d| d["topic"].nil? }
|
19
19
|
return result
|
20
20
|
end
|
21
|
-
|
22
21
|
end
|
23
|
-
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
1 / 0
|
@@ -0,0 +1 @@
|
|
1
|
+
require '_no_such_file_'
|
@@ -0,0 +1 @@
|
|
1
|
+
TEST_1 = 1
|
@@ -0,0 +1 @@
|
|
1
|
+
TEST_2 = 2
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'smallcage'
|
3
|
+
|
4
|
+
describe SmallCage::AnonymousLoader do
|
5
|
+
let(:root_dir) { File.join(SPEC_DATA_DIR, 'anonymous_loader') }
|
6
|
+
let(:dir1) { File.join(root_dir, '1') }
|
7
|
+
|
8
|
+
it 'loads ruby files' do
|
9
|
+
result = SmallCage::AnonymousLoader.load(dir1, /(test\d)\.rb\z/)
|
10
|
+
expect(result[:names]).to eq %w{Test1 Test2}
|
11
|
+
expect(result[:module]::TEST_1).to eq 1
|
12
|
+
expect(result[:module]::TEST_2).to eq 2
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when directory does not exist' do
|
16
|
+
it 'returns empty result' do
|
17
|
+
dir = File.join(root_dir, '0')
|
18
|
+
result = SmallCage::AnonymousLoader.load(dir, /(test\d)\.rb\z/)
|
19
|
+
expect(result[:names]).to eq []
|
20
|
+
expect(result[:module]).to be_a(Module)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when loaded file cause error' do
|
25
|
+
subject { SmallCage::AnonymousLoader.load(dir1, pattern) }
|
26
|
+
|
27
|
+
context '1 / 0' do
|
28
|
+
let(:pattern) { /(error1)\.rb\z/ }
|
29
|
+
it { expect { subject }.to raise_error ZeroDivisionError }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'require "_no_such_file_"' do
|
33
|
+
let(:pattern) { /(error2)\.rb\z/ }
|
34
|
+
it { expect { subject }.to raise_error LoadError }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,271 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
require 'smallcage'
|
3
|
+
|
4
|
+
describe SmallCage::Application do
|
5
|
+
|
6
|
+
def capture_result
|
7
|
+
status = nil
|
8
|
+
result = nil
|
9
|
+
tmpout = StringIO.new
|
10
|
+
tmperr = StringIO.new
|
11
|
+
original_out, $stdout = $stdout, tmpout
|
12
|
+
original_err, $stderr = $stderr, tmperr
|
13
|
+
begin
|
14
|
+
result = yield
|
15
|
+
rescue SystemExit => e
|
16
|
+
status = e.status
|
17
|
+
ensure
|
18
|
+
$stdout = original_out
|
19
|
+
$stderr = original_err
|
20
|
+
end
|
21
|
+
|
22
|
+
return {
|
23
|
+
:exit => status,
|
24
|
+
:result => result,
|
25
|
+
:stdout => tmpout.string,
|
26
|
+
:stderr => tmperr.string
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
before(:each) do
|
31
|
+
@target = SmallCage::Application.new
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should parse update command' do
|
35
|
+
options = @target.parse_options(['update', '.'])
|
36
|
+
options.should eq(:path => '.', :command => :update, :quiet => false)
|
37
|
+
|
38
|
+
options = @target.parse_options(['up', '.'])
|
39
|
+
options.should eq(:path => '.', :command => :update, :quiet => false)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should parse clean command' do
|
43
|
+
options = @target.parse_options(['clean', '.'])
|
44
|
+
options.should eq(:path => '.', :command => :clean, :quiet => false)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should parse server command' do
|
48
|
+
options = @target.parse_options(['server', '.'])
|
49
|
+
options.should eq(:path => '.', :command => :server, :quiet => false, :port => 8080) # num
|
50
|
+
|
51
|
+
options = @target.parse_options(['sv', '.', '8080'])
|
52
|
+
options.should eq(:path => '.', :command => :server, :quiet => false, :port => 8080) # string
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should accept only number port' do
|
56
|
+
result = capture_result { @target.parse_options(['server', '.', 'pot']) }
|
57
|
+
result[:exit].should eq 1
|
58
|
+
result[:stdout].should be_empty
|
59
|
+
result[:stderr].should eq "illegal port number: pot\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should not accept port 0' do
|
63
|
+
result = capture_result { @target.parse_options(['server', '.', '0']) }
|
64
|
+
result[:exit].should eq 1
|
65
|
+
result[:stdout].should be_empty
|
66
|
+
result[:stderr].should eq "illegal port number: 0\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should parse auto command' do
|
70
|
+
options = @target.parse_options(['auto', '.'])
|
71
|
+
options.should eq(:path => '.', :command => :auto, :port => nil, :bell => false, :quiet => false)
|
72
|
+
|
73
|
+
options = @target.parse_options(['au', '.', '8080'])
|
74
|
+
options.should eq(:path => '.', :command => :auto, :port => 8080, :bell => false, :quiet => false)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should parse import command' do
|
78
|
+
options = @target.parse_options(['import', 'base', '.'])
|
79
|
+
options.should eq(:command => :import, :from => 'base', :to => '.', :quiet => false)
|
80
|
+
|
81
|
+
options = @target.parse_options(['import'])
|
82
|
+
options.should eq(:command => :import, :from => 'default', :to => '.', :quiet => false)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should parse export command' do
|
86
|
+
options = @target.parse_options(['export', '.', 'path'])
|
87
|
+
options.should eq(:command => :export, :path => '.', :out => 'path', :quiet => false)
|
88
|
+
|
89
|
+
options = @target.parse_options(['export'])
|
90
|
+
options.should eq(:command => :export, :path => '.', :out => nil, :quiet => false)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should parse uri command' do
|
94
|
+
options = @target.parse_options(['uri', './path/to/target'])
|
95
|
+
options.should eq(:command => :uri, :path => './path/to/target', :quiet => false)
|
96
|
+
|
97
|
+
options = @target.parse_options(['uri'])
|
98
|
+
options.should eq(:command => :uri, :path => '.', :quiet => false)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should parse manifest command' do
|
102
|
+
options = @target.parse_options(['manifest', './path/to/target'])
|
103
|
+
options.should eq(:command => :manifest, :path => './path/to/target', :quiet => false)
|
104
|
+
|
105
|
+
options = @target.parse_options(['manifest'])
|
106
|
+
options.should eq( :command => :manifest, :path => '.', :quiet => false )
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should exit 1 if command is empty' do
|
110
|
+
result = capture_result { @target.parse_options([]) }
|
111
|
+
result[:exit].should eq 1
|
112
|
+
result[:stdout].should =~ /\AUsage:/
|
113
|
+
result[:stdout].should =~ /^Subcommands are:/
|
114
|
+
result[:stderr].should be_empty
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should show help' do
|
118
|
+
result = capture_result { @target.parse_options(['help']) }
|
119
|
+
result[:exit].should eq 0
|
120
|
+
result[:stdout].should =~ /\AUsage:/
|
121
|
+
result[:stdout].should =~ /^Subcommands are:/
|
122
|
+
result[:stderr].should be_empty
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should show help if the arguments include --help' do
|
126
|
+
result = capture_result { @target.parse_options(['--help', 'update']) }
|
127
|
+
result[:exit].should eq 0
|
128
|
+
result[:stdout].should =~ /\AUsage:/
|
129
|
+
result[:stdout].should =~ /^Subcommands are:/
|
130
|
+
result[:stderr].should be_empty
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should show subcommand help' do
|
134
|
+
result = capture_result { @target.parse_options(['help', 'update']) }
|
135
|
+
result[:exit].should eq 0
|
136
|
+
result[:stdout].should =~ /\AUsage: smc update \[path\]/
|
137
|
+
result[:stderr].should be_empty
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should exit if the command is unknown' do
|
141
|
+
result = capture_result { @target.parse_options(['xxxx']) }
|
142
|
+
result[:exit].should eq 1
|
143
|
+
result[:stdout].should be_empty
|
144
|
+
result[:stderr].should eq "no such subcommand: xxxx\n"
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should show version' do
|
148
|
+
result = capture_result { @target.parse_options(['--version', 'update']) }
|
149
|
+
result[:exit].should eq 0
|
150
|
+
result[:stdout].should =~ /\ASmallCage \d+\.\d+\.\d+ - /
|
151
|
+
result[:stderr].should be_empty
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should exit when subcommand is empty' do
|
155
|
+
result = capture_result { @target.parse_options(['', '--version']) }
|
156
|
+
result[:exit].should eq 1
|
157
|
+
result[:stdout].should =~ /\AUsage:/
|
158
|
+
result[:stdout].should =~ /^Subcommands are:/
|
159
|
+
result[:stderr].should be_empty
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should ignore subcommand with --version option' do
|
163
|
+
result = capture_result { @target.parse_options(['help', '--version']) }
|
164
|
+
result[:exit].should eq 0
|
165
|
+
result[:stdout].should =~ /\ASmallCage \d+\.\d+\.\d+ - /
|
166
|
+
result[:stderr].should be_empty
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should ignore subcommand with -v option' do
|
170
|
+
result = capture_result { @target.parse_options(['help', '-v']) }
|
171
|
+
result[:exit].should eq 0
|
172
|
+
result[:stdout].should =~ /\ASmallCage \d+\.\d+\.\d+ - /
|
173
|
+
result[:stderr].should be_empty
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should ignore subcommand with --help option' do
|
177
|
+
result = capture_result { @target.parse_options(['update', '--help']) }
|
178
|
+
result[:exit].should eq 0
|
179
|
+
result[:stdout].should =~ /\AUsage: smc update \[path\] \[options\]/
|
180
|
+
result[:stderr].should be_empty
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should ignore subcommand with -h option' do
|
184
|
+
result = capture_result { @target.parse_options(['update', '-h']) }
|
185
|
+
result[:exit].should eq 0
|
186
|
+
result[:stdout].should =~ /\AUsage: smc update \[path\] \[options\]/
|
187
|
+
result[:stderr].should be_empty
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should exit with unknown main option --QQQ' do
|
191
|
+
result = capture_result { @target.parse_options(['--QQQ']) }
|
192
|
+
result[:exit].should eq 1
|
193
|
+
result[:stdout].should be_empty
|
194
|
+
result[:stderr].should eq "invalid option: --QQQ\n"
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should exit with unknown sub option --QQQ' do
|
198
|
+
result = capture_result { @target.parse_options(['update', '--QQQ']) }
|
199
|
+
result[:exit].should eq 1
|
200
|
+
result[:stdout].should be_empty
|
201
|
+
result[:stderr].should eq "invalid option: --QQQ\n"
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should accept auto command --bell option' do
|
205
|
+
result = capture_result { @target.parse_options(['auto', '--bell']) }
|
206
|
+
result[:exit].should be_nil
|
207
|
+
result[:stdout].should be_empty
|
208
|
+
result[:stderr].should be_empty
|
209
|
+
result[:result].should eq(
|
210
|
+
:command => :auto,
|
211
|
+
:port => nil,
|
212
|
+
:path => '.',
|
213
|
+
:bell => true,
|
214
|
+
:quiet => false
|
215
|
+
)
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should set bell option false as default' do
|
219
|
+
result = capture_result { @target.parse_options(['auto']) }
|
220
|
+
result[:exit].should be_nil
|
221
|
+
result[:stdout].should be_empty
|
222
|
+
result[:stderr].should be_empty
|
223
|
+
result[:result].should eq(
|
224
|
+
:command => :auto,
|
225
|
+
:port => nil,
|
226
|
+
:path => '.',
|
227
|
+
:bell => false,
|
228
|
+
:quiet => false
|
229
|
+
)
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should accept --quiet option' do
|
233
|
+
result = capture_result { @target.parse_options(['--quiet', 'update']) }
|
234
|
+
result[:exit].should be_nil
|
235
|
+
result[:stdout].should be_empty
|
236
|
+
result[:stderr].should be_empty
|
237
|
+
result[:result].should eq(
|
238
|
+
:command => :update,
|
239
|
+
:path => '.',
|
240
|
+
:quiet => true
|
241
|
+
)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'should accept --quiet option after subcommand' do
|
245
|
+
result = capture_result { @target.parse_options(['update', '--quiet']) }
|
246
|
+
result[:exit].should be_nil
|
247
|
+
result[:stdout].should be_empty
|
248
|
+
result[:stderr].should be_empty
|
249
|
+
result[:result].should eq(
|
250
|
+
:command => :update,
|
251
|
+
:path => '.',
|
252
|
+
:quiet => true
|
253
|
+
)
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'should accept --quiet option before and after subcommand' do
|
257
|
+
opts = %w{--quiet auto --quiet path --bell 80}
|
258
|
+
result = capture_result { @target.parse_options(opts) }
|
259
|
+
result[:exit].should be_nil
|
260
|
+
result[:stdout].should be_empty
|
261
|
+
result[:stderr].should be_empty
|
262
|
+
result[:result].should eq(
|
263
|
+
:command => :auto,
|
264
|
+
:path => 'path',
|
265
|
+
:port => 80,
|
266
|
+
:bell => true,
|
267
|
+
:quiet => true
|
268
|
+
)
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|