smallcage 0.0.8 → 0.0.9
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 +10 -0
- data/Manifest.txt +23 -7
- data/bin/smc +6 -126
- data/lib/smallcage.rb +4 -8
- data/lib/smallcage/application.rb +159 -0
- data/lib/smallcage/commands/auto.rb +133 -27
- data/lib/smallcage/commands/base.rb +19 -0
- data/lib/smallcage/commands/clean.rb +10 -2
- data/lib/smallcage/commands/export.rb +41 -0
- data/lib/smallcage/commands/import.rb +12 -7
- data/lib/smallcage/commands/manifest.rb +1 -1
- data/lib/smallcage/commands/server.rb +5 -14
- data/lib/smallcage/commands/update.rb +92 -11
- data/lib/smallcage/document_path.rb +46 -0
- data/lib/smallcage/http_server.rb +66 -0
- data/lib/smallcage/loader.rb +37 -26
- data/lib/smallcage/{commands → resources}/Manifest.erb +0 -0
- data/lib/smallcage/resources/auto.html +119 -0
- data/lib/smallcage/runner.rb +15 -0
- data/lib/smallcage/version.rb +1 -1
- data/project/{default → base}/_smc/helpers/base_helper.rb +0 -0
- data/project/{default → base}/_smc/helpers/site_helper.rb +0 -0
- data/project/{default → base}/_smc/templates/default.rhtml +0 -0
- data/project/{default → base}/_smc/templates/footer.rhtml +0 -0
- data/project/{default → base}/_smc/templates/header.rhtml +0 -0
- data/project/lang/_smc/helpers/lang_helper.rb +19 -0
- data/project/lang/_smc/templates/other_lang.rhtml +6 -0
- data/project/redcloth/_smc/helpers/red_cloth_helper.rb +14 -0
- data/project/redcloth/_smc/templates/markdown.rhtml +5 -0
- data/project/redcloth/_smc/templates/textile.rhtml +5 -0
- data/project/standard/_smc/helpers/menu_helper.rb +2 -2
- data/project/standard/about/index.html.smc +1 -1
- data/project/standard/index.html.smc +1 -1
- data/project/standard/sample1/index.html.smc +1 -1
- data/project/standard/sample1/index2.html.smc +1 -1
- data/project/standard/sample2/index.html.smc +1 -1
- data/spec/data/htdocs1/a/b/c/index.html.smc +6 -1
- data/{log/debug.log → spec/data/htdocs2/_smc/templates/dummy.rhtml} +0 -0
- data/spec/data/htdocs2/a/b/c/test.html +1 -0
- data/spec/data/htdocs2/a/b/test.html +1 -0
- data/spec/data/htdocs2/a/test.html.smc +2 -0
- data/spec/document_path_spec.rb +42 -0
- data/spec/export_spec.rb +45 -0
- data/spec/loader_spec.rb +20 -6
- data/spec/manifest_spec.rb +18 -11
- data/spec/smallcage_spec.rb +17 -11
- metadata +25 -9
File without changes
|
@@ -0,0 +1,119 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>SmallCage Auto Update</title>
|
4
|
+
<script type="text/javascript">
|
5
|
+
<!--
|
6
|
+
|
7
|
+
function getTransport() {
|
8
|
+
var imprements = [
|
9
|
+
function() {return new XMLHttpRequest()},
|
10
|
+
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
|
11
|
+
function() {return new ActiveXObject('Microsoft.XMLHTTP')}
|
12
|
+
];
|
13
|
+
var returnValue;
|
14
|
+
for (var i = 0; i < imprements.length; i++) {
|
15
|
+
var lambda = imprements[i];
|
16
|
+
try {
|
17
|
+
returnValue = lambda();
|
18
|
+
break;
|
19
|
+
} catch (e) { }
|
20
|
+
}
|
21
|
+
return returnValue;
|
22
|
+
}
|
23
|
+
|
24
|
+
function getSource(uri, loaded, failed) {
|
25
|
+
var transport = getTransport();
|
26
|
+
transport.open("GET", uri, true);
|
27
|
+
|
28
|
+
transport.onreadystatechange=function() {
|
29
|
+
if (transport.readyState == 4) {
|
30
|
+
if (transport.status == 200) {
|
31
|
+
loaded(transport.responseText);
|
32
|
+
} else {
|
33
|
+
if (failed) {
|
34
|
+
failed(transport);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
transport.send(null);
|
40
|
+
}
|
41
|
+
|
42
|
+
function initTimer(span) {
|
43
|
+
window.setInterval("checkUpdate()", span);
|
44
|
+
}
|
45
|
+
|
46
|
+
var loading = false;
|
47
|
+
var currentSrc = "";
|
48
|
+
var currentUri = "";
|
49
|
+
|
50
|
+
function checkUpdate() {
|
51
|
+
if (loading) {
|
52
|
+
return false;
|
53
|
+
}
|
54
|
+
|
55
|
+
if (scrollWait) {
|
56
|
+
targetWindow.scrollBy(scrollWait.x, scrollWait.y);
|
57
|
+
scrollWait = null;
|
58
|
+
}
|
59
|
+
|
60
|
+
var success = function(src) {
|
61
|
+
loading = false;
|
62
|
+
if (currentSrc == src) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
currentSrc = src;
|
66
|
+
|
67
|
+
lines = src.split("\n")
|
68
|
+
var uri = lines[0];
|
69
|
+
showPage(uri);
|
70
|
+
document.getElementById("main").innerHTML =
|
71
|
+
"<p>Latest Updated Page: <a href=\"" + uri + "\" target=\"smcauto\">" + uri + "</a></p><p>" + lines[1] + "</p>";
|
72
|
+
};
|
73
|
+
var failed = function(src) {
|
74
|
+
document.getElementById("main").innerHTML = "<p>Load error</p>";
|
75
|
+
};
|
76
|
+
|
77
|
+
getSource("/_smc/update_uri", success, failed);
|
78
|
+
loading = true;
|
79
|
+
}
|
80
|
+
|
81
|
+
var targetWindow = null;
|
82
|
+
var scrollWait = null;
|
83
|
+
function showPage(uri) {
|
84
|
+
if (targetWindow == null) {
|
85
|
+
if (uri == ":reload") {
|
86
|
+
uri = "/";
|
87
|
+
}
|
88
|
+
targetWindow = window.open(uri, "smcauto");
|
89
|
+
} else {
|
90
|
+
if (uri == ":reload") {
|
91
|
+
var realuri = targetWindow.location.href;
|
92
|
+
} else {
|
93
|
+
var realuri = uri;
|
94
|
+
}
|
95
|
+
|
96
|
+
var x = targetWindow.scrollX;
|
97
|
+
var y = targetWindow.scrollY;
|
98
|
+
|
99
|
+
targetWindow.location = realuri;
|
100
|
+
if (currentUri == realuri) {
|
101
|
+
scrollWait = {"x": x, "y":y};
|
102
|
+
}
|
103
|
+
}
|
104
|
+
currentUri = uri;
|
105
|
+
}
|
106
|
+
|
107
|
+
// -->
|
108
|
+
</script>
|
109
|
+
|
110
|
+
</head>
|
111
|
+
|
112
|
+
<body onLoad="initTimer(1000)">
|
113
|
+
|
114
|
+
<div id="main">
|
115
|
+
Latest Updated Page:
|
116
|
+
</div>
|
117
|
+
|
118
|
+
</body>
|
119
|
+
</html>
|
data/lib/smallcage/runner.rb
CHANGED
@@ -6,31 +6,46 @@ module SmallCage
|
|
6
6
|
|
7
7
|
def initialize(opts)
|
8
8
|
@opts = opts
|
9
|
+
require_command "base"
|
9
10
|
end
|
10
11
|
|
11
12
|
def update
|
13
|
+
require_command "update"
|
12
14
|
SmallCage::Commands::Update.execute(@opts)
|
13
15
|
end
|
14
16
|
|
15
17
|
def clean
|
18
|
+
require_command "clean"
|
16
19
|
SmallCage::Commands::Clean.execute(@opts)
|
17
20
|
end
|
18
21
|
|
19
22
|
def server
|
23
|
+
require_command "server"
|
20
24
|
SmallCage::Commands::Server.execute(@opts)
|
21
25
|
end
|
22
26
|
|
23
27
|
def auto
|
28
|
+
require_command "auto"
|
24
29
|
SmallCage::Commands::Auto.execute(@opts)
|
25
30
|
end
|
26
31
|
|
27
32
|
def import
|
33
|
+
require_command "import"
|
28
34
|
SmallCage::Commands::Import.execute(@opts)
|
29
35
|
end
|
30
36
|
|
31
37
|
def manifest
|
38
|
+
require_command "manifest"
|
32
39
|
SmallCage::Commands::Manifest.execute(@opts)
|
33
40
|
end
|
41
|
+
|
42
|
+
def export
|
43
|
+
require_command "export"
|
44
|
+
SmallCage::Commands::Export.execute(@opts)
|
45
|
+
end
|
34
46
|
|
47
|
+
def require_command(name)
|
48
|
+
require "smallcage/commands/#{name}.rb"
|
49
|
+
end
|
35
50
|
end
|
36
51
|
end
|
data/lib/smallcage/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SmallCage
|
2
|
+
module LangHelper
|
3
|
+
|
4
|
+
def lang
|
5
|
+
return @obj["lang"] unless @obj["lang"].nil?
|
6
|
+
|
7
|
+
if @obj["uri"] =~ %r{^/(ja|en)/}
|
8
|
+
return $1
|
9
|
+
end
|
10
|
+
|
11
|
+
return nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def switch_lang(code)
|
15
|
+
@obj["uri"].gsub(%r{^/(en|ja)/}, "/#{code}/")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -3,13 +3,13 @@ module SmallCage
|
|
3
3
|
|
4
4
|
def menu_active(name)
|
5
5
|
p = @obj["menu_path"]
|
6
|
-
p ||= uri
|
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
|
-
p ||= uri
|
12
|
+
p ||= @obj["uri"]
|
13
13
|
return p =~ rex ? "active" : "inactive"
|
14
14
|
end
|
15
15
|
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
c
|
@@ -0,0 +1 @@
|
|
1
|
+
b
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'smallcage'
|
3
|
+
|
4
|
+
describe SmallCage::DocumentPath do
|
5
|
+
root = Pathname.new(File.dirname(__FILE__) + "/data/htdocs1")
|
6
|
+
|
7
|
+
before do
|
8
|
+
@docpath = SmallCage::DocumentPath.new(root, root + "a/b/c/index.html.smc")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have uri property" do
|
12
|
+
@docpath.uri.should == "/a/b/c/index.html.smc"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return smc file or not" do
|
16
|
+
@docpath.smc?.should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return output file" do
|
20
|
+
out = @docpath.outfile
|
21
|
+
out.should be_an_instance_of(SmallCage::DocumentPath)
|
22
|
+
out.path.basename.to_s.should == "index.html"
|
23
|
+
out.path.to_s.should match(%r{^/.+/a/b/c/index.html$})
|
24
|
+
@docpath.path.to_s[0..-5].should == out.path.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return output file uri" do
|
28
|
+
out = @docpath.outuri
|
29
|
+
out.should == "/a/b/c/index.html"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return root uri" do
|
33
|
+
docpath = SmallCage::DocumentPath.new(root, root)
|
34
|
+
docpath.uri.should == "/"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return directory uri" do
|
38
|
+
docpath = SmallCage::DocumentPath.new(root, root + "a/b")
|
39
|
+
docpath.uri.should == "/a/b"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/export_spec.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'smallcage'
|
3
|
+
|
4
|
+
describe "SmallCage::Commands::Export" do
|
5
|
+
|
6
|
+
docroot = Pathname.new(File.dirname(__FILE__) + "/data/htdocs2")
|
7
|
+
outdir = Pathname.new(File.dirname(__FILE__) + "/data/out")
|
8
|
+
|
9
|
+
it "should export not smc files" do
|
10
|
+
begin
|
11
|
+
opts = { :command => "export",
|
12
|
+
:path => docroot.to_s,
|
13
|
+
:out => outdir.to_s,
|
14
|
+
:quiet => true }
|
15
|
+
SmallCage::Runner.run(opts)
|
16
|
+
|
17
|
+
(outdir + "./a/test.html.smc").exist?.should_not be_true
|
18
|
+
(outdir + "./a/test.html").exist?.should_not be_true
|
19
|
+
(outdir + "./a/b/test.html").exist?.should be_true
|
20
|
+
(outdir + "./a/b/c/test.html").exist?.should be_true
|
21
|
+
ensure
|
22
|
+
FileUtils.rm_r(outdir)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should export project subdirectory" do
|
27
|
+
begin
|
28
|
+
path = docroot + "a/b/c"
|
29
|
+
opts = { :command => "export",
|
30
|
+
:path => path.to_s,
|
31
|
+
:out => outdir.to_s,
|
32
|
+
:quiet => true }
|
33
|
+
SmallCage::Runner.run(opts)
|
34
|
+
|
35
|
+
(outdir + "./a/test.html.smc").exist?.should_not be_true
|
36
|
+
(outdir + "./a/test.html").exist?.should_not be_true
|
37
|
+
(outdir + "./a/b/test.html").exist?.should_not be_true
|
38
|
+
|
39
|
+
(outdir + "./a/b/c/test.html").exist?.should be_true
|
40
|
+
ensure
|
41
|
+
FileUtils.rm_r(outdir)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/spec/loader_spec.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
require 'smallcage'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe SmallCage::Loader do
|
5
5
|
|
6
|
-
|
6
|
+
before do
|
7
|
+
@docroot = Pathname.new(File.dirname(__FILE__) + "/data/htdocs1")
|
8
|
+
end
|
7
9
|
|
8
10
|
it "should load path value which returns Pathname object" do
|
9
|
-
ldr = SmallCage::Loader.new(docroot)
|
10
|
-
obj = ldr.load(docroot + "a/b/c/index.html.smc")
|
11
|
+
ldr = SmallCage::Loader.new(@docroot)
|
12
|
+
obj = ldr.load(@docroot + "a/b/c/index.html.smc")
|
11
13
|
|
12
14
|
obj["path"].should be_an_instance_of(Pathname)
|
13
15
|
obj["path"].smc.should be_an_instance_of(Pathname)
|
@@ -17,7 +19,7 @@ describe "SmallCage::Loader" do
|
|
17
19
|
end
|
18
20
|
|
19
21
|
it "should be able to omit smc extention" do
|
20
|
-
ldr = SmallCage::Loader.new(docroot + "a/b/c/index.html")
|
22
|
+
ldr = SmallCage::Loader.new(@docroot + "a/b/c/index.html")
|
21
23
|
objects = []
|
22
24
|
ldr.each_smc_obj do |o|
|
23
25
|
objects << o
|
@@ -29,7 +31,7 @@ describe "SmallCage::Loader" do
|
|
29
31
|
end
|
30
32
|
|
31
33
|
it "should find smc root dir" do
|
32
|
-
path = docroot + "a/b/c/index.html.smc"
|
34
|
+
path = @docroot + "a/b/c/index.html.smc"
|
33
35
|
|
34
36
|
depth = 5
|
35
37
|
root = SmallCage::Loader.find_root(path, depth)
|
@@ -38,4 +40,16 @@ describe "SmallCage::Loader" do
|
|
38
40
|
depth = 3
|
39
41
|
lambda { SmallCage::Loader.find_root(path, depth) }.should raise_error
|
40
42
|
end
|
43
|
+
|
44
|
+
it "should load strings" do
|
45
|
+
path = @docroot + "a/b/c/index.html.smc"
|
46
|
+
ldr = SmallCage::Loader.new(path)
|
47
|
+
|
48
|
+
root = SmallCage::Loader.find_root(path)
|
49
|
+
objects = []
|
50
|
+
ldr.each_smc_obj do |o|
|
51
|
+
objects << o
|
52
|
+
end
|
53
|
+
objects[0]["strings"][0].should == "abc\ndef\n\nghi"
|
54
|
+
end
|
41
55
|
end
|