hydeweb 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGELOG +28 -1
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/data/new_site/hyde.conf +4 -0
  5. data/data/new_site/layouts/default.haml +3 -2
  6. data/hydeweb.gemspec +115 -105
  7. data/lib/hyde/clicommand.rb +2 -1
  8. data/lib/hyde/clicommands.rb +13 -2
  9. data/lib/hyde/helpers.rb +16 -9
  10. data/lib/hyde/layout.rb +5 -0
  11. data/lib/hyde/meta.rb +1 -1
  12. data/lib/hyde/page.rb +124 -7
  13. data/lib/hyde/page_factory.rb +12 -2
  14. data/lib/hyde/project.rb +17 -6
  15. data/lib/hyde/renderer.rb +17 -3
  16. data/lib/hyde/renderers.rb +45 -12
  17. data/lib/hyde/sinatra/init.rb +5 -3
  18. data/lib/hyde/utils.rb +10 -0
  19. data/lib/hyde.rb +15 -14
  20. data/lib/hyde_misc/console.rb +4 -0
  21. data/manual/Extending/ExtendingHyde.md +3 -2
  22. data/manual/Hyde.md +9 -4
  23. data/manual/Introduction/Configuration.md +67 -1
  24. data/manual/Introduction/GettingStarted.md +7 -9
  25. data/manual/Introduction/Installation.md +2 -2
  26. data/manual/Introduction/Layouts.md +11 -1
  27. data/manual/Introduction/Metadata.md +92 -0
  28. data/manual/Introduction/Partials.md +10 -0
  29. data/manual/Introduction/TemplateLanguages.md +5 -5
  30. data/manual/Tips/Tips.md +42 -0
  31. data/test/fixtures/content_for/layouts/cf-args.haml +2 -0
  32. data/test/fixtures/content_for/layouts/cf.haml +14 -0
  33. data/test/fixtures/content_for/site/cf-args-default.haml +2 -0
  34. data/test/fixtures/content_for/site/cf-args.haml +5 -0
  35. data/test/fixtures/content_for/site/cf.haml +6 -0
  36. data/test/fixtures/content_for/site/cf2.haml +3 -0
  37. data/test/fixtures/content_for/www_control/cf-args-default.html +1 -0
  38. data/test/fixtures/content_for/www_control/cf-args.html +2 -0
  39. data/test/fixtures/content_for/www_control/cf.html +17 -0
  40. data/test/fixtures/content_for/www_control/cf2.html +19 -0
  41. metadata +38 -16
  42. data/.gitignore +0 -25
  43. /data/test/fixtures/{two → content_for}/_config.yml +0 -0
  44. /data/test/fixtures/{two → content_for}/layouts/default.haml +0 -0
  45. /data/test/fixtures/{two → content_for}/layouts/shared/test.haml +0 -0
  46. /data/test/fixtures/{two → content_for}/site/default.html.haml +0 -0
  47. /data/test/fixtures/{two → content_for}/site/index.html.haml +0 -0
  48. /data/test/fixtures/{two → content_for}/site/var.html.haml +0 -0
  49. /data/test/fixtures/{two → content_for}/www_control/default.html +0 -0
  50. /data/test/fixtures/{two → content_for}/www_control/index.html +0 -0
  51. /data/test/fixtures/{two → content_for}/www_control/var.html +0 -0
data/CHANGELOG CHANGED
@@ -1,4 +1,30 @@
1
- v0.0.5 - 2010-xx-xx
1
+ v0.0.7
2
+ ------
3
+
4
+ - Add support for Sass and SCSS.
5
+ - Add support for ignored files.
6
+
7
+ v0.0.6
8
+ ------
9
+
10
+ - Added support for blocks for `yield_content` (as default text).
11
+ - `Page#referrer` now is a page (instead of a string of the name).
12
+ - Partials path is now not ignored by default.
13
+ - Add support for page ordering (by the `position` key in metadata).
14
+ - You can now start an IRB session with the `hyde console` command.
15
+ - Implement traversion methods for page: #next, #previous, #siblings,
16
+ and #parent.
17
+ - Implement the 'page' variable to be available in pages.
18
+ - Add Page#title.
19
+ - Add Page#path.
20
+ - Add Page#breadcrumbs.
21
+ - Implement Utils#escape_html.
22
+ - Hyde now always tries 'layouts/default.*' as the default layout, if none's
23
+ specified. (TODO: layout: false)
24
+ - Implement Renderer.layoutable?, which dictates if a renderer is capable of
25
+ having a layout.
26
+
27
+ v0.0.5 - 2010-05-30
2
28
  -------------------
3
29
 
4
30
  - Implemented `content_for` and `yield_content` helpers
@@ -11,4 +37,5 @@ v0.0.5 - 2010-xx-xx
11
37
 
12
38
  v0.0.4 - 2010-05-25
13
39
  -------------------
40
+
14
41
  - First public release
data/Rakefile CHANGED
@@ -45,7 +45,7 @@ Rake::RDocTask.new do |rdoc|
45
45
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
46
 
47
47
  rdoc.rdoc_dir = 'rdoc'
48
- rdoc.title = "aoeu #{version}"
48
+ rdoc.title = "Hyde #{version}"
49
49
  rdoc.rdoc_files.include('README*')
50
50
  rdoc.rdoc_files.include('lib/**/*.rb')
51
51
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.7
@@ -21,6 +21,10 @@ partials_path: layouts
21
21
  # The folder where the HTML files are to be built when typing `hyde build`.
22
22
  output_path: public
23
23
 
24
+ # Any files matching these in the site_path will be excluded.
25
+ ignore:
26
+ - **/*~
27
+
24
28
  # Put any custom gems here.
25
29
  # gems:
26
30
  # - hyde-rst
@@ -1,9 +1,10 @@
1
1
  !!!
2
2
  %html
3
3
  %head
4
- %title= title
4
+ %title= page.title
5
5
  %body
6
- =yield
6
+ #content
7
+ != yield
7
8
  %div#footer
8
9
  %hr
9
10
  %p Generated by Hyde
data/hydeweb.gemspec CHANGED
@@ -1,137 +1,147 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hydeweb}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.7"
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-30}
12
+ s.date = %q{2010-11-24}
13
13
  s.default_executable = %q{hyde}
14
14
  s.description = %q{Website preprocessor}
15
15
  s.email = %q{rico@sinefunc.com}
16
16
  s.executables = ["hyde"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
- "README.md"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
- ".gitignore",
23
- ".yardopts",
24
- "AUTHORS",
25
- "CHANGELOG",
26
- "LICENSE",
27
- "README.md",
28
- "Rakefile",
29
- "VERSION",
30
- "bin/hyde",
31
- "data/new_site/.gitignore",
32
- "data/new_site/README.md",
33
- "data/new_site/hyde.conf",
34
- "data/new_site/layouts/default.haml",
35
- "data/new_site/site/index.html.haml",
36
- "data/pages/404.html",
37
- "hydeweb.gemspec",
38
- "lib/hyde.rb",
39
- "lib/hyde/clicommand.rb",
40
- "lib/hyde/clicommands.rb",
41
- "lib/hyde/helpers.rb",
42
- "lib/hyde/layout.rb",
43
- "lib/hyde/meta.rb",
44
- "lib/hyde/ostruct.rb",
45
- "lib/hyde/page.rb",
46
- "lib/hyde/page_factory.rb",
47
- "lib/hyde/partial.rb",
48
- "lib/hyde/project.rb",
49
- "lib/hyde/renderer.rb",
50
- "lib/hyde/renderers.rb",
51
- "lib/hyde/sinatra/init.rb",
52
- "lib/hyde/utils.rb",
53
- "manual/Extending/ExtendingHyde.md",
54
- "manual/Hyde.md",
55
- "manual/Introduction/Configuration.md",
56
- "manual/Introduction/GettingStarted.md",
57
- "manual/Introduction/Installation.md",
58
- "manual/Introduction/Layouts.md",
59
- "manual/Introduction/Metadata.md",
60
- "manual/Introduction/Partials.md",
61
- "manual/Introduction/TemplateLanguages.md",
62
- "test/fixtures/custom/_config.yml",
63
- "test/fixtures/custom/extensions/custom/custom.rb",
64
- "test/fixtures/custom/layouts/default.haml",
65
- "test/fixtures/custom/layouts/erbtest.erb",
66
- "test/fixtures/custom/layouts/shared/sidebar.haml",
67
- "test/fixtures/custom/site/about/index.html",
68
- "test/fixtures/custom/site/assets/common.css.less",
69
- "test/fixtures/custom/site/assets/style.css.less",
70
- "test/fixtures/custom/site/foo.html.haml",
71
- "test/fixtures/custom/site/index.html.haml",
72
- "test/fixtures/custom/site/layout_test.html.haml",
73
- "test/fixtures/custom/site/lol.html.erb",
74
- "test/fixtures/custom/site/markdown.html.md",
75
- "test/fixtures/custom/site/yes.html",
76
- "test/fixtures/custom/www_control/about/index.html",
77
- "test/fixtures/custom/www_control/assets/common.css",
78
- "test/fixtures/custom/www_control/assets/style.css",
79
- "test/fixtures/custom/www_control/foo.html",
80
- "test/fixtures/custom/www_control/index.html",
81
- "test/fixtures/custom/www_control/layout_test.html",
82
- "test/fixtures/custom/www_control/lol.html",
83
- "test/fixtures/custom/www_control/markdown.html",
84
- "test/fixtures/custom/www_control/yes.html",
85
- "test/fixtures/default/_config.yml",
86
- "test/fixtures/default/extensions/custom/custom.rb",
87
- "test/fixtures/default/layouts/default.haml",
88
- "test/fixtures/default/site/about/index.html",
89
- "test/fixtures/default/site/foo.html.haml",
90
- "test/fixtures/default/site/index.html.haml",
91
- "test/fixtures/default/site/layout_test.html.haml",
92
- "test/fixtures/default/site/yes.html",
93
- "test/fixtures/default/www_control/about/index.html",
94
- "test/fixtures/default/www_control/foo.html",
95
- "test/fixtures/default/www_control/index.html",
96
- "test/fixtures/default/www_control/layout_test.html",
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",
107
- "test/helper.rb",
108
- "test/test_all_fixtures.rb",
109
- "test/test_build.rb",
110
- "test/test_hyde.rb",
111
- "test/test_page.rb",
112
- "test/test_utils.rb"
22
+ ".yardopts",
23
+ "AUTHORS",
24
+ "CHANGELOG",
25
+ "LICENSE",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/hyde",
30
+ "data/new_site/.gitignore",
31
+ "data/new_site/README.md",
32
+ "data/new_site/hyde.conf",
33
+ "data/new_site/layouts/default.haml",
34
+ "data/new_site/site/index.html.haml",
35
+ "data/pages/404.html",
36
+ "hydeweb.gemspec",
37
+ "lib/hyde.rb",
38
+ "lib/hyde/clicommand.rb",
39
+ "lib/hyde/clicommands.rb",
40
+ "lib/hyde/helpers.rb",
41
+ "lib/hyde/layout.rb",
42
+ "lib/hyde/meta.rb",
43
+ "lib/hyde/ostruct.rb",
44
+ "lib/hyde/page.rb",
45
+ "lib/hyde/page_factory.rb",
46
+ "lib/hyde/partial.rb",
47
+ "lib/hyde/project.rb",
48
+ "lib/hyde/renderer.rb",
49
+ "lib/hyde/renderers.rb",
50
+ "lib/hyde/sinatra/init.rb",
51
+ "lib/hyde/utils.rb",
52
+ "lib/hyde_misc/console.rb",
53
+ "manual/Extending/ExtendingHyde.md",
54
+ "manual/Hyde.md",
55
+ "manual/Introduction/Configuration.md",
56
+ "manual/Introduction/GettingStarted.md",
57
+ "manual/Introduction/Installation.md",
58
+ "manual/Introduction/Layouts.md",
59
+ "manual/Introduction/Metadata.md",
60
+ "manual/Introduction/Partials.md",
61
+ "manual/Introduction/TemplateLanguages.md",
62
+ "manual/Tips/Tips.md",
63
+ "test/fixtures/content_for/_config.yml",
64
+ "test/fixtures/content_for/layouts/cf-args.haml",
65
+ "test/fixtures/content_for/layouts/cf.haml",
66
+ "test/fixtures/content_for/layouts/default.haml",
67
+ "test/fixtures/content_for/layouts/shared/test.haml",
68
+ "test/fixtures/content_for/site/cf-args-default.haml",
69
+ "test/fixtures/content_for/site/cf-args.haml",
70
+ "test/fixtures/content_for/site/cf.haml",
71
+ "test/fixtures/content_for/site/cf2.haml",
72
+ "test/fixtures/content_for/site/default.html.haml",
73
+ "test/fixtures/content_for/site/index.html.haml",
74
+ "test/fixtures/content_for/site/var.html.haml",
75
+ "test/fixtures/content_for/www_control/cf-args-default.html",
76
+ "test/fixtures/content_for/www_control/cf-args.html",
77
+ "test/fixtures/content_for/www_control/cf.html",
78
+ "test/fixtures/content_for/www_control/cf2.html",
79
+ "test/fixtures/content_for/www_control/default.html",
80
+ "test/fixtures/content_for/www_control/index.html",
81
+ "test/fixtures/content_for/www_control/var.html",
82
+ "test/fixtures/custom/_config.yml",
83
+ "test/fixtures/custom/extensions/custom/custom.rb",
84
+ "test/fixtures/custom/layouts/default.haml",
85
+ "test/fixtures/custom/layouts/erbtest.erb",
86
+ "test/fixtures/custom/layouts/shared/sidebar.haml",
87
+ "test/fixtures/custom/site/about/index.html",
88
+ "test/fixtures/custom/site/assets/common.css.less",
89
+ "test/fixtures/custom/site/assets/style.css.less",
90
+ "test/fixtures/custom/site/foo.html.haml",
91
+ "test/fixtures/custom/site/index.html.haml",
92
+ "test/fixtures/custom/site/layout_test.html.haml",
93
+ "test/fixtures/custom/site/lol.html.erb",
94
+ "test/fixtures/custom/site/markdown.html.md",
95
+ "test/fixtures/custom/site/yes.html",
96
+ "test/fixtures/custom/www_control/about/index.html",
97
+ "test/fixtures/custom/www_control/assets/common.css",
98
+ "test/fixtures/custom/www_control/assets/style.css",
99
+ "test/fixtures/custom/www_control/foo.html",
100
+ "test/fixtures/custom/www_control/index.html",
101
+ "test/fixtures/custom/www_control/layout_test.html",
102
+ "test/fixtures/custom/www_control/lol.html",
103
+ "test/fixtures/custom/www_control/markdown.html",
104
+ "test/fixtures/custom/www_control/yes.html",
105
+ "test/fixtures/default/_config.yml",
106
+ "test/fixtures/default/extensions/custom/custom.rb",
107
+ "test/fixtures/default/layouts/default.haml",
108
+ "test/fixtures/default/site/about/index.html",
109
+ "test/fixtures/default/site/foo.html.haml",
110
+ "test/fixtures/default/site/index.html.haml",
111
+ "test/fixtures/default/site/layout_test.html.haml",
112
+ "test/fixtures/default/site/yes.html",
113
+ "test/fixtures/default/www_control/about/index.html",
114
+ "test/fixtures/default/www_control/foo.html",
115
+ "test/fixtures/default/www_control/index.html",
116
+ "test/fixtures/default/www_control/layout_test.html",
117
+ "test/fixtures/default/www_control/yes.html",
118
+ "test/helper.rb",
119
+ "test/test_all_fixtures.rb",
120
+ "test/test_build.rb",
121
+ "test/test_hyde.rb",
122
+ "test/test_page.rb",
123
+ "test/test_utils.rb"
113
124
  ]
114
125
  s.homepage = %q{http://github.com/sinefunc/hyde}
115
- s.rdoc_options = ["--charset=UTF-8"]
116
126
  s.require_paths = ["lib"]
117
- s.rubygems_version = %q{1.3.6}
127
+ s.rubygems_version = %q{1.3.7}
118
128
  s.summary = %q{Website preprocessor}
119
129
  s.test_files = [
120
130
  "test/fixtures/custom/extensions/custom/custom.rb",
121
- "test/fixtures/default/extensions/custom/custom.rb",
122
- "test/helper.rb",
123
- "test/test_all_fixtures.rb",
124
- "test/test_build.rb",
125
- "test/test_hyde.rb",
126
- "test/test_page.rb",
127
- "test/test_utils.rb"
131
+ "test/fixtures/default/extensions/custom/custom.rb",
132
+ "test/helper.rb",
133
+ "test/test_all_fixtures.rb",
134
+ "test/test_build.rb",
135
+ "test/test_hyde.rb",
136
+ "test/test_page.rb",
137
+ "test/test_utils.rb"
128
138
  ]
129
139
 
130
140
  if s.respond_to? :specification_version then
131
141
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
132
142
  s.specification_version = 3
133
143
 
134
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
144
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
135
145
  s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
136
146
  s.add_runtime_dependency(%q<less>, [">= 1.2.21"])
137
147
  s.add_runtime_dependency(%q<haml>, [">= 2.2.20"])
@@ -25,7 +25,8 @@ module Hyde
25
25
 
26
26
  def self.project
27
27
  if $project.nil?
28
- log "Error: Hyde config file not found. (looking for: hyde.conf, _config.yml)"
28
+ files = Hyde::Project.config_filenames.join(", ")
29
+ log "Error: Hyde config file not found. (looking for: #{files})"
29
30
  log "Run this command in a Hyde project directory.\nTo start a new Hyde project, type `hyde create <name>`"
30
31
  exit
31
32
  end
@@ -67,7 +67,7 @@ module Hyde
67
67
  project.build ostream
68
68
  end
69
69
  end
70
-
70
+
71
71
  class Start < CLICommand
72
72
  desc "Starts the local webserver"
73
73
  def self.run(*a)
@@ -76,17 +76,28 @@ module Hyde
76
76
  end
77
77
 
78
78
  def self.help
79
+ port = project.config.port
79
80
  log "Usage: hyde start"
80
81
  log ""
81
82
  log "This command starts the local webserver. You may then be able to"
82
83
  log "see your site locally by visiting the URL:"
83
84
  log ""
84
- log " http://127.0.0.1:4567"
85
+ log " http://127.0.0.1:#{port}"
85
86
  log ""
86
87
  log "You may shut the server down by pressing Ctrl-C."
87
88
  end
88
89
  end
89
90
 
91
+ class Console < CLICommand
92
+ desc "Starts a console"
93
+
94
+ def self.run(*a)
95
+ path = File.join(Hyde::LIB_PATH, 'hyde_misc', 'console.rb')
96
+ cmd = "irb -r\"#{path}\""
97
+ system cmd
98
+ end
99
+ end
100
+
90
101
  class Create < CLICommand
91
102
  desc "Starts a new Hyde project"
92
103
  def self.run(*a)
data/lib/hyde/helpers.rb CHANGED
@@ -3,40 +3,47 @@ module Hyde
3
3
  def partial(partial_path, locals = {})
4
4
  begin
5
5
  p = project[partial_path.to_s, :Partial]
6
- p.referrer = self.referrer
6
+ p.referrer = (referrer || self)
7
7
  p.render locals
8
+
8
9
  rescue ::Hyde::NotFound
9
10
  "<!-- Can't find #{partial_path.to_s} -->"
10
11
  end
11
12
  end
12
13
 
13
14
  def content_for(key, &block)
14
- content_blocks[key.to_sym] = block
15
+ content_block[key.to_sym] = block
15
16
  end
16
17
 
17
18
  def has_content?(key)
18
- content_blocks.keys.include? key.to_sym
19
+ content_block.keys.include? key.to_sym
19
20
  end
20
21
 
21
- def yield_content(key, *args)
22
- block = content_blocks[key.to_sym]
23
- return '' if block.nil?
22
+ def yield_content(key, *args, &default_block)
23
+ block = content_block[key.to_sym]
24
24
 
25
25
  if respond_to?(:block_is_haml?) && block_is_haml?(block)
26
26
  capture_haml *args, &block
27
- elsif block.is_a? Proc
27
+
28
+ elsif block.respond_to?(:call)
28
29
  block.call *args
30
+
31
+ elsif block_given? and respond_to(:block_is_haml?) and block_is_haml?(default_block)
32
+ capture_haml *args, &default_block
33
+
29
34
  elsif block_given?
30
35
  yield
36
+
31
37
  else
32
38
  ''
33
39
  end
34
40
  end
35
41
 
36
42
  protected
37
- def content_blocks
43
+ def content_block
44
+ file_key = (referrer || self).to_sym
38
45
  @@content_blocks ||= Hash.new
39
- @@content_blocks[referrer.to_sym] ||= Hash.new { |h, k| h[k] = [] }
46
+ @@content_blocks[file_key] ||= Hash.new
40
47
  end
41
48
  end
42
49
  end
data/lib/hyde/layout.rb CHANGED
@@ -3,5 +3,10 @@ module Hyde
3
3
  def self.get_filename(path, project)
4
4
  project.root(:layouts, path)
5
5
  end
6
+
7
+ def layout
8
+ # Don't try a default layout.
9
+ @layout
10
+ end
6
11
  end
7
12
  end
data/lib/hyde/meta.rb CHANGED
@@ -15,7 +15,7 @@ module Hyde
15
15
  def layout=(value)
16
16
  super value
17
17
  @page.layout = @page.project[value, :Layout]
18
- @page.layout.referrer = page.referrer
18
+ @page.layout.referrer = (page.referrer || page)
19
19
  end
20
20
  end
21
21
  end
data/lib/hyde/page.rb CHANGED
@@ -25,9 +25,9 @@ module Hyde
25
25
  # A reference to the parent {Project} instance
26
26
  attr_reader :project
27
27
 
28
- attr_accessor :layout
28
+ attr_accessor :referrer
29
29
 
30
- attr_writer :referrer
30
+ DEFAULT_LAYOUT = 'default'
31
31
 
32
32
  # Factory
33
33
  #
@@ -35,22 +35,139 @@ module Hyde
35
35
  PageFactory.create path, project, def_page_class
36
36
  end
37
37
 
38
- def referrer
39
- @referrer.nil? ? name : @referrer
40
- end
41
-
42
38
  # Returns the rendered output.
43
39
  def render(data = {}, &block)
44
40
  data = @meta | data
41
+ data[:page] ||= self
45
42
  output = @renderer.render(data, &block)
46
- output = @layout.render(data) { output } unless @layout.nil?
43
+ output = layout.render(data) { output } unless layout.nil?
47
44
  output
48
45
  end
49
46
 
47
+ def layout=(val)
48
+ @layout = val
49
+ end
50
+
51
+ def layout
52
+ begin
53
+ @layout ||= project[DEFAULT_LAYOUT, :Layout] if !@renderer.nil? and @renderer.layoutable?
54
+ @layout
55
+ rescue NotFound
56
+ nil
57
+ end
58
+ end
59
+
60
+ def title
61
+ @title ||= if meta.title
62
+ meta.title
63
+ elsif is_index?
64
+ File.basename(File.dirname(filename))
65
+ else
66
+ File.basename(filename, '.*')
67
+ end
68
+ end
69
+
70
+ # Returns the URL path for the page.
71
+ def path
72
+ return @url unless @url.nil?
73
+
74
+ url = File.split(@name)
75
+ url[1] = File.basename(url[1], '.*')
76
+ url[1] = (url[1] + @renderer.default_ext) unless url[1].include?('.')
77
+ @url = '/' + url.join('/')
78
+ end
79
+
50
80
  def get_binding #(&blk)
51
81
  binding
52
82
  end
53
83
 
84
+ def to_s
85
+ name
86
+ end
87
+
88
+ def to_sym
89
+ (filename).to_sym
90
+ end
91
+
92
+ def <=>(other)
93
+ result = self.position <=> other.position
94
+ result ||= self.position.to_s <=> other.position.to_s
95
+ result
96
+ end
97
+
98
+ def position
99
+ meta.position || title
100
+ end
101
+
102
+ def parent
103
+ folder = File.dirname(@name)
104
+ folder = File.join(folder, '..') if is_index?
105
+ folder = File.expand_path(folder)
106
+
107
+ files = Dir[File.join(folder, 'index.*')]
108
+ return nil if files.empty?
109
+
110
+ page = PageFactory.create(files.first, @project)
111
+ return nil if page === self
112
+
113
+ page
114
+ end
115
+
116
+ def children
117
+ return [] unless is_index?
118
+ folder = File.dirname(@name)
119
+
120
+ get_pages_from folder
121
+ end
122
+
123
+ def siblings
124
+ folder = File.dirname(@name)
125
+ folder = File.join(folder, '..') if is_index?
126
+
127
+ get_pages_from folder
128
+ end
129
+
130
+ def get_pages_from(folder)
131
+ # Sanity check: don't go beyond the root
132
+ return [] unless File.expand_path(folder).include?(File.expand_path(@project.root(:site)))
133
+
134
+ files = Dir[@project.root(:site, folder, '*')]
135
+ files.inject([]) do |a, name|
136
+ if File.directory?(name)
137
+ name = Dir[File.join(name, 'index.*')].first
138
+ a << PageFactory.create(name, @project) unless name.nil?
139
+
140
+ else
141
+ page = PageFactory.create name, @project
142
+ a << page unless page.is_index?
143
+
144
+ end
145
+ a
146
+ end.sort
147
+ end
148
+
149
+ # Returns an array of the page's ancestors, starting from the root page.
150
+ def breadcrumbs
151
+ @crumbs ||= parent.nil? ? [] : (parent.breadcrumbs + [parent])
152
+ end
153
+
154
+ def ===(other)
155
+ return false if other.nil?
156
+ super || (File.expand_path(self.filename) === File.expand_path(other.filename))
157
+ end
158
+
159
+ def next
160
+ siblings.each_cons(2) { |(i, other)| return other if i === self }
161
+ end
162
+
163
+ def previous
164
+ siblings.each_cons(2) { |(other, i)| return other if i === self }
165
+ end
166
+
167
+ def is_index?
168
+ !@name.match(/(^|\/)index/).nil?
169
+ end
170
+
54
171
  protected
55
172
 
56
173
  # Constructor.
@@ -1,6 +1,15 @@
1
1
  module Hyde
2
2
  class PageFactory
3
+ # Creates a Page with the right class, as defined in the Page's metadata.
4
+ #
5
+ # Params:
6
+ # path - A path, or a filename
7
+ #
3
8
  def self.create(path, project, def_page_class = Page)
9
+ # Remove prefix
10
+ path.gsub!(project.root(:site), '')
11
+ path.gsub!(/^\/+/, '')
12
+
4
13
  ext = File.extname(path)
5
14
  begin
6
15
  do_create path, project, def_page_class
@@ -29,7 +38,8 @@ module Hyde
29
38
  raise NotFound, "`#{path}` is a directory, not a file"
30
39
 
31
40
  elsif File.exists? filename
32
- renderer = Hyde::Renderer::Passthru
41
+ ext = File.extname(filename)[1..-1]
42
+ renderer = Hyde::Renderer.get(ext)
33
43
 
34
44
  else
35
45
  # Look for the file
@@ -43,7 +53,7 @@ module Hyde
43
53
  begin
44
54
  ext = File.extname(match)[1..-1].capitalize.to_sym
45
55
  exts << File.extname(match)
46
- r_class = Hyde::Renderers.const_get(ext)
56
+ r_class = Hyde::Renderers.const_get(ext) # .get(ext, nil)
47
57
  renderer ||= r_class
48
58
  filename = match
49
59
  rescue NoMethodError