jeremylightsmith-actionsite 0.4 → 0.6

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/Rakefile CHANGED
@@ -18,6 +18,7 @@ desc "generate gemspec"
18
18
  task :gemspec do
19
19
  File.open("actionsite.gemspec", "w") do |f|
20
20
  f << ERB.new(File.read("actionsite.gemspec.erb"), 0, "%<>").result(binding)
21
- end
21
+ end
22
+ puts "generated gemspec for actionsite #{ActionSite::VERSION}"
22
23
  end
23
24
 
data/lib/action_site.rb CHANGED
@@ -19,5 +19,5 @@ require 'action_site/link_checker'
19
19
  require 'action_site/async_link_checker'
20
20
 
21
21
  module ActionSite
22
- VERSION = 0.4
22
+ VERSION = "0.6"
23
23
  end
@@ -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[in_dir + "/*"].each do |in_file|
40
- out_file = in_file.gsub(in_dir, out_dir)
41
-
42
- if excluded?(in_file)
43
- # nothing
44
-
45
- elsif File.symlink?(in_file)
46
- cp in_file, out_file rescue nil # maybe the links don't exist here
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
- elsif File.directory?(in_file)
49
- mkdir_p out_file
50
- generate in_file, out_file
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
- elsif resource?(in_file)
53
- ln_s File.expand_path(in_file), File.expand_path(out_file)
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
- else
56
- out_file = out_file.gsub(/\..+$/, '.html')
57
- generate_page(in_file, out_file)
58
- puts " #{in_file} => #{out_file}"
59
- end
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"
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: []