plato 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,7 +1,2 @@
1
1
  .DS_Store
2
2
  /pkg
3
- /content
4
- /template
5
- /resources
6
- /cache
7
- /config.rb
data/Rakefile CHANGED
@@ -22,7 +22,8 @@ begin
22
22
  gemspec.email = "matt@freels.name"
23
23
  gemspec.homepage = "http://github.com/freels/plato"
24
24
  gemspec.authors = ["Matt Freels"]
25
- gemspec.add_dependency 'tilt', '>= 1.0.1'
25
+ gemspec.add_dependency 'tilt', '~> 1.0.1'
26
+ gemspec.add_dependency 'ruby_archive', '~> 0.1.2'
26
27
 
27
28
  # development
28
29
  gemspec.add_development_dependency 'rspec'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/bin/plato CHANGED
@@ -1,6 +1,45 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'plato'
4
+ require 'yaml'
5
+ require 'optparse'
4
6
 
5
- # bare-bones for now...
6
- Plato::Site.new.generate!
7
+ opts = {
8
+ 'root' => '.',
9
+ 'template' => 'template',
10
+ 'cache' => 'cache'
11
+ }
12
+
13
+ op = OptionParser.new {|op|
14
+ op.on('-s url') {|val| opts['base_url'] = val }
15
+ op.on('-d dir') {|val| opts['root'] = val }
16
+ op.on('-t template') {|val| opts['template'] = val }
17
+ op.on('-c cache') {|val| opts['cache'] = val }
18
+ op.on('-h', '--help') { puts op }
19
+ }
20
+
21
+ op.parse!(ARGV.dup)
22
+
23
+ platorc = File.join(opts['root'], 'platorc')
24
+
25
+ if File.exist? platorc
26
+ begin
27
+ opts.update YAML.load_file(platorc)
28
+ rescue
29
+ $stderr.puts "Error reading from platorc."; exit 2
30
+ end
31
+ end
32
+
33
+
34
+ # error checking
35
+
36
+ unless opts['base_url']
37
+ $stderr.puts "Error: Must specify a base site url: plato -s URL"
38
+ $stderr.puts "\n"
39
+ $stderr.puts op
40
+ exit 1
41
+ end
42
+
43
+ puts "Generating site..."
44
+ Plato::Site.new(*opts.values_at('base_url', 'template', 'cache', 'root')).generate!
45
+ puts "done!"
@@ -5,5 +5,5 @@ require 'fileutils'
5
5
  git_dir = ENV['GIT_DIR'] = File.expand_path(ENV['GIT_DIR'])
6
6
 
7
7
  FileUtils.cd '..'
8
- system "env GIT_DIR=#{git_dir} git reset --hard HEAD >> /tmp/post-receive 2>&1"
9
- system "plato >> /tmp/post-receive 2>&1"
8
+ system "env GIT_DIR=#{git_dir} git reset --hard HEAD"
9
+ system "plato"
data/lib/plato.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tilt'
2
+ require 'ruby_archive'
2
3
 
3
4
  module Plato
4
5
  require 'plato/config'
@@ -22,7 +22,7 @@ module Plato
22
22
 
23
23
  def save_to(path, codec = nil)
24
24
  repo = Repo.new(path, codec || self.codec)
25
- @contents.each {|path, hash| repo.save(path, hash) }
25
+ @contents.map {|path, hash| repo.save(path, hash); path }
26
26
  end
27
27
 
28
28
  def [](key)
data/lib/plato/site.rb CHANGED
@@ -1,26 +1,44 @@
1
1
  module Plato
2
2
  class Site
3
- attr_accessor :root
3
+ attr_reader :base_url
4
+ attr_reader :root
5
+ attr_reader :template_path, :config_path, :content_path, :resources_path, :cache_path
4
6
 
5
- def initialize(root = '.')
6
- @root = File.expand_path(root)
7
+ def initialize(base_url, template = 'template', cache = 'cache', root = '.')
8
+ @base_url = base_url
9
+ @root = File.expand_path(root)
10
+
11
+ @cache_path = File.expand_path(cache, @root)
12
+ @template_path = detect_zip_path File.expand_path(template, @root)
13
+
14
+ @config_path = File.join(@template_path, 'config.rb')
15
+ @content_path = File.join(@root, "content")
16
+ @resources_path = File.join(@root, "resources")
7
17
  end
8
18
 
9
19
  def generate!
10
20
  RenderContext.load_view_helpers(File.join(template_path, 'view_helpers.rb'))
11
- resources.save_to(cache_path)
12
- template_resources.save_to(cache_path)
13
- rendered_templates.save_to(cache_path)
14
- rendered_content.save_to(cache_path)
21
+ [ resources.save_to(cache_path),
22
+ template_resources.save_to(cache_path),
23
+ rendered_templates.save_to(cache_path),
24
+ rendered_content.save_to(cache_path)
25
+ ].each do |ps|
26
+ puts ps.map{|s| " » #{s}" }
27
+ end
15
28
  end
16
29
 
17
- def base_url; config['base_url'] end
30
+ DETECT_EXT = /(?:(.*)\/)?([^\/]+)\.([^.]+)\Z/
31
+ def detect_zip_path(path)
32
+ path = "#{path}.zip" if !File.exist? path and File.exist? "#{path}.zip"
18
33
 
19
- def config_path; File.join(root, "config.rb") end
20
- def template_path; File.join(root, "template") end
21
- def content_path; File.join(root, "content") end
22
- def resources_path; File.join(root, "resources") end
23
- def cache_path; File.join(root, "cache") end
34
+ if File.exist? path and !File.directory? path and path.match(DETECT_EXT)
35
+ dir, base, ext = path.match(DETECT_EXT).values_at(1,2,3)
36
+
37
+ [dir, "#{base}.#{ext}!", base].compact.join("/")
38
+ else
39
+ path
40
+ end
41
+ end
24
42
 
25
43
  def config
26
44
  @config ||= Config.read(ConfigDSL, File.read(config_path))
@@ -31,7 +49,7 @@ module Plato
31
49
 
32
50
  manifest = Manifest.new template_path, {
33
51
  :codec => :template,
34
- :filter => lambda {|p| p !~ /\Aview_helpers\.rb/ }
52
+ :filter => lambda {|p| p !~ /\A(config\.rb|view_helpers\.rb)/ }
35
53
  }
36
54
 
37
55
  path_parser = PathTemplate.new(":name*.:format.:engine")
data/plato.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{plato}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Freels"]
12
- s.date = %q{2010-08-10}
12
+ s.date = %q{2010-10-09}
13
13
  s.description = %q{use templates and content to generate static sites.}
14
14
  s.email = %q{matt@freels.name}
15
15
  s.executables = ["plato", "plato-prepare-repo"]
@@ -41,16 +41,19 @@ Gem::Specification.new do |s|
41
41
  s.specification_version = 3
42
42
 
43
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_runtime_dependency(%q<tilt>, [">= 1.0.1"])
44
+ s.add_runtime_dependency(%q<tilt>, ["~> 1.0.1"])
45
+ s.add_runtime_dependency(%q<ruby_archive>, ["~> 0.1.2"])
45
46
  s.add_development_dependency(%q<rspec>, [">= 0"])
46
47
  s.add_development_dependency(%q<rr>, [">= 0"])
47
48
  else
48
- s.add_dependency(%q<tilt>, [">= 1.0.1"])
49
+ s.add_dependency(%q<tilt>, ["~> 1.0.1"])
50
+ s.add_dependency(%q<ruby_archive>, ["~> 0.1.2"])
49
51
  s.add_dependency(%q<rspec>, [">= 0"])
50
52
  s.add_dependency(%q<rr>, [">= 0"])
51
53
  end
52
54
  else
53
- s.add_dependency(%q<tilt>, [">= 1.0.1"])
55
+ s.add_dependency(%q<tilt>, ["~> 1.0.1"])
56
+ s.add_dependency(%q<ruby_archive>, ["~> 0.1.2"])
54
57
  s.add_dependency(%q<rspec>, [">= 0"])
55
58
  s.add_dependency(%q<rr>, [">= 0"])
56
59
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plato
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Freels
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-10 00:00:00 -07:00
18
+ date: 2010-10-09 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  hash: 21
30
30
  segments:
@@ -35,9 +35,25 @@ dependencies:
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: rspec
38
+ name: ruby_archive
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 31
46
+ segments:
47
+ - 0
48
+ - 1
49
+ - 2
50
+ version: 0.1.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
41
57
  none: false
42
58
  requirements:
43
59
  - - ">="
@@ -47,11 +63,11 @@ dependencies:
47
63
  - 0
48
64
  version: "0"
49
65
  type: :development
50
- version_requirements: *id002
66
+ version_requirements: *id003
51
67
  - !ruby/object:Gem::Dependency
52
68
  name: rr
53
69
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
55
71
  none: false
56
72
  requirements:
57
73
  - - ">="
@@ -61,7 +77,7 @@ dependencies:
61
77
  - 0
62
78
  version: "0"
63
79
  type: :development
64
- version_requirements: *id003
80
+ version_requirements: *id004
65
81
  description: use templates and content to generate static sites.
66
82
  email: matt@freels.name
67
83
  executables: