hydeweb 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1 +1,14 @@
1
+ v0.0.5 - 2010-xx-xx
2
+ -------------------
1
3
 
4
+ - Implemented `content_for` and `yield_content` helpers
5
+ - Added `partials_path` config variable
6
+ - Changed helper method `partial`s syntax (from `partial X, :locals => { ... }` to `partial X, ...`)
7
+ - Line numbers for errors are shown now
8
+ - Added rudimentary 404 page
9
+ - Added `hyde_requirement` config variable -- Hyde will now not proceed if the project needs a later version of Hyde
10
+ - Extensions are now auto-guessed (for example, 'foo.less' will be accessible as 'foo.css')
11
+
12
+ v0.0.4 - 2010-05-25
13
+ -------------------
14
+ - First public release
data/README.md CHANGED
@@ -19,10 +19,15 @@ To do
19
19
 
20
20
  - ignores
21
21
  - error pages
22
+ - page types
22
23
  - _meta.yml
23
24
 
24
25
  Done:
25
26
 
27
+ - default extensions
28
+ - version checking
29
+ - content_for
30
+ - partials_path
26
31
  - last_modified
27
32
  - partials support
28
33
  - hyde build
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/bin/hyde CHANGED
@@ -9,6 +9,11 @@ require 'hyde'
9
9
  # This will load the extensions
10
10
  begin
11
11
  $project = Hyde::Project.new
12
+
13
+ rescue Hyde::IncompatibleError => e
14
+ $stderr << e.message << "\n"
15
+ exit
16
+
12
17
  rescue Hyde::NoRootError; end
13
18
 
14
19
  if ARGV.size == 0
@@ -1,6 +1,8 @@
1
1
  # This is a Hyde site.
2
2
  # Install the `hydeweb` Ruby gem and type `hyde` for help.
3
3
 
4
+ hyde_requirement: 0.0.5
5
+
4
6
  # Path options
5
7
  # -------------
6
8
 
@@ -13,6 +15,9 @@ layouts_path: layouts
13
15
  # The folder where the optional extensions are kept.
14
16
  extensions_path: extensions
15
17
 
18
+ # The folder for partials.
19
+ partials_path: layouts
20
+
16
21
  # The folder where the HTML files are to be built when typing `hyde build`.
17
22
  output_path: public
18
23
 
@@ -0,0 +1,3 @@
1
+ <body style='text-align: center'>
2
+ <h1>Not found.</h1>
3
+ <a href='/-'>List of pages</a>
data/hydeweb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hydeweb}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rico Sta. Cruz", "Sinefunc, Inc."]
12
- s.date = %q{2010-05-25}
12
+ s.date = %q{2010-05-30}
13
13
  s.default_executable = %q{hyde}
14
14
  s.description = %q{Website preprocessor}
15
15
  s.email = %q{rico@sinefunc.com}
@@ -33,13 +33,14 @@ Gem::Specification.new do |s|
33
33
  "data/new_site/hyde.conf",
34
34
  "data/new_site/layouts/default.haml",
35
35
  "data/new_site/site/index.html.haml",
36
+ "data/pages/404.html",
36
37
  "hydeweb.gemspec",
37
38
  "lib/hyde.rb",
38
39
  "lib/hyde/clicommand.rb",
39
40
  "lib/hyde/clicommands.rb",
40
41
  "lib/hyde/helpers.rb",
41
- "lib/hyde/init.rb",
42
42
  "lib/hyde/layout.rb",
43
+ "lib/hyde/meta.rb",
43
44
  "lib/hyde/ostruct.rb",
44
45
  "lib/hyde/page.rb",
45
46
  "lib/hyde/page_factory.rb",
@@ -47,6 +48,7 @@ Gem::Specification.new do |s|
47
48
  "lib/hyde/project.rb",
48
49
  "lib/hyde/renderer.rb",
49
50
  "lib/hyde/renderers.rb",
51
+ "lib/hyde/sinatra/init.rb",
50
52
  "lib/hyde/utils.rb",
51
53
  "manual/Extending/ExtendingHyde.md",
52
54
  "manual/Hyde.md",
@@ -93,6 +95,15 @@ Gem::Specification.new do |s|
93
95
  "test/fixtures/default/www_control/index.html",
94
96
  "test/fixtures/default/www_control/layout_test.html",
95
97
  "test/fixtures/default/www_control/yes.html",
98
+ "test/fixtures/two/_config.yml",
99
+ "test/fixtures/two/layouts/default.haml",
100
+ "test/fixtures/two/layouts/shared/test.haml",
101
+ "test/fixtures/two/site/default.html.haml",
102
+ "test/fixtures/two/site/index.html.haml",
103
+ "test/fixtures/two/site/var.html.haml",
104
+ "test/fixtures/two/www_control/default.html",
105
+ "test/fixtures/two/www_control/index.html",
106
+ "test/fixtures/two/www_control/var.html",
96
107
  "test/helper.rb",
97
108
  "test/test_all_fixtures.rb",
98
109
  "test/test_build.rb",
data/lib/hyde.rb CHANGED
@@ -10,16 +10,17 @@ module Hyde
10
10
  autoload :Renderer, "#{prefix}/hyde/renderer"
11
11
  autoload :Renderers, "#{prefix}/hyde/renderers"
12
12
  autoload :Utils, "#{prefix}/hyde/utils"
13
- autoload :Scope, "#{prefix}/hyde/scope"
13
+ autoload :Meta, "#{prefix}/hyde/meta"
14
14
  autoload :CLICommand, "#{prefix}/hyde/clicommand"
15
15
  autoload :CLICommands, "#{prefix}/hyde/clicommands"
16
16
  autoload :Helpers, "#{prefix}/hyde/helpers"
17
17
  autoload :Partial, "#{prefix}/hyde/partial"
18
18
 
19
19
  Error = Class.new(::StandardError)
20
- NoGemError = Class.new(Error)
21
- NotFound = Class.new(Error)
22
- NoRootError = Class.new(Error)
20
+ NoGemError = Class.new(Error)
21
+ NotFound = Class.new(Error)
22
+ NoRootError = Class.new(Error)
23
+ IncompatibleError = Class.new(Error)
23
24
 
24
25
  class RenderError < Error
25
26
  attr_accessor :message
@@ -43,4 +44,8 @@ module Hyde
43
44
  def version
44
45
  @version ||= File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')) { |f| f.read.strip }
45
46
  end
47
+
48
+ def compatible_with?(given_version)
49
+ Gem::Version.new(version) >= Gem::Version.new(given_version)
50
+ end
46
51
  end
@@ -72,7 +72,7 @@ module Hyde
72
72
  desc "Starts the local webserver"
73
73
  def self.run(*a)
74
74
  project
75
- system "ruby \"%s\"" % [File.join(lib_path, 'hyde', 'init.rb')]
75
+ system "ruby \"%s\"" % [File.join(lib_path, 'hyde', 'sinatra', 'init.rb')]
76
76
  end
77
77
 
78
78
  def self.help
data/lib/hyde/helpers.rb CHANGED
@@ -1,15 +1,42 @@
1
1
  module Hyde
2
2
  module Helpers
3
- module Default
4
- def render_partial(partial_path, args = {})
5
- locals = args[:locals] || {}
6
- p = Partial.create partial_path.to_s, project
3
+ def partial(partial_path, locals = {})
4
+ begin
5
+ p = project[partial_path.to_s, :Partial]
6
+ p.referrer = self.referrer
7
7
  p.render locals
8
+ rescue ::Hyde::NotFound
9
+ "<!-- Can't find #{partial_path.to_s} -->"
8
10
  end
11
+ end
12
+
13
+ def content_for(key, &block)
14
+ content_blocks[key.to_sym] = block
15
+ end
16
+
17
+ def has_content?(key)
18
+ content_blocks.keys.include? key.to_sym
19
+ end
20
+
21
+ def yield_content(key, *args)
22
+ block = content_blocks[key.to_sym]
23
+ return '' if block.nil?
9
24
 
10
- def partial(*a)
11
- render_partial *a
25
+ if respond_to?(:block_is_haml?) && block_is_haml?(block)
26
+ capture_haml *args, &block
27
+ elsif block.is_a? Proc
28
+ block.call *args
29
+ elsif block_given?
30
+ yield
31
+ else
32
+ ''
12
33
  end
13
34
  end
35
+
36
+ protected
37
+ def content_blocks
38
+ @@content_blocks ||= Hash.new
39
+ @@content_blocks[referrer.to_sym] ||= Hash.new { |h, k| h[k] = [] }
40
+ end
14
41
  end
15
42
  end
data/lib/hyde/layout.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  module Hyde
2
2
  class Layout < Page
3
- def self.create(path, project, page_class = Layout)
4
- super path, project, page_class
5
- end
6
-
7
3
  def self.get_filename(path, project)
8
4
  project.root(:layouts, path)
9
5
  end
data/lib/hyde/meta.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Hyde
2
+ class Meta < OStruct
3
+ attr_reader :page
4
+
5
+ def initialize(page)
6
+ @page = page
7
+ super nil
8
+ end
9
+
10
+ def |(data)
11
+ # TODO: Consider OStruct here?
12
+ @table.merge data #if data.is_a? Hash
13
+ end
14
+
15
+ def layout=(value)
16
+ super value
17
+ @page.layout = @page.project[value, :Layout]
18
+ @page.layout.referrer = page.referrer
19
+ end
20
+ end
21
+ end
data/lib/hyde/ostruct.rb CHANGED
@@ -3,16 +3,11 @@ require 'ostruct'
3
3
  module Hyde
4
4
  class OStruct < OpenStruct
5
5
  def merge!(hash)
6
- hash.each_pair { |k, v| self.set!(k, v) }
6
+ hash.each_pair { |key, value| self.send "#{key.to_s}=".to_sym, value }
7
7
  end
8
8
 
9
9
  def include?(key)
10
10
  @table.keys.include? key
11
11
  end
12
-
13
- protected
14
- def set!(key, value)
15
- self.send "#{key.to_s}=".to_sym, value
16
- end
17
12
  end
18
13
  end
data/lib/hyde/page.rb CHANGED
@@ -2,20 +2,17 @@ module Hyde
2
2
  class Page
3
3
  include Hyde::Utils
4
4
 
5
- attr :filename
6
5
  attr :renderer
7
- attr :meta
8
- attr :page
9
- attr :layout
10
- attr :project
11
6
 
12
7
  # The filename of the source file.
8
+ #
13
9
  # @example
14
10
  # puts page.name
15
11
  # puts page.filename
16
12
  #
17
13
  # # about/index.html
18
14
  # # about/index.html.haml
15
+ #
19
16
  attr_accessor :filename
20
17
 
21
18
  # Metadata hash
@@ -28,55 +25,42 @@ module Hyde
28
25
  # A reference to the parent {Project} instance
29
26
  attr_reader :project
30
27
 
28
+ attr_accessor :layout
29
+
30
+ attr_writer :referrer
31
+
31
32
  # Factory
32
33
  #
33
- def self.create(path, project, def_page_class = Page)
34
+ def self.[](path, project, def_page_class = Page)
34
35
  PageFactory.create path, project, def_page_class
35
36
  end
36
37
 
38
+ def referrer
39
+ @referrer.nil? ? name : @referrer
40
+ end
41
+
37
42
  # Returns the rendered output.
38
43
  def render(data = {}, &block)
44
+ data = @meta | data
39
45
  output = @renderer.render(data, &block)
40
- # BUG: @layout should build on top of that data
41
- output = @layout.render(@meta.merge data) { output } unless @layout.nil?
46
+ output = @layout.render(data) { output } unless @layout.nil?
42
47
  output
43
48
  end
44
49
 
45
- def method_missing(meth, *args, &blk)
46
- meta[meth.to_s] || meta[meth.to_sym] || super
47
- end
48
-
49
- def get_binding
50
+ def get_binding #(&blk)
50
51
  binding
51
52
  end
52
53
 
53
- # Sets the meta data as read from the file.
54
- #
55
- # Params:
56
- # meta - The metadata Hash.
57
- #
58
- # Called by Renderer::Base.
59
- #
60
- def set_meta(meta)
61
- # TODO: OStruct and stuff
62
- # Merge
63
- @meta ||= Hash.new
64
- @meta.merge! meta
65
-
66
- # Set the Layout
67
- @layout = Layout.create(@meta['layout'], @project) if @meta['layout']
68
- end
69
-
70
54
  protected
71
55
 
72
56
  # Constructor.
73
57
  # The `page` argument is a page name
74
- # Don't use me: use {Project#create}
58
+ # Don't use me: use {Project#[]}
75
59
  #
76
60
  def initialize(path, project, renderer, filename)
77
61
  @project = project
78
62
  @name ||= path
79
- @meta ||= {}
63
+ @meta ||= Meta.new self
80
64
  @filename = filename
81
65
  @renderer = renderer.new(self, filename)
82
66
  end
@@ -1,12 +1,15 @@
1
1
  module Hyde
2
2
  class PageFactory
3
3
  def self.create(path, project, def_page_class = Page)
4
+ ext = File.extname(path)
4
5
  begin
5
6
  do_create path, project, def_page_class
6
7
  rescue NotFound
7
- do_create "#{path}/index.html".squeeze('/'), project, def_page_class
8
- rescue NotFound => e
9
- raise e
8
+ begin
9
+ do_create "#{path.chomp(ext)}", project, def_page_class
10
+ rescue NotFound
11
+ do_create "#{path}/index.html".squeeze('/'), project, def_page_class
12
+ end
10
13
  end
11
14
  end
12
15
 
data/lib/hyde/partial.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Hyde
2
2
  class Partial < Layout
3
- def self.create(path, project, page_class = Partial)
4
- super path, project, page_class
3
+ def self.get_filename(path, project)
4
+ project.root(:partials, path)
5
5
  end
6
6
  end
7
7
  end
data/lib/hyde/project.rb CHANGED
@@ -3,6 +3,14 @@ module Hyde
3
3
  class Project
4
4
  include Hyde::Utils
5
5
 
6
+ # The filename of the configuration file, relative to the project root. (String)
7
+ #
8
+ attr :config_file
9
+
10
+ # The configuration k/v storage (OStruct)
11
+ #
12
+ attr_accessor :config
13
+
6
14
  # The root path (String).
7
15
  #
8
16
  # @example
@@ -12,51 +20,37 @@ module Hyde
12
20
  #
13
21
  def root(*args)
14
22
  where = ''
15
- where = send("#{args.shift.to_s}_path") if args[0].class == Symbol
23
+ where = @config.send("#{args.shift.to_s}_path") if args[0].class == Symbol
16
24
  path = args
17
25
  File.expand_path(File.join [@root, where, path].reject(&:empty?))
18
26
  end
19
27
 
20
- # The filename of the configuration file, relative to the project root. (String)
21
- #
22
- attr :config_file
23
-
24
- # The configuration k/v storage (OStruct)
25
- #
26
- attr_accessor :config
27
-
28
28
  # Can raise a NoRootError
29
29
  #
30
30
  def initialize(root = Dir.pwd)
31
31
  @config = OStruct.new defaults
32
32
  @root, @config_file = find_root_from root
33
- @config.merge! YAML::load_file(@config_file) if File.exists? @config_file
34
- load_extensions
35
- end
33
+ @config.merge! YAML::load_file(@config_file)
36
34
 
37
- def method_missing(meth, *args, &blk)
38
- super unless @config.include?(meth)
39
- @config.send meth
40
- end
35
+ # Check for version
36
+ raise IncompatibleError, "This project requires at least Hyde v#{@config.hyde_requirement}." \
37
+ unless @config.hyde_requirement.nil? or \
38
+ ::Hyde.compatible_with?(@config.hyde_requirement)
41
39
 
42
- # Returns a page in a certain URL path.
43
- # @return {Page} or a subclass of it
44
- #
45
- def get_page(path)
46
- Page.create path, self
40
+ load_extensions
47
41
  end
48
42
 
49
- # Returns a layout
50
- # (Try Layout.create path, @project instead)
43
+ # Returns an object in the project.
44
+ # Can be a page, layout, template...
51
45
  #
52
- def get_layout(path)
53
- Layout.create path, self
54
- end
55
-
56
- # Can throw a NotFound.
46
+ # @example
47
+ # @project['index.html']
48
+ # @project['default', :Layout]
49
+ # @project['widgets/sidebar', :Partial]
57
50
  #
58
- def render(path)
59
- Page.create(path, self).render
51
+ def [](name, default_class=Page)
52
+ default_class = ::Hyde.const_get(default_class) if default_class.is_a? Symbol
53
+ Hyde::Page[name, self, default_class]
60
54
  end
61
55
 
62
56
  # Writes the output files.
@@ -64,21 +58,25 @@ module Hyde
64
58
  # ostream - (Stream) Where to send the messages
65
59
  #
66
60
  def build(ostream = nil)
67
- raise Errno::EEXISTS if File.exists? root(:output) and not File.directory? root(:output)
68
- Dir.mkdir(root :output) unless File.directory?(root :output)
61
+ if File.exists? root(:output)
62
+ raise Errno::EEXISTS unless File.directory? root(:output)
63
+ else
64
+ Dir.mkdir root(:output)
65
+ end
69
66
 
70
67
  begin
71
68
  files.each do |path|
72
- ostream << " * #{output_path}/#{path}\n" if ostream
69
+ ostream << " * #{@config.output_path}/#{path}\n" if ostream
70
+
73
71
  begin
74
- rendered = render(path)
75
- mfile = force_file_open(root(:output, path))
76
- mfile << rendered
77
- mfile.close
72
+ rendered = self[path].render
73
+ force_file_open(root(:output, path)) { |file| file << rendered }
74
+
78
75
  rescue RenderError => e
79
76
  ostream << " *** Error: #{e.to_s}".gsub("\n", "\n *** ") << "\n"
80
77
  end
81
78
  end
79
+
82
80
  rescue NoGemError => e
83
81
  ostream << " *** Error: #{e.message}\n"
84
82
  end
@@ -96,7 +94,9 @@ module Hyde
96
94
  if ignored_files.include?(path) or File.directory?(match)
97
95
  # pass
98
96
  elsif not get_renderer(ext).nil? # Has a renderer associated
99
- a << file.chomp(".#{ext}")
97
+ fname = file.chomp(".#{ext}")
98
+ fname += get_renderer(ext).default_ext unless File.basename(fname).include?('.')
99
+ a << fname
100
100
  else
101
101
  a << file
102
102
  end
@@ -112,8 +112,9 @@ module Hyde
112
112
  root(:layouts, '**/*'),
113
113
  root(:extensions, '**/*'),
114
114
  root(:output, '**/*'),
115
+ root(:partials, '**/*'),
115
116
  @config_file
116
- ]
117
+ ].uniq
117
118
  end
118
119
 
119
120
  # Returns a list of ignored files based on the {ignore_list}.
@@ -175,6 +176,7 @@ module Hyde
175
176
  def defaults
176
177
  { 'layouts_path' => 'layouts',
177
178
  'extensions_path' => 'extensions',
179
+ 'partials_path' => 'layouts',
178
180
  'site_path' => 'site',
179
181
  'output_path' => 'public',
180
182
  'gems' => []
data/lib/hyde/renderer.rb CHANGED
@@ -17,7 +17,7 @@ module Hyde
17
17
  end
18
18
 
19
19
  def render(data, &block)
20
- scope = build_scope(page, data)
20
+ scope = build_scope(page, data, &block)
21
21
  evaluate scope, data, &block
22
22
  end
23
23
 
@@ -26,7 +26,11 @@ module Hyde
26
26
  @markup
27
27
  end
28
28
 
29
- protected
29
+ def self.default_ext
30
+ ''
31
+ end
32
+
33
+ protected
30
34
  def require_lib(lib, gem=lib)
31
35
  begin
32
36
  require lib
@@ -37,21 +41,18 @@ module Hyde
37
41
  end
38
42
  end
39
43
 
40
- def build_scope(page, data)
44
+ def build_scope(page, data, &block)
41
45
  # Page is the scope
42
- scope = page.get_binding
46
+ scope = page.get_binding &block
43
47
  scope_object = eval("self", scope)
44
48
 
45
49
  # Inherit local vars
46
- scope_object.send(:instance_variable_set, '@_locals', data)
47
- f_set_locals = data.keys.map { |k| "#{k} = @_locals[#{k.inspect}];" }.join("\n")
50
+ data_object = data.inject({}) { |a, i| a[i[0].to_s] = i[1]; a }
51
+ scope_object.send(:instance_variable_set, '@_locals', data_object)
52
+ f_set_locals = data_object.keys.map { |k| "#{k} = @_locals[#{k.inspect}];" }.join("\n")
48
53
  eval(f_set_locals, scope)
49
54
 
50
55
  scope_object.instance_eval do
51
- def eval_block(src, &block)
52
- # This will let you eval something, and `yield` within that block.
53
- eval src, &block
54
- end
55
56
  get_helpers.each { |helper_class| extend helper_class }
56
57
  end
57
58
 
@@ -66,6 +67,10 @@ module Hyde
66
67
 
67
68
  # Any filetype that is split with the -- separator
68
69
  class Parsable < Base
70
+ def self.default_ext
71
+ '.html'
72
+ end
73
+
69
74
  def initialize(page, filename)
70
75
  super page, filename
71
76
 
@@ -76,7 +81,7 @@ module Hyde
76
81
  @markup = parts[0]
77
82
  else
78
83
  @markup = parts[1]
79
- page.set_meta YAML::load("--- " + parts[0])
84
+ page.meta.merge! YAML::load("--- " + parts[0])
80
85
  end
81
86
  end
82
87
 
@@ -16,11 +16,15 @@ module Hyde
16
16
  def evaluate(scope, data={}, &block)
17
17
  require_lib 'erb'
18
18
  @engine = ::ERB.new markup
19
- eval("self", scope).eval_block @engine.src, &block
19
+ eval @engine.src, scope
20
20
  end
21
21
  end
22
22
 
23
23
  class Less < Renderer::Base
24
+ def self.default_ext
25
+ '.css'
26
+ end
27
+
24
28
  def evaluate(scope, data={}, &block)
25
29
  require_lib 'less'
26
30
  begin
@@ -50,6 +54,10 @@ module Hyde
50
54
  end
51
55
 
52
56
  class Textile < Renderer::Parsable
57
+ def self.default_ext
58
+ '.css'
59
+ end
60
+
53
61
  def evaluate(s, d={}, &block)
54
62
  require_lib 'redcloth', 'RedCloth'
55
63
  RedCloth.new(markup).to_html
@@ -6,7 +6,7 @@ rescue LoadError
6
6
  exit
7
7
  end
8
8
 
9
- $:.unshift File.dirname(__FILE__) + "/.."
9
+ $:.unshift File.dirname(__FILE__) + "/../.."
10
10
  require 'hyde'
11
11
 
12
12
  $project = Hyde::Project.new
@@ -34,7 +34,7 @@ class Main < Sinatra::Base
34
34
  type = File.extname(path)[1..-1]
35
35
  content_type type.to_sym if type.is_a? String
36
36
 
37
- page = Hyde::Page.create path, @@project
37
+ page = @@project[path]
38
38
 
39
39
  # Send the last modified time
40
40
  last_modified File.mtime(page.filename)
@@ -43,15 +43,19 @@ class Main < Sinatra::Base
43
43
  page.render
44
44
 
45
45
  rescue Hyde::RenderError => e
46
- puts " * `#{path}` error"
46
+ puts " * `#{path}` line #{e.line} error"
47
47
  puts " *** #{e.message}".gsub("\n","\n *** ")
48
48
  e.message
49
49
 
50
50
  rescue Hyde::NotFound
51
51
  raise Sinatra::NotFound
52
-
53
52
  end
54
53
  end
54
+
55
+ not_found do
56
+ html_path = File.join(File.dirname(__FILE__), %w[.. .. .. data pages 404.html])
57
+ File.open(html_path) { |f| f.read } + (" "*4096)
58
+ end
55
59
  end
56
60
 
57
61
  Main.show_start
data/lib/hyde/utils.rb CHANGED
@@ -10,15 +10,20 @@ module Hyde
10
10
  end
11
11
  end
12
12
 
13
- def force_file_open(filepath)
13
+ def force_file_open(filepath, &blk)
14
14
  require 'fileutils'
15
15
  FileUtils.mkdir_p File.dirname(filepath)
16
- File.new filepath, 'w'
16
+
17
+ if block_given?
18
+ File.open filepath, 'w', &blk
19
+ else
20
+ File.new filepath, 'w'
21
+ end
17
22
  end
18
23
 
19
24
  # Returns all helper classes under the Hyde::Helpers module.
20
25
  def get_helpers
21
- Hyde::Helpers.constants.inject([]) do |a, constant|
26
+ Hyde::Helpers.constants.inject([Hyde::Helpers]) do |a, constant|
22
27
  mod = Hyde::Helpers.const_get(constant)
23
28
  a << mod if mod.is_a? Module
24
29
  a
@@ -4,5 +4,5 @@ title: Site
4
4
  != "<!-- (default layout) -->"
5
5
  %h2 Template
6
6
  %div
7
- =render_partial 'shared/sidebar'
7
+ =partial 'shared/sidebar'
8
8
  =yield
@@ -0,0 +1,8 @@
1
+ ---
2
+ layouts_path: layouts
3
+ extensions_path: extensions
4
+ site_path: site
5
+ output_path: www
6
+ ignore:
7
+ - hyde
8
+ - _*
@@ -0,0 +1,4 @@
1
+ title: Default
2
+ --
3
+ %title= title
4
+ = yield
@@ -0,0 +1,4 @@
1
+ custom: "partial"
2
+ --
3
+ .partial
4
+ = custom
@@ -0,0 +1,2 @@
1
+ layout: default
2
+ --
@@ -0,0 +1,9 @@
1
+ layout: default
2
+ title: Index
3
+ --
4
+ Hello
5
+
6
+ %h3 Partial
7
+ = partial 'shared/test'
8
+ = partial 'shared/test', :custom => 'yip'
9
+ / End
@@ -0,0 +1,5 @@
1
+ var1: one
2
+ var2: two
3
+ --
4
+ = var1
5
+ = var2
@@ -0,0 +1,2 @@
1
+ <title>Default</title>
2
+
@@ -0,0 +1,10 @@
1
+ <title>Index</title>
2
+ Hello
3
+ <h3>Partial</h3>
4
+ <div class='partial'>
5
+ partial
6
+ </div>
7
+ <div class='partial'>
8
+ yip
9
+ </div>
10
+ <!-- End -->
@@ -0,0 +1,2 @@
1
+ one
2
+ two
data/test/helper.rb CHANGED
@@ -20,3 +20,12 @@ class Test::Unit::TestCase
20
20
  File.join File.dirname(__FILE__), 'fixtures', site
21
21
  end
22
22
  end
23
+
24
+ module Hyde
25
+ class Project
26
+ # Can throw a NotFound. Get rid of this!
27
+ def render(path)
28
+ self[path].render
29
+ end
30
+ end
31
+ end
data/test/test_hyde.rb CHANGED
@@ -36,26 +36,26 @@ class TestHyde < Test::Unit::TestCase
36
36
  end
37
37
 
38
38
  should "use layouts" do
39
- output = @project.render 'layout_test.html'
39
+ output = @project['layout_test.html'].render
40
40
  assert_match /This is the meta title/, output
41
41
  assert_match /<!-- \(default layout\) -->/, output
42
42
  end
43
43
 
44
44
  should "account for index.html" do
45
- home_output = @project.render('index.html')
46
- assert_equal home_output, @project.render('/')
47
- assert_equal home_output, @project.render('/index.html')
45
+ home_output = @project['index.html'].render
46
+ assert_equal home_output, @project['/'].render
47
+ assert_equal home_output, @project['/index.html'].render
48
48
 
49
- about_output = @project.render('/about/index.html')
50
- assert_equal about_output, @project.render('/about')
51
- assert_equal about_output, @project.render('/about/')
49
+ about_output = @project['/about/index.html'].render
50
+ assert_equal about_output, @project['/about'].render
51
+ assert_equal about_output, @project['/about/'].render
52
52
  end
53
53
 
54
54
  should "get types right" do
55
- page = @project.get_page('index.html')
55
+ page = @project['index.html']
56
56
  assert page.is_a? Hyde::Page
57
57
 
58
- layout = Hyde::Layout.create 'default', @project
58
+ layout = @project['default', Hyde::Layout]
59
59
  assert layout.is_a? Hyde::Layout
60
60
  assert layout.is_a? Hyde::Page
61
61
  end
data/test/test_page.rb CHANGED
@@ -3,7 +3,7 @@ require 'helper'
3
3
  class TestPage < Test::Unit::TestCase
4
4
  def setup(site = 'default')
5
5
  @project = get_project site
6
- @page = @project.get_page 'index.html'
6
+ @page = Hyde::Page['index.html', @project]
7
7
  end
8
8
 
9
9
  should "raise a method missing error" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rico Sta. Cruz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-25 00:00:00 +08:00
18
+ date: 2010-05-30 00:00:00 +08:00
19
19
  default_executable: hyde
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -84,13 +84,14 @@ files:
84
84
  - data/new_site/hyde.conf
85
85
  - data/new_site/layouts/default.haml
86
86
  - data/new_site/site/index.html.haml
87
+ - data/pages/404.html
87
88
  - hydeweb.gemspec
88
89
  - lib/hyde.rb
89
90
  - lib/hyde/clicommand.rb
90
91
  - lib/hyde/clicommands.rb
91
92
  - lib/hyde/helpers.rb
92
- - lib/hyde/init.rb
93
93
  - lib/hyde/layout.rb
94
+ - lib/hyde/meta.rb
94
95
  - lib/hyde/ostruct.rb
95
96
  - lib/hyde/page.rb
96
97
  - lib/hyde/page_factory.rb
@@ -98,6 +99,7 @@ files:
98
99
  - lib/hyde/project.rb
99
100
  - lib/hyde/renderer.rb
100
101
  - lib/hyde/renderers.rb
102
+ - lib/hyde/sinatra/init.rb
101
103
  - lib/hyde/utils.rb
102
104
  - manual/Extending/ExtendingHyde.md
103
105
  - manual/Hyde.md
@@ -144,6 +146,15 @@ files:
144
146
  - test/fixtures/default/www_control/index.html
145
147
  - test/fixtures/default/www_control/layout_test.html
146
148
  - test/fixtures/default/www_control/yes.html
149
+ - test/fixtures/two/_config.yml
150
+ - test/fixtures/two/layouts/default.haml
151
+ - test/fixtures/two/layouts/shared/test.haml
152
+ - test/fixtures/two/site/default.html.haml
153
+ - test/fixtures/two/site/index.html.haml
154
+ - test/fixtures/two/site/var.html.haml
155
+ - test/fixtures/two/www_control/default.html
156
+ - test/fixtures/two/www_control/index.html
157
+ - test/fixtures/two/www_control/var.html
147
158
  - test/helper.rb
148
159
  - test/test_all_fixtures.rb
149
160
  - test/test_build.rb