jeremylightsmith-actionsite 0.4 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/lib/action_site.rb +1 -1
- data/lib/action_site/site.rb +60 -20
- metadata +11 -1
data/Rakefile
CHANGED
data/lib/action_site.rb
CHANGED
data/lib/action_site/site.rb
CHANGED
@@ -7,6 +7,8 @@ require 'action_site/generators/markaby_generator'
|
|
7
7
|
require 'action_site/generators/redcloth_generator'
|
8
8
|
require 'action_site/generators/yaml_generator'
|
9
9
|
|
10
|
+
require 'thin'
|
11
|
+
|
10
12
|
module ActionSite
|
11
13
|
EXCLUDED_DIRECTORIES = %w(layouts helpers)
|
12
14
|
RESOURCE_EXTENSIONS = %w(css ico gif jpg png js pdf)
|
@@ -19,8 +21,9 @@ module ActionSite
|
|
19
21
|
}
|
20
22
|
|
21
23
|
class Site
|
24
|
+
include FileUtils
|
22
25
|
attr_reader :context
|
23
|
-
|
26
|
+
|
24
27
|
def initialize(in_dir, out_dir)
|
25
28
|
@context = Context.new
|
26
29
|
@generator = HtmlGenerator.new(@context, in_dir, generators)
|
@@ -36,30 +39,44 @@ module ActionSite
|
|
36
39
|
end
|
37
40
|
|
38
41
|
def generate(in_dir = @in_dir, out_dir = @out_dir)
|
39
|
-
Dir
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
Dir.chdir(@in_dir) do
|
43
|
+
Dir["**/*"].each do |path|
|
44
|
+
refresh_page path
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def refresh_page(path)
|
50
|
+
in_file, out_file = File.join(@in_dir, path), File.join(@out_dir, path)
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
if !File.exist?(in_file)
|
53
|
+
# is there another version that does?
|
54
|
+
return unless in_file.extension == "html" && (in_file = Dir[in_file.split_filename[0] + ".*"].first)
|
55
|
+
end
|
56
|
+
|
57
|
+
if excluded?(in_file)
|
58
|
+
# nothing
|
51
59
|
|
52
|
-
|
53
|
-
|
60
|
+
elsif File.symlink?(in_file)
|
61
|
+
mkdir_p File.dirname(out_file)
|
62
|
+
cp in_file, out_file rescue nil # maybe the links don't exist here
|
54
63
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
64
|
+
elsif File.directory?(in_file)
|
65
|
+
mkdir_p out_file
|
66
|
+
generate in_file, out_file
|
67
|
+
|
68
|
+
elsif resource?(in_file)
|
69
|
+
mkdir_p File.dirname(out_file)
|
70
|
+
ln_sf File.expand_path(in_file), File.expand_path(out_file)
|
71
|
+
|
72
|
+
else
|
73
|
+
mkdir_p File.dirname(out_file)
|
74
|
+
out_file = out_file.gsub(/\..+$/, '.html')
|
75
|
+
generate_page(in_file, out_file)
|
76
|
+
puts " #{in_file} => #{out_file}"
|
60
77
|
end
|
61
78
|
end
|
62
|
-
|
79
|
+
|
63
80
|
def excluded?(file)
|
64
81
|
File.directory?(file) && EXCLUDED_DIRECTORIES.include?(File.basename(file))
|
65
82
|
end
|
@@ -68,6 +85,29 @@ module ActionSite
|
|
68
85
|
RESOURCE_EXTENSIONS.include?(file.extension)
|
69
86
|
end
|
70
87
|
|
88
|
+
def serve(port = 3000)
|
89
|
+
app = proc do |env|
|
90
|
+
path = env["PATH_INFO"]
|
91
|
+
file = File.join("public", "brenda", path)
|
92
|
+
if File.directory?(file)
|
93
|
+
path = env["PATH_INFO"] = File.join(path, "index.html")
|
94
|
+
end
|
95
|
+
|
96
|
+
begin
|
97
|
+
refresh_page(path)
|
98
|
+
rescue Exception
|
99
|
+
return [500, {"Content-Type" => "text/plain"}, "Error in generation :\n\n#{$!.to_s}\n#{$!.backtrace.join("\n")}"]
|
100
|
+
end
|
101
|
+
|
102
|
+
Rack::File.new("public/brenda").call(env)
|
103
|
+
end
|
104
|
+
|
105
|
+
Thin::Server.start('0.0.0.0', port) do
|
106
|
+
use Rack::CommonLogger
|
107
|
+
run app
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
71
111
|
private
|
72
112
|
|
73
113
|
def generate_page(in_file, out_file)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeremylightsmith-actionsite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.6"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Lightsmith
|
@@ -42,6 +42,16 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 0.0.0
|
44
44
|
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: thin
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
version:
|
45
55
|
description: ActionSite is a static site generator for ruby patterned after rails view templates supporting erb, yaml, redcloth and markaby(ish).
|
46
56
|
email: jeremy.lightsmith@gmail.com
|
47
57
|
executables: []
|