hydeweb 0.0.1.pre1
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 +24 -0
- data/.yardopts +1 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/bin/hyde +60 -0
- data/hyde.gemspec +80 -0
- data/hydegen.gemspec +58 -0
- data/lib/hyde/init.rb +23 -0
- data/lib/hyde/layout.rb +7 -0
- data/lib/hyde/ostruct.rb +14 -0
- data/lib/hyde/page.rb +90 -0
- data/lib/hyde/project.rb +99 -0
- data/lib/hyde/renderer.rb +65 -0
- data/lib/hyde/renderers.rb +17 -0
- data/lib/hyde/utils.rb +13 -0
- data/lib/hyde.rb +15 -0
- data/test/fixtures/default/_config.yml +4 -0
- data/test/fixtures/default/_layouts/default.haml +5 -0
- data/test/fixtures/default/about/index.html +1 -0
- data/test/fixtures/default/foo.html.haml +3 -0
- data/test/fixtures/default/hyde +2 -0
- data/test/fixtures/default/index.html.haml +6 -0
- data/test/fixtures/default/layout_test.html.haml +6 -0
- data/test/fixtures/default/yes.html +2 -0
- data/test/helper.rb +27 -0
- data/test/test_hyde.rb +45 -0
- metadata +136 -0
data/.gitignore
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--files="docs/*"
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Sinefunc, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Hyde
|
2
|
+
====
|
3
|
+
|
4
|
+
Installation
|
5
|
+
------------
|
6
|
+
|
7
|
+
gem install hydeweb
|
8
|
+
|
9
|
+
Usage
|
10
|
+
-----
|
11
|
+
|
12
|
+
hyde create <project_name>
|
13
|
+
cd <project_name>
|
14
|
+
hyde start
|
15
|
+
|
16
|
+
To do
|
17
|
+
-----
|
18
|
+
|
19
|
+
- partials support
|
20
|
+
- more renderers
|
21
|
+
- less
|
22
|
+
- markdown
|
23
|
+
- textile
|
24
|
+
|
25
|
+
- hyde build
|
26
|
+
- hyde gen
|
27
|
+
- extensions support
|
28
|
+
|
29
|
+
- _meta.yml
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |s|
|
4
|
+
s.name = "hydeweb"
|
5
|
+
s.authors = ["Rico Sta. Cruz", "Sinefunc, Inc."]
|
6
|
+
s.email = "rico@sinefunc.com"
|
7
|
+
s.summary = "Website preprocessor"
|
8
|
+
s.homepage = "http://github.com/sinefunc/hyde"
|
9
|
+
s.description = "Website preprocessor"
|
10
|
+
s.add_dependency('sinatra', '>= 1.0.0')
|
11
|
+
s.add_dependency('less', '>= 1.2.21')
|
12
|
+
s.add_dependency('haml', '>= 2.2.20')
|
13
|
+
end
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/test_*.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
task :test => :check_dependencies
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "aoeu #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1.pre1
|
data/bin/hyde
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
lib_path = File.dirname(__FILE__) + "/../lib"
|
3
|
+
$:.unshift lib_path
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
require 'rubygems'
|
7
|
+
require 'hyde'
|
8
|
+
|
9
|
+
options = {
|
10
|
+
}
|
11
|
+
|
12
|
+
opts = OptionParser.new do |o|
|
13
|
+
o.banner = "usage: hyde <action> [<options>]"
|
14
|
+
o.separator ""
|
15
|
+
|
16
|
+
#o.on("-w", "--watch", "watch for changes") do
|
17
|
+
# options[:watch] = true
|
18
|
+
#end
|
19
|
+
|
20
|
+
o.separator "Actions:"
|
21
|
+
o.separator " start - Starts a server"
|
22
|
+
o.separator " build - Creates HTML files"
|
23
|
+
o.separator " create <name> - Starts a project"
|
24
|
+
o.separator ""
|
25
|
+
o.separator "Options:"
|
26
|
+
|
27
|
+
# Help
|
28
|
+
o.on_tail("-h", "--help", "show this message") do
|
29
|
+
puts opts
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.parse!
|
35
|
+
options[:action] = ARGV[0]
|
36
|
+
options[:params] = []
|
37
|
+
(1...ARGV.size).each { |i| options[:params] << ARGV[i] }
|
38
|
+
|
39
|
+
if options[:action] == 'start'
|
40
|
+
system "ruby #{lib_path}/hyde/init.rb"
|
41
|
+
|
42
|
+
elsif options[:action] == 'build'
|
43
|
+
Hyde::Project.new.build
|
44
|
+
|
45
|
+
elsif options[:action] == 'create'
|
46
|
+
unless options[:params].size == 1
|
47
|
+
puts opts
|
48
|
+
else
|
49
|
+
begin
|
50
|
+
Dir.mkdir options[:params][0]
|
51
|
+
rescue Errno::EEXIST
|
52
|
+
puts "Error: this directory already exists"
|
53
|
+
end
|
54
|
+
|
55
|
+
# TODO: Magic here
|
56
|
+
end
|
57
|
+
|
58
|
+
else
|
59
|
+
puts opts
|
60
|
+
end
|
data/hyde.gemspec
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{hyde}
|
8
|
+
s.version = "0.0.1.pre1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["rstacruz"]
|
12
|
+
s.date = %q{2010-04-27}
|
13
|
+
s.default_executable = %q{hyde}
|
14
|
+
s.description = %q{Website preprocessor}
|
15
|
+
s.email = %q{rico@sinefunc.com}
|
16
|
+
s.executables = ["hyde"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".gitignore",
|
23
|
+
".yardopts",
|
24
|
+
"LICENSE",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/hyde",
|
29
|
+
"hyde.gemspec",
|
30
|
+
"hydegen.gemspec",
|
31
|
+
"lib/hyde.rb",
|
32
|
+
"lib/hyde/init.rb",
|
33
|
+
"lib/hyde/layout.rb",
|
34
|
+
"lib/hyde/ostruct.rb",
|
35
|
+
"lib/hyde/page.rb",
|
36
|
+
"lib/hyde/project.rb",
|
37
|
+
"lib/hyde/renderer.rb",
|
38
|
+
"lib/hyde/renderers.rb",
|
39
|
+
"lib/hyde/utils.rb",
|
40
|
+
"test/fixtures/default/_config.yml",
|
41
|
+
"test/fixtures/default/_layouts/default.haml",
|
42
|
+
"test/fixtures/default/about/index.html",
|
43
|
+
"test/fixtures/default/foo.html.haml",
|
44
|
+
"test/fixtures/default/hyde",
|
45
|
+
"test/fixtures/default/index.html.haml",
|
46
|
+
"test/fixtures/default/layout_test.html.haml",
|
47
|
+
"test/fixtures/default/yes.html",
|
48
|
+
"test/helper.rb",
|
49
|
+
"test/test_hyde.rb"
|
50
|
+
]
|
51
|
+
s.homepage = %q{http://github.com/sinefunc/hyde}
|
52
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
53
|
+
s.require_paths = ["lib"]
|
54
|
+
s.rubygems_version = %q{1.3.6}
|
55
|
+
s.summary = %q{Website preprocessor}
|
56
|
+
s.test_files = [
|
57
|
+
"test/helper.rb",
|
58
|
+
"test/test_hyde.rb"
|
59
|
+
]
|
60
|
+
|
61
|
+
if s.respond_to? :specification_version then
|
62
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
|
67
|
+
s.add_runtime_dependency(%q<less>, [">= 1.2.21"])
|
68
|
+
s.add_runtime_dependency(%q<haml>, [">= 2.2.20"])
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<sinatra>, [">= 1.0.0"])
|
71
|
+
s.add_dependency(%q<less>, [">= 1.2.21"])
|
72
|
+
s.add_dependency(%q<haml>, [">= 2.2.20"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<sinatra>, [">= 1.0.0"])
|
76
|
+
s.add_dependency(%q<less>, [">= 1.2.21"])
|
77
|
+
s.add_dependency(%q<haml>, [">= 2.2.20"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/hydegen.gemspec
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{hyde}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["rstacruz"]
|
12
|
+
s.date = %q{2010-04-26}
|
13
|
+
s.default_executable = %q{hyde}
|
14
|
+
s.description = %q{Website preprocessor}
|
15
|
+
s.email = %q{rico@sinefunc.com}
|
16
|
+
s.executables = ["hyde"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"hyde.gemspec"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/sinefunc/hyde}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.6}
|
33
|
+
s.summary = %q{Website preprocessor}
|
34
|
+
s.test_files = [
|
35
|
+
"test/helper.rb",
|
36
|
+
"test/test_hyde.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
|
45
|
+
s.add_runtime_dependency(%q<less>, [">= 1.2.21"])
|
46
|
+
s.add_runtime_dependency(%q<haml>, [">= 2.2.20"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<sinatra>, [">= 1.0.0"])
|
49
|
+
s.add_dependency(%q<less>, [">= 1.2.21"])
|
50
|
+
s.add_dependency(%q<haml>, [">= 2.2.20"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<sinatra>, [">= 1.0.0"])
|
54
|
+
s.add_dependency(%q<less>, [">= 1.2.21"])
|
55
|
+
s.add_dependency(%q<haml>, [">= 2.2.20"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/lib/hyde/init.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
$:.unshift File.dirname(__FILE__) + "/.."
|
6
|
+
require 'hyde'
|
7
|
+
|
8
|
+
class Main < Sinatra::Base
|
9
|
+
configure do
|
10
|
+
# $log = Logger.new(File.join('log', "#{Sinatra::Application.environment}.log"))
|
11
|
+
end
|
12
|
+
|
13
|
+
get '/*' do
|
14
|
+
begin
|
15
|
+
@project ||= Hyde::Project.new
|
16
|
+
@project.render params[:splat].to_s
|
17
|
+
rescue Hyde::NotFound
|
18
|
+
raise Sinatra::NotFound
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Main.run!
|
data/lib/hyde/layout.rb
ADDED
data/lib/hyde/ostruct.rb
ADDED
data/lib/hyde/page.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
module Hyde
|
2
|
+
class Page
|
3
|
+
attr :filename, :renderer, :meta,
|
4
|
+
:page, :layout, :project
|
5
|
+
|
6
|
+
attr_accessor :filename
|
7
|
+
attr_accessor :meta
|
8
|
+
attr_accessor :data
|
9
|
+
attr_accessor :name
|
10
|
+
|
11
|
+
attr_reader :project
|
12
|
+
|
13
|
+
# Constructor.
|
14
|
+
#
|
15
|
+
# The `page` argument is a page name
|
16
|
+
#
|
17
|
+
def initialize( page, project )
|
18
|
+
@project = project
|
19
|
+
@name ||= page
|
20
|
+
@meta ||= {}
|
21
|
+
|
22
|
+
renderer = nil
|
23
|
+
|
24
|
+
info = get_page_info(self, @project)
|
25
|
+
@filename = info[:filename]
|
26
|
+
@renderer = info[:renderer]
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns the rendered output.
|
30
|
+
def render( data = {} )
|
31
|
+
output = @renderer.render(@meta.merge data)
|
32
|
+
unless @layout.nil?
|
33
|
+
hash = @meta.merge({ "content" => output })
|
34
|
+
output = @layout.render hash
|
35
|
+
end
|
36
|
+
output
|
37
|
+
end
|
38
|
+
|
39
|
+
# Sets the meta data as read from the file.
|
40
|
+
#
|
41
|
+
# Params:
|
42
|
+
# meta - The metadata Hash.
|
43
|
+
#
|
44
|
+
# Called by Renderer::Base.
|
45
|
+
#
|
46
|
+
def set_meta( meta )
|
47
|
+
# Merge
|
48
|
+
@meta ||= Hash.new
|
49
|
+
@meta.merge! meta
|
50
|
+
|
51
|
+
# Set the Layout
|
52
|
+
@layout = Layout.new(@meta['layout'], @project) if @meta['layout']
|
53
|
+
end
|
54
|
+
|
55
|
+
protected
|
56
|
+
def get_page_info(page, project)
|
57
|
+
renderer = nil
|
58
|
+
filename = "#{project.root}/#{page.name}"
|
59
|
+
|
60
|
+
if File.exists? filename
|
61
|
+
renderer = Hyde::Renderer::Passthru
|
62
|
+
|
63
|
+
else
|
64
|
+
# Look for the file
|
65
|
+
matches = Dir["#{project.root}/#{page.name}.*"]
|
66
|
+
raise NotFound.new("Can't find `#{page.name}` or `#{page.name}.*`") \
|
67
|
+
if matches.empty?
|
68
|
+
|
69
|
+
# Check for a matching renderer
|
70
|
+
exts = []
|
71
|
+
matches.each do |match|
|
72
|
+
begin
|
73
|
+
ext = File.extname(match)[1..-1].capitalize.to_sym
|
74
|
+
r_class = Hyde::Renderers.const_get(ext)
|
75
|
+
exts << ext
|
76
|
+
renderer ||= r_class
|
77
|
+
filename = match
|
78
|
+
rescue NoMethodError; end
|
79
|
+
end
|
80
|
+
|
81
|
+
raise NotFound.new("No matching renderers found: " + exts.inspect) \
|
82
|
+
if renderer.nil?
|
83
|
+
end
|
84
|
+
|
85
|
+
{ :renderer => renderer.new(page, filename),
|
86
|
+
:filename => filename
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/hyde/project.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
module Hyde
|
2
|
+
class Project
|
3
|
+
|
4
|
+
# The root path (String).
|
5
|
+
# root
|
6
|
+
# root :layouts
|
7
|
+
# root :site, 'blah'
|
8
|
+
def root(*args)
|
9
|
+
where = ''
|
10
|
+
where = send("#{args.shift.to_s}_path") if args[0].class == Symbol
|
11
|
+
path = args
|
12
|
+
File.join [@root, where, path].reject(&:empty?)
|
13
|
+
end
|
14
|
+
|
15
|
+
# The filename of the configuration file, relative to the project root.
|
16
|
+
attr :config_file
|
17
|
+
|
18
|
+
# The configuration k/v storage (Hash)
|
19
|
+
attr_accessor :config
|
20
|
+
|
21
|
+
def initialize( root = Dir.pwd )
|
22
|
+
@root = root
|
23
|
+
@config_file ||= "#{@root}/_config.yml"
|
24
|
+
|
25
|
+
@config = OStruct.new defaults
|
26
|
+
@config.merge! YAML::load_file(@config_file) if File.exists? @config_file
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(meth, *args, &blk)
|
30
|
+
@config.send meth
|
31
|
+
end
|
32
|
+
|
33
|
+
# Can throw a NotFound.
|
34
|
+
def render( pathname )
|
35
|
+
pathname = "index.html" if pathname.empty?
|
36
|
+
page = Page.new pathname, self
|
37
|
+
page.render
|
38
|
+
end
|
39
|
+
|
40
|
+
def build
|
41
|
+
# Can error
|
42
|
+
Dir.mkdir @site_root unless File.exists? @site_root
|
43
|
+
files.each do |file|
|
44
|
+
output = File.join(root, site_path, file)
|
45
|
+
# mkdir and open output
|
46
|
+
# render file
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns a list of all URLs
|
51
|
+
def files
|
52
|
+
@file_list ||= Dir[File.join(root, '**', '*')].inject([]) do |a, match|
|
53
|
+
# Make sure its the canonical name
|
54
|
+
path = File.expand_path(match)
|
55
|
+
file = path.gsub /^#{Regexp.escape root}\/?/, ''
|
56
|
+
ext = File.extname(file)[1..-1]
|
57
|
+
|
58
|
+
ignore_list = [
|
59
|
+
root(:layouts, '**/*'),
|
60
|
+
root(:extensions, '**/*'),
|
61
|
+
root(:output, '**/*'),
|
62
|
+
@config_file
|
63
|
+
]
|
64
|
+
|
65
|
+
ignore_files = ignore_list.inject([]) { |a, spec|
|
66
|
+
Dir[spec].each { |file| a << File.expand_path(file) }; a
|
67
|
+
}
|
68
|
+
|
69
|
+
if ignore_files.include?(path) or Dir.exists?(match)
|
70
|
+
# pass
|
71
|
+
elsif not get_renderer(ext).nil? # Has a renderer associated
|
72
|
+
a << file.chomp(".#{ext}")
|
73
|
+
else
|
74
|
+
a << file
|
75
|
+
end
|
76
|
+
a
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
def defaults
|
82
|
+
{ 'layouts_path' => '_layouts',
|
83
|
+
'extensions_path' => '_extensions',
|
84
|
+
'site_path' => '_site',
|
85
|
+
'output_path' => '_output'
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_renderer(name)
|
90
|
+
begin
|
91
|
+
class_name = name.to_s.capitalize.to_sym
|
92
|
+
renderer = Renderers.const_get(class_name)
|
93
|
+
rescue NameError
|
94
|
+
renderer = nil
|
95
|
+
end
|
96
|
+
renderer
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
3
|
+
module Hyde
|
4
|
+
module Renderer
|
5
|
+
class Base
|
6
|
+
attr_reader :meta
|
7
|
+
attr_reader :page
|
8
|
+
|
9
|
+
def initialize( page, filename )
|
10
|
+
@meta = {}
|
11
|
+
@page = page
|
12
|
+
@filename = filename
|
13
|
+
end
|
14
|
+
|
15
|
+
def render( data = {} )
|
16
|
+
""
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Any filetype that is split with the -- separator
|
21
|
+
class Parsable < Base
|
22
|
+
@markup = ""
|
23
|
+
|
24
|
+
def initialize(page, filename)
|
25
|
+
super page, filename
|
26
|
+
|
27
|
+
# Parse out the file's metadata and markup contents
|
28
|
+
parts = get_file_parts filename, :max_parts => 2
|
29
|
+
if parts.length == 1
|
30
|
+
# If it doesn't come with a header, assume the whole file is the data
|
31
|
+
@markup = parts[0]
|
32
|
+
else
|
33
|
+
@markup = parts[1]
|
34
|
+
page.set_meta YAML::load("--- " + parts[0])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def get_file_parts(filename, *args)
|
40
|
+
options = { :max_parts => -1 }
|
41
|
+
args.each_pair { |k, v| options[k] = v } if args.is_a? Hash
|
42
|
+
|
43
|
+
data = [""]
|
44
|
+
i = 0 # Current part number
|
45
|
+
File.open(filename, "r").each_line do |line|
|
46
|
+
if ((line.strip == "--") and
|
47
|
+
((i <= options[:max_parts]) or (options[:max_parts] == -1)))
|
48
|
+
data[i+=1] = ""
|
49
|
+
else
|
50
|
+
data[i] << line
|
51
|
+
end
|
52
|
+
end
|
53
|
+
data
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Passthru < Base
|
58
|
+
def render( data = {} )
|
59
|
+
data = ""
|
60
|
+
File.open(@page.filename, "r").each_line { |line| data << line }
|
61
|
+
data
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'haml'
|
2
|
+
|
3
|
+
module Hyde
|
4
|
+
module Renderers
|
5
|
+
class Haml < Renderer::Parsable
|
6
|
+
def render( data = {} )
|
7
|
+
@engine = ::Haml::Engine.new(@markup, {})
|
8
|
+
|
9
|
+
if data.is_a? Hash
|
10
|
+
@engine.render OpenStruct.new data
|
11
|
+
else
|
12
|
+
@engine.render data
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/hyde/utils.rb
ADDED
data/lib/hyde.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Hyde
|
4
|
+
prefix = File.dirname(__FILE__)
|
5
|
+
autoload :OStruct, "#{prefix}/hyde/ostruct"
|
6
|
+
autoload :Project, "#{prefix}/hyde/project"
|
7
|
+
autoload :Layout, "#{prefix}/hyde/layout"
|
8
|
+
autoload :Page, "#{prefix}/hyde/page"
|
9
|
+
autoload :Renderer, "#{prefix}/hyde/renderer"
|
10
|
+
autoload :Renderers, "#{prefix}/hyde/renderers"
|
11
|
+
autoload :Utils, "#{prefix}/hyde/utils"
|
12
|
+
|
13
|
+
class NotFound < Exception
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'contest'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
require 'hyde'
|
8
|
+
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
include Hyde::Utils
|
11
|
+
|
12
|
+
def setup(site = 'default')
|
13
|
+
@project = get_project site
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_project(site)
|
17
|
+
Hyde::Project.new fixture(site)
|
18
|
+
end
|
19
|
+
|
20
|
+
def fixture(site)
|
21
|
+
File.join File.dirname(__FILE__), 'fixtures', site
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_same_file(a, b)
|
25
|
+
assert same_file?(a, b)
|
26
|
+
end
|
27
|
+
end
|
data/test/test_hyde.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestHyde < Test::Unit::TestCase
|
4
|
+
should "return the right paths" do
|
5
|
+
root_path = fixture 'default'
|
6
|
+
assert_same_file root_path, @project.root
|
7
|
+
assert_same_file File.join(root_path, '_layouts'), \
|
8
|
+
@project.root(:layouts)
|
9
|
+
assert_same_file File.join(root_path, '_layouts', 'abc'), \
|
10
|
+
@project.root(:layouts, 'abc')
|
11
|
+
assert_same_file File.join(root_path, 'layouts', 'abc'), \
|
12
|
+
@project.root('layouts', 'abc')
|
13
|
+
end
|
14
|
+
|
15
|
+
should "Do things" do
|
16
|
+
@project.render 'yes.html'
|
17
|
+
@project.render 'foo.html'
|
18
|
+
end
|
19
|
+
|
20
|
+
should "recognize not found" do
|
21
|
+
assert_raises Hyde::NotFound do
|
22
|
+
@project.render 'garbage.html'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
should "use layouts" do
|
27
|
+
output = @project.render 'layout_test.html'
|
28
|
+
assert_match /This is the meta title/, output
|
29
|
+
assert_match /<!-- \(default layout\) -->/, output
|
30
|
+
end
|
31
|
+
|
32
|
+
should "list the project files properly" do
|
33
|
+
files = @project.files
|
34
|
+
assert files.include? 'index.html'
|
35
|
+
assert files.include? 'about/index.html'
|
36
|
+
assert files.include? 'layout_test.html'
|
37
|
+
assert !files.include?('about')
|
38
|
+
assert !files.include?('about/')
|
39
|
+
assert !files.include?('_config.yml')
|
40
|
+
assert !files.include?('layout/default')
|
41
|
+
assert !files.include?('layout/default.haml')
|
42
|
+
assert !files.include?('layout_test.html.haml')
|
43
|
+
puts files
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hydeweb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- pre1
|
10
|
+
version: 0.0.1.pre1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Rico Sta. Cruz
|
14
|
+
- Sinefunc, Inc.
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-04-27 00:00:00 +08:00
|
20
|
+
default_executable: hyde
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: sinatra
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: less
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 2
|
46
|
+
- 21
|
47
|
+
version: 1.2.21
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: haml
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 2
|
59
|
+
- 2
|
60
|
+
- 20
|
61
|
+
version: 2.2.20
|
62
|
+
type: :runtime
|
63
|
+
version_requirements: *id003
|
64
|
+
description: Website preprocessor
|
65
|
+
email: rico@sinefunc.com
|
66
|
+
executables:
|
67
|
+
- hyde
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files:
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
files:
|
74
|
+
- .gitignore
|
75
|
+
- .yardopts
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- VERSION
|
80
|
+
- bin/hyde
|
81
|
+
- hyde.gemspec
|
82
|
+
- hydegen.gemspec
|
83
|
+
- lib/hyde.rb
|
84
|
+
- lib/hyde/init.rb
|
85
|
+
- lib/hyde/layout.rb
|
86
|
+
- lib/hyde/ostruct.rb
|
87
|
+
- lib/hyde/page.rb
|
88
|
+
- lib/hyde/project.rb
|
89
|
+
- lib/hyde/renderer.rb
|
90
|
+
- lib/hyde/renderers.rb
|
91
|
+
- lib/hyde/utils.rb
|
92
|
+
- test/fixtures/default/_config.yml
|
93
|
+
- test/fixtures/default/_layouts/default.haml
|
94
|
+
- test/fixtures/default/about/index.html
|
95
|
+
- test/fixtures/default/foo.html.haml
|
96
|
+
- test/fixtures/default/hyde
|
97
|
+
- test/fixtures/default/index.html.haml
|
98
|
+
- test/fixtures/default/layout_test.html.haml
|
99
|
+
- test/fixtures/default/yes.html
|
100
|
+
- test/helper.rb
|
101
|
+
- test/test_hyde.rb
|
102
|
+
has_rdoc: true
|
103
|
+
homepage: http://github.com/sinefunc/hyde
|
104
|
+
licenses: []
|
105
|
+
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options:
|
108
|
+
- --charset=UTF-8
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 1
|
124
|
+
- 3
|
125
|
+
- 1
|
126
|
+
version: 1.3.1
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 1.3.6
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: Website preprocessor
|
134
|
+
test_files:
|
135
|
+
- test/helper.rb
|
136
|
+
- test/test_hyde.rb
|