hydeweb 0.0.3.pre → 0.0.4

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.
Files changed (40) hide show
  1. data/.yardopts +5 -2
  2. data/AUTHORS +6 -0
  3. data/CHANGELOG +1 -0
  4. data/LICENSE +1 -1
  5. data/README.md +4 -1
  6. data/Rakefile +4 -0
  7. data/VERSION +1 -1
  8. data/hydeweb.gemspec +21 -11
  9. data/lib/hyde/helpers.rb +9 -2
  10. data/lib/hyde/init.rb +11 -1
  11. data/lib/hyde/page.rb +9 -53
  12. data/lib/hyde/page_factory.rb +63 -0
  13. data/lib/hyde/partial.rb +7 -0
  14. data/lib/hyde/project.rb +58 -34
  15. data/lib/hyde.rb +13 -11
  16. data/{docs → manual}/Extending/ExtendingHyde.md +1 -1
  17. data/manual/Hyde.md +58 -0
  18. data/{docs → manual}/Introduction/Configuration.md +2 -0
  19. data/manual/Introduction/GettingStarted.md +66 -0
  20. data/{docs/Introduction/Partials.md → manual/Introduction/Metadata.md} +1 -1
  21. data/manual/Introduction/Partials.md +63 -0
  22. data/manual/Introduction/TemplateLanguages.md +59 -0
  23. data/test/fixtures/custom/layouts/default.haml +1 -0
  24. data/test/fixtures/custom/layouts/shared/sidebar.haml +4 -0
  25. data/test/fixtures/custom/site/about/index.html +1 -1
  26. data/test/fixtures/custom/www_control/about/index.html +1 -1
  27. data/test/fixtures/custom/www_control/index.html +7 -0
  28. data/test/fixtures/custom/www_control/layout_test.html +7 -0
  29. data/test/fixtures/custom/www_control/markdown.html +7 -0
  30. data/test/fixtures/default/extensions/custom/custom.rb +2 -0
  31. data/test/helper.rb +8 -0
  32. data/test/test_all_fixtures.rb +6 -2
  33. data/test/test_hyde.rb +29 -10
  34. data/test/test_page.rb +26 -0
  35. metadata +25 -18
  36. data/docs/Hyde.md +0 -17
  37. data/docs/Introduction/GettingStarted.md +0 -32
  38. data/docs/Introduction/TemplateLanguages.md +0 -15
  39. /data/{docs → manual}/Introduction/Installation.md +0 -0
  40. /data/{docs → manual}/Introduction/Layouts.md +0 -0
data/.yardopts CHANGED
@@ -1,2 +1,5 @@
1
- --files="docs/*/*"
2
- --main="docs/Hyde.md"
1
+ --files="manual/*/*"
2
+ --files="AUTHORS"
3
+ --files="LICENSE"
4
+ --files="CHANGELOG"
5
+ --main="manual/Hyde.md"
data/AUTHORS ADDED
@@ -0,0 +1,6 @@
1
+ Credits
2
+ =======
3
+
4
+ Hyde was created and being developed and maintained by Rico Sta. Cruz of Sinefunc, Inc.
5
+
6
+ A hat tip goes to Tom Preston-Werner (mojombo) for Jekyll, the very project that inspired Hyde.
data/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Sinefunc, Inc.
1
+ Copyright (c) 2010 Rico Sta. Cruz and Sinefunc, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -17,11 +17,14 @@ Usage
17
17
  To do
18
18
  -----
19
19
 
20
- - partials support
20
+ - ignores
21
+ - error pages
21
22
  - _meta.yml
22
23
 
23
24
  Done:
24
25
 
26
+ - last_modified
27
+ - partials support
25
28
  - hyde build
26
29
  - extensions support
27
30
  - hyde gen
data/Rakefile CHANGED
@@ -49,3 +49,7 @@ Rake::RDocTask.new do |rdoc|
49
49
  rdoc.rdoc_files.include('README*')
50
50
  rdoc.rdoc_files.include('lib/**/*.rb')
51
51
  end
52
+
53
+ task :autotest do
54
+ system "rstakeout 'rake test' **/*.rb"
55
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3.pre
1
+ 0.0.4
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.3.pre"
8
+ s.version = "0.0.4"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
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-04}
12
+ s.date = %q{2010-05-25}
13
13
  s.default_executable = %q{hyde}
14
14
  s.description = %q{Website preprocessor}
15
15
  s.email = %q{rico@sinefunc.com}
@@ -21,6 +21,8 @@ Gem::Specification.new do |s|
21
21
  s.files = [
22
22
  ".gitignore",
23
23
  ".yardopts",
24
+ "AUTHORS",
25
+ "CHANGELOG",
24
26
  "LICENSE",
25
27
  "README.md",
26
28
  "Rakefile",
@@ -31,14 +33,6 @@ Gem::Specification.new do |s|
31
33
  "data/new_site/hyde.conf",
32
34
  "data/new_site/layouts/default.haml",
33
35
  "data/new_site/site/index.html.haml",
34
- "docs/Extending/ExtendingHyde.md",
35
- "docs/Hyde.md",
36
- "docs/Introduction/Configuration.md",
37
- "docs/Introduction/GettingStarted.md",
38
- "docs/Introduction/Installation.md",
39
- "docs/Introduction/Layouts.md",
40
- "docs/Introduction/Partials.md",
41
- "docs/Introduction/TemplateLanguages.md",
42
36
  "hydeweb.gemspec",
43
37
  "lib/hyde.rb",
44
38
  "lib/hyde/clicommand.rb",
@@ -48,14 +42,26 @@ Gem::Specification.new do |s|
48
42
  "lib/hyde/layout.rb",
49
43
  "lib/hyde/ostruct.rb",
50
44
  "lib/hyde/page.rb",
45
+ "lib/hyde/page_factory.rb",
46
+ "lib/hyde/partial.rb",
51
47
  "lib/hyde/project.rb",
52
48
  "lib/hyde/renderer.rb",
53
49
  "lib/hyde/renderers.rb",
54
50
  "lib/hyde/utils.rb",
51
+ "manual/Extending/ExtendingHyde.md",
52
+ "manual/Hyde.md",
53
+ "manual/Introduction/Configuration.md",
54
+ "manual/Introduction/GettingStarted.md",
55
+ "manual/Introduction/Installation.md",
56
+ "manual/Introduction/Layouts.md",
57
+ "manual/Introduction/Metadata.md",
58
+ "manual/Introduction/Partials.md",
59
+ "manual/Introduction/TemplateLanguages.md",
55
60
  "test/fixtures/custom/_config.yml",
56
61
  "test/fixtures/custom/extensions/custom/custom.rb",
57
62
  "test/fixtures/custom/layouts/default.haml",
58
63
  "test/fixtures/custom/layouts/erbtest.erb",
64
+ "test/fixtures/custom/layouts/shared/sidebar.haml",
59
65
  "test/fixtures/custom/site/about/index.html",
60
66
  "test/fixtures/custom/site/assets/common.css.less",
61
67
  "test/fixtures/custom/site/assets/style.css.less",
@@ -75,6 +81,7 @@ Gem::Specification.new do |s|
75
81
  "test/fixtures/custom/www_control/markdown.html",
76
82
  "test/fixtures/custom/www_control/yes.html",
77
83
  "test/fixtures/default/_config.yml",
84
+ "test/fixtures/default/extensions/custom/custom.rb",
78
85
  "test/fixtures/default/layouts/default.haml",
79
86
  "test/fixtures/default/site/about/index.html",
80
87
  "test/fixtures/default/site/foo.html.haml",
@@ -90,6 +97,7 @@ Gem::Specification.new do |s|
90
97
  "test/test_all_fixtures.rb",
91
98
  "test/test_build.rb",
92
99
  "test/test_hyde.rb",
100
+ "test/test_page.rb",
93
101
  "test/test_utils.rb"
94
102
  ]
95
103
  s.homepage = %q{http://github.com/sinefunc/hyde}
@@ -99,10 +107,12 @@ Gem::Specification.new do |s|
99
107
  s.summary = %q{Website preprocessor}
100
108
  s.test_files = [
101
109
  "test/fixtures/custom/extensions/custom/custom.rb",
110
+ "test/fixtures/default/extensions/custom/custom.rb",
102
111
  "test/helper.rb",
103
112
  "test/test_all_fixtures.rb",
104
113
  "test/test_build.rb",
105
114
  "test/test_hyde.rb",
115
+ "test/test_page.rb",
106
116
  "test/test_utils.rb"
107
117
  ]
108
118
 
data/lib/hyde/helpers.rb CHANGED
@@ -1,8 +1,15 @@
1
1
  module Hyde
2
2
  module Helpers
3
3
  module Default
4
- # def render # partial support
5
- # end
4
+ def render_partial(partial_path, args = {})
5
+ locals = args[:locals] || {}
6
+ p = Partial.create partial_path.to_s, project
7
+ p.render locals
8
+ end
9
+
10
+ def partial(*a)
11
+ render_partial *a
12
+ end
6
13
  end
7
14
  end
8
15
  end
data/lib/hyde/init.rb CHANGED
@@ -33,13 +33,23 @@ class Main < Sinatra::Base
33
33
  path = params[:splat][0]
34
34
  type = File.extname(path)[1..-1]
35
35
  content_type type.to_sym if type.is_a? String
36
- @@project.render path
36
+
37
+ page = Hyde::Page.create path, @@project
38
+
39
+ # Send the last modified time
40
+ last_modified File.mtime(page.filename)
41
+ cache_control :public, :must_revalidate, :max_age => 60
42
+
43
+ page.render
44
+
37
45
  rescue Hyde::RenderError => e
38
46
  puts " * `#{path}` error"
39
47
  puts " *** #{e.message}".gsub("\n","\n *** ")
40
48
  e.message
49
+
41
50
  rescue Hyde::NotFound
42
51
  raise Sinatra::NotFound
52
+
43
53
  end
44
54
  end
45
55
  end
data/lib/hyde/page.rb CHANGED
@@ -13,6 +13,7 @@ module Hyde
13
13
  # @example
14
14
  # puts page.name
15
15
  # puts page.filename
16
+ #
16
17
  # # about/index.html
17
18
  # # about/index.html.haml
18
19
  attr_accessor :filename
@@ -28,17 +29,13 @@ module Hyde
28
29
  attr_reader :project
29
30
 
30
31
  # Factory
31
- # Try {Project#get_page} instead
32
- def self.create(path, project, page_class = Page)
33
- info = get_page_info(path, project)
34
- page = page_class.new(path, project, info[:renderer], info[:filename])
32
+ #
33
+ def self.create(path, project, def_page_class = Page)
34
+ PageFactory.create path, project, def_page_class
35
35
  end
36
36
 
37
37
  # Returns the rendered output.
38
38
  def render(data = {}, &block)
39
- if self.is_a? Layout
40
- # puts debug
41
- end
42
39
  output = @renderer.render(data, &block)
43
40
  # BUG: @layout should build on top of that data
44
41
  output = @layout.render(@meta.merge data) { output } unless @layout.nil?
@@ -46,13 +43,7 @@ module Hyde
46
43
  end
47
44
 
48
45
  def method_missing(meth, *args, &blk)
49
- if meta.keys.include?(meth.to_s)
50
- meta[meth.to_s]
51
- elsif meta.keys.include?(meth.to_sym)
52
- meta[meth.to_sym]
53
- else
54
- raise NoMethodError.new "Undefined method `#{self.class}::#{meth}`"
55
- end
46
+ meta[meth.to_s] || meta[meth.to_sym] || super
56
47
  end
57
48
 
58
49
  def get_binding
@@ -67,18 +58,21 @@ module Hyde
67
58
  # Called by Renderer::Base.
68
59
  #
69
60
  def set_meta(meta)
61
+ # TODO: OStruct and stuff
70
62
  # Merge
71
63
  @meta ||= Hash.new
72
64
  @meta.merge! meta
73
65
 
74
66
  # Set the Layout
75
- @layout = @project.get_layout(@meta['layout']) if @meta['layout']
67
+ @layout = Layout.create(@meta['layout'], @project) if @meta['layout']
76
68
  end
77
69
 
78
70
  protected
71
+
79
72
  # Constructor.
80
73
  # The `page` argument is a page name
81
74
  # Don't use me: use {Project#create}
75
+ #
82
76
  def initialize(path, project, renderer, filename)
83
77
  @project = project
84
78
  @name ||= path
@@ -90,43 +84,5 @@ module Hyde
90
84
  def self.get_filename(path, project)
91
85
  project.root(:site, path)
92
86
  end
93
-
94
- def self.get_page_info(path, project)
95
- renderer = nil
96
- filename = get_filename(path, project)
97
-
98
- if File.exists? filename
99
- renderer = Hyde::Renderer::Passthru
100
-
101
- else
102
- # Look for the file
103
- matches = Dir["#{filename}.*"]
104
- raise NotFound.new("Can't find `#{path}{,.*}` -- #{filename}") \
105
- if matches.empty?
106
-
107
- # Check for a matching renderer
108
- exts = []
109
- matches.each do |match|
110
- begin
111
- ext = File.extname(match)[1..-1].capitalize.to_sym
112
- exts << File.extname(match)
113
- r_class = Hyde::Renderers.const_get(ext)
114
- renderer ||= r_class
115
- filename = match
116
- rescue NoMethodError
117
- # pass
118
- rescue NameError # Renderer not found
119
- # pass
120
- end
121
- end
122
-
123
- raise NotFound.new("No matching (#{exts.join(", ")}) renderers found for `#{path}`") \
124
- if renderer.nil?
125
- end
126
-
127
- { :renderer => renderer,
128
- :filename => filename
129
- }
130
- end
131
87
  end
132
88
  end
@@ -0,0 +1,63 @@
1
+ module Hyde
2
+ class PageFactory
3
+ def self.create(path, project, def_page_class = Page)
4
+ begin
5
+ do_create path, project, def_page_class
6
+ rescue NotFound
7
+ do_create "#{path}/index.html".squeeze('/'), project, def_page_class
8
+ rescue NotFound => e
9
+ raise e
10
+ end
11
+ end
12
+
13
+ def self.do_create(path, project, def_page_class = Page)
14
+ info = get_page_info(path, project, def_page_class)
15
+ page_class = info[:page_class]
16
+ page_class.new(path, project, info[:renderer], info[:filename])
17
+ end
18
+
19
+ protected
20
+
21
+ def self.get_page_info(path, project, page_class)
22
+ renderer = nil
23
+ filename = page_class.get_filename(path, project)
24
+
25
+ if File.directory? filename
26
+ raise NotFound, "`#{path}` is a directory, not a file"
27
+
28
+ elsif File.exists? filename
29
+ renderer = Hyde::Renderer::Passthru
30
+
31
+ else
32
+ # Look for the file
33
+ matches = Dir["#{filename}.*"]
34
+ raise NotFound, "Can't find `#{path}{,.*}` -- #{filename}" \
35
+ if matches.empty?
36
+
37
+ # Check for a matching renderer
38
+ exts = []
39
+ matches.each do |match|
40
+ begin
41
+ ext = File.extname(match)[1..-1].capitalize.to_sym
42
+ exts << File.extname(match)
43
+ r_class = Hyde::Renderers.const_get(ext)
44
+ renderer ||= r_class
45
+ filename = match
46
+ rescue NoMethodError
47
+ # pass
48
+ rescue NameError # Renderer not found
49
+ # pass
50
+ end
51
+ end
52
+
53
+ raise NotFound, "No matching (#{exts.join(", ")}) renderers found for `#{path}`" \
54
+ if renderer.nil?
55
+ end
56
+
57
+ { :renderer => renderer,
58
+ :filename => filename,
59
+ :page_class => page_class
60
+ }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,7 @@
1
+ module Hyde
2
+ class Partial < Layout
3
+ def self.create(path, project, page_class = Partial)
4
+ super path, project, page_class
5
+ end
6
+ end
7
+ end
data/lib/hyde/project.rb CHANGED
@@ -4,9 +4,12 @@ module Hyde
4
4
  include Hyde::Utils
5
5
 
6
6
  # The root path (String).
7
+ #
8
+ # @example
7
9
  # root
8
10
  # root :layouts
9
11
  # root :site, 'blah'
12
+ #
10
13
  def root(*args)
11
14
  where = ''
12
15
  where = send("#{args.shift.to_s}_path") if args[0].class == Symbol
@@ -14,68 +17,57 @@ module Hyde
14
17
  File.expand_path(File.join [@root, where, path].reject(&:empty?))
15
18
  end
16
19
 
17
- # The filename of the configuration file, relative to the project root.
20
+ # The filename of the configuration file, relative to the project root. (String)
21
+ #
18
22
  attr :config_file
19
23
 
20
- # The configuration k/v storage (Hash)
24
+ # The configuration k/v storage (OStruct)
25
+ #
21
26
  attr_accessor :config
22
27
 
23
28
  # Can raise a NoRootError
24
- def initialize( root = Dir.pwd )
29
+ #
30
+ def initialize(root = Dir.pwd)
25
31
  @config = OStruct.new defaults
26
32
  @root, @config_file = find_root_from root
27
33
  @config.merge! YAML::load_file(@config_file) if File.exists? @config_file
28
34
  load_extensions
29
35
  end
30
36
 
31
- def find_root_from(start)
32
- check = File.expand_path(start)
33
- ret = nil
34
- while ret.nil?
35
- # See if any of these files exist
36
- ['_config.yml', 'hyde.conf'].each do |config_name|
37
- config_file = File.join(check, config_name)
38
- ret ||= [check, config_file] if File.exists? config_file
39
- end
40
-
41
- # Traverse back (die if we reach the root)
42
- old_check = check
43
- check = File.expand_path(File.join(check, '..'))
44
- raise NoRootError if check == old_check
45
- end
46
- ret
47
- end
48
-
49
37
  def method_missing(meth, *args, &blk)
50
- raise NoMethodError, "No method `#{meth}`" unless @config.include?(meth)
38
+ super unless @config.include?(meth)
51
39
  @config.send meth
52
40
  end
53
41
 
54
42
  # Returns a page in a certain URL path.
55
43
  # @return {Page} or a subclass of it
44
+ #
56
45
  def get_page(path)
57
- path = "index.html" if path.empty?
58
- Page.create path, self
46
+ Page.create path, self
59
47
  end
60
48
 
49
+ # Returns a layout
50
+ # (Try Layout.create path, @project instead)
51
+ #
61
52
  def get_layout(path)
62
53
  Layout.create path, self
63
54
  end
64
55
 
65
56
  # Can throw a NotFound.
57
+ #
66
58
  def render(path)
67
- get_page(path).render
59
+ Page.create(path, self).render
68
60
  end
69
61
 
70
62
  # Writes the output files.
71
63
  # @param
72
64
  # ostream - (Stream) Where to send the messages
65
+ #
73
66
  def build(ostream = nil)
74
67
  raise Errno::EEXISTS if File.exists? root(:output) and not File.directory? root(:output)
75
- Dir.mkdir root(:output) unless File.directory? root(:output)
68
+ Dir.mkdir(root :output) unless File.directory?(root :output)
76
69
 
77
70
  begin
78
- continue = true
79
71
  files.each do |path|
80
72
  ostream << " * #{output_path}/#{path}\n" if ostream
81
73
  begin
@@ -88,11 +80,12 @@ module Hyde
88
80
  end
89
81
  end
90
82
  rescue NoGemError => e
91
- ostream << "Error: #{e.message}\n"
83
+ ostream << " *** Error: #{e.message}\n"
92
84
  end
93
85
  end
94
86
 
95
87
  # Returns a list of all URL paths
88
+ #
96
89
  def files
97
90
  @file_list = Dir[File.join(root(:site), '**', '*')].inject([]) do |a, match|
98
91
  # Make sure its the canonical name
@@ -111,6 +104,9 @@ module Hyde
111
104
  end
112
105
  end
113
106
 
107
+ # Returns a list of file specs to be excluded from processing.
108
+ # @see {#ignored_files}
109
+ #
114
110
  def ignore_list
115
111
  @ignore_list ||= [
116
112
  root(:layouts, '**/*'),
@@ -120,21 +116,47 @@ module Hyde
120
116
  ]
121
117
  end
122
118
 
123
- # Returns a list of ignored files.
119
+ # Returns a list of ignored files based on the {ignore_list}.
124
120
  # TODO: This is innefficient... do it another way
121
+ #
125
122
  def ignored_files
126
- @ignored_files ||= ignore_list.inject([]) { |a, spec|
123
+ @ignored_files ||= ignore_list.inject([]) do |a, spec|
127
124
  Dir[spec].each { |file| a << File.expand_path(file) }; a
128
- }
125
+ end
129
126
  end
130
127
 
131
128
  protected
132
129
 
133
- def load_extensions
134
- @config.gems.each do |gem|
135
- require gem
130
+ # Looks for the hyde config file to determine the project root.
131
+ #
132
+ def find_root_from(start)
133
+ check = File.expand_path(start)
134
+ ret = nil
135
+ while ret.nil?
136
+ # See if any of these files exist
137
+ ['_config.yml', 'hyde.conf'].each do |config_name|
138
+ config_file = File.join(check, config_name)
139
+ ret ||= [check, config_file] if File.exists? config_file
140
+ end
141
+
142
+ # Traverse back (die if we reach the root)
143
+ old_check = check
144
+ check = File.expand_path(File.join(check, '..'))
145
+ raise NoRootError if check == old_check
136
146
  end
147
+ ret
148
+ end
149
+
150
+ # Loads the ruby files in the extensions folder
151
+ #
152
+ def load_extensions
153
+ # Load the init.rb file
154
+ require(root 'init.rb') if File.exists?(root 'init.rb')
137
155
 
156
+ # Load the gems in the config file
157
+ @config.gems.each { |gem| require gem }
158
+
159
+ # Load the extensions
138
160
  ext_roots = Dir[root :extensions, '*'].select { |d| File.directory? d }
139
161
  ext_roots.each do |dir|
140
162
  ext = File.basename(dir)
@@ -149,6 +171,7 @@ module Hyde
149
171
  require ext_files[0] if ext_files[0]
150
172
  end
151
173
  end
174
+
152
175
  def defaults
153
176
  { 'layouts_path' => 'layouts',
154
177
  'extensions_path' => 'extensions',
@@ -159,6 +182,7 @@ module Hyde
159
182
  end
160
183
 
161
184
  # Returns the renderer associated with the given file extension.
185
+ #
162
186
  def get_renderer(name)
163
187
  begin
164
188
  class_name = name.to_s.capitalize.to_sym
data/lib/hyde.rb CHANGED
@@ -2,17 +2,19 @@ require 'yaml'
2
2
 
3
3
  module Hyde
4
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
- autoload :Scope, "#{prefix}/hyde/scope"
13
- autoload :CLICommand, "#{prefix}/hyde/clicommand"
14
- autoload :CLICommands,"#{prefix}/hyde/clicommands"
15
- autoload :Helpers, "#{prefix}/hyde/helpers"
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 :PageFactory, "#{prefix}/hyde/page_factory"
10
+ autoload :Renderer, "#{prefix}/hyde/renderer"
11
+ autoload :Renderers, "#{prefix}/hyde/renderers"
12
+ autoload :Utils, "#{prefix}/hyde/utils"
13
+ autoload :Scope, "#{prefix}/hyde/scope"
14
+ autoload :CLICommand, "#{prefix}/hyde/clicommand"
15
+ autoload :CLICommands, "#{prefix}/hyde/clicommands"
16
+ autoload :Helpers, "#{prefix}/hyde/helpers"
17
+ autoload :Partial, "#{prefix}/hyde/partial"
16
18
 
17
19
  Error = Class.new(::StandardError)
18
20
  NoGemError = Class.new(Error)
@@ -77,7 +77,7 @@ It will also show under `hyde --help` since it provides a `desc`.
77
77
  # extensions/hyde-clean/hyde-clean.rb
78
78
  module Hyde
79
79
  module CLICommands
80
- class Clean
80
+ class Clean < CLICommand
81
81
  desc "Cleans up your project's dirt"
82
82
 
83
83
  def self.run(*a)
data/manual/Hyde.md ADDED
@@ -0,0 +1,58 @@
1
+ Hyde
2
+ ====
3
+
4
+ Hyde is a website preprocessor.
5
+
6
+ - __Layouts and Partials:__ Hyde lets you define your site's header and footer
7
+ layouts in a separate file, and even separate snippets of your site
8
+ into reuseable components (partials). Your code will be much cleaner and
9
+ DRYer!
10
+
11
+ - __Template languages:__ Hyde lets you write your site in any template
12
+ language you need -- the translation will be taken care of for you.
13
+ Hyde supports HAML, LessCSS, Markdown, SASS and Textile by default, and
14
+ more can be added through extensions.
15
+
16
+ - __Extendable:__ Hyde is easily customizable with extensions. You can add
17
+ new helpers, new commands, support for new languages and many more by
18
+ simply adding the extensions to your project folder. Some are even
19
+ available as simple Ruby gems!
20
+
21
+ - __Design fast:__ Hyde comes with a web server that lets you serve up
22
+ your site locally. Any changes to your files will be seen on your next
23
+ browser refresh!
24
+
25
+ - __Build your site as static HTMLs:__ You can export your site as plain
26
+ HTML files with one simple command.
27
+
28
+ Why use Hyde?
29
+ -------------
30
+
31
+ It's like building a static site, but better! You can use Hyde for:
32
+
33
+ - Building HTML prototypes
34
+ - Building sites with no dynamic logic
35
+ - Creating a blog where the entries are stored in a source repository
36
+
37
+ Introduction
38
+ ------------
39
+
40
+ - `++++` {file:Installation Installation} -- Start here
41
+ - `++++` {file:GettingStarted Getting started}
42
+ - `++--` {file:TemplateLanguages Template languages}
43
+ - `----` {file:Layouts Layouts}
44
+ - `----` {file:Partials Partials}
45
+ - `----` {file:Metadata Metadata}
46
+ - `----` {file:Configuration Configuration}
47
+
48
+ Extending Hyde
49
+ --------------
50
+
51
+ - `+++-` {file:ExtendingHyde Extending Hyde}
52
+
53
+ Basic info
54
+ ----------
55
+
56
+ - {file:AUTHORS Credits}
57
+ - {file:LICENSE License}
58
+
@@ -1,2 +1,4 @@
1
1
  Configuration
2
2
  =============
3
+
4
+ `hyde.conf`
@@ -0,0 +1,66 @@
1
+ Getting started
2
+ ===============
3
+
4
+ Starting your first project
5
+ ---------------------------
6
+
7
+ Create your first project with:
8
+
9
+ hyde create <name>
10
+
11
+ Where `<name>` is the name of your project. This will create a folder with that
12
+ name, along with some sample files to get you started.
13
+
14
+ Starting
15
+ --------
16
+
17
+ Begin working on your project by starting the Hyde webserver. This is optional,
18
+ but is recommended as it's a nice way to see your changes in real time.
19
+
20
+ hyde start
21
+
22
+ After typing this, you will see the server has started. Point your web browser to
23
+ `http://localhost:4567` to see your site. You should now see your project's
24
+ default "welcome" page.
25
+
26
+
27
+ Editing your site
28
+ -----------------
29
+
30
+ Your project has a subfolder called `site` -- this is where all the site's files are
31
+ stored. In general, dropping any file in this folder will make it accessible with the
32
+ same filename.
33
+
34
+ Try this: create a file called `products.html` and fill it up like you would an
35
+ HTML page. After that, point your browser to `http://localhost:4567/products.html`,
36
+ which should now show the page you were working on.
37
+
38
+ You may also put your files in subfolders. If you were to create the file
39
+ `site/assets/my_style.css`, it should be accessible through
40
+ `http://localhost:4567/assets/my_style.css`.
41
+
42
+ Dynamic files
43
+ -------------
44
+
45
+ There are files with two extensions, for instance, `index.html.haml`. If a file
46
+ ends in one of Hyde's dynamic file extensions (like `.haml`), it will be stripped
47
+ out and the file will be rendered using the template engine in that extension (in
48
+ this case, HAML).
49
+
50
+ More about this in the next section.
51
+
52
+ Building HTML files
53
+ -------------------
54
+
55
+ The `hyde start` webserver is good for local development, but when it's time to
56
+ deploy your site, you will need to build your files. This process outputs raw
57
+ HTML files for your entire site (for the dynamic files), with Hyde translating
58
+ any files that need translation (e.g., HAML and ERB files).
59
+
60
+ Build your files by typing this in the command prompt:
61
+
62
+ hyde build
63
+
64
+ This will create a folder called `public/` where the built files are stored.
65
+ You can now deploy this folder to your webserver.
66
+
@@ -1,2 +1,2 @@
1
- Partials
1
+ Metadata
2
2
  ========
@@ -0,0 +1,63 @@
1
+ Partials
2
+ ========
3
+
4
+ A partial is a snippet of code that you can reuse in any page of your site.
5
+ This is particularly useful for repetitive sections, and for sections that may
6
+ make your files too large to manage.
7
+
8
+ Creating partials
9
+ -----------------
10
+
11
+ Put your partial file anywhere in the `layouts` folder, e.g.:
12
+
13
+ <!-- layouts/shared/sidebar.erb -->
14
+ <div id='#sidebar'>
15
+ <h2><span>Sidebar</span><h2>
16
+ <div class='description'>
17
+ <p>This is a sidebar partial defined in a separate file.</p>
18
+ </div>
19
+ </div>
20
+
21
+ In your site's files, you can invoke a partial through:
22
+
23
+ <!-- site/index.html.erb -->
24
+ <h1>Partial:</h1>
25
+ <%= partial 'shared/sidebar' %>
26
+ <span>End of partial.</span>
27
+ <span>This is now text from index.html.</span>
28
+
29
+ This will output:
30
+
31
+ <!-- public/index.html -->
32
+ <h1>Partial:</h1>
33
+ <div id='#sidebar'>
34
+ <h2><span>Sidebar</span><h2>
35
+ <div class='description'>
36
+ <p>This is a sidebar partial defined in a separate file.</p>
37
+ </div>
38
+ </div>
39
+ <span>End of partial.</span>
40
+ <span>This is now text from index.html.</span>
41
+
42
+ Partials with local variables
43
+ -----------------------------
44
+
45
+ You can define a partial with some local variables that will be passed
46
+ to it by the caller.
47
+
48
+ <!-- layouts/shared/product.erb -->
49
+ <div class='product'>
50
+ <div class='title'>
51
+ <h2><%= name %></h2>
52
+ </div>
53
+ <div class='desc'>
54
+ <p><%= description %></p>
55
+ </div>
56
+ </div>
57
+
58
+ In your files, call a partial by:
59
+
60
+ <!-- site/index.html.erb -->
61
+ <%= partial 'shared/product', { :name => '5MP Camera CX-300', :description => 'This is a camera with an adjustable focal length and Bluetooth support.' } %>
62
+
63
+
@@ -0,0 +1,59 @@
1
+ Template languages
2
+ ==================
3
+
4
+ Hyde comes with support for some common template languages. This means you can
5
+ write your site in a language like Markdown or HAML, and have Hyde take care
6
+ of translating them accordingly.
7
+
8
+ If a file ends in one of Hyde's supported file extensions (like `.haml`), it will be stripped
9
+ out and the file will be rendered using the template engine in that extension (in
10
+ this case, HAML).
11
+
12
+ Supported languages
13
+ -------------------
14
+
15
+ Hyde supports the following languages out-of-the-box:
16
+
17
+ - HTML template languages
18
+ - `.haml` -- HAML
19
+ - `.md` -- Markdown
20
+ - `.textile` -- Textile
21
+ - `.erb` -- ERB (Embedded Ruby)
22
+
23
+ - CSS template languages
24
+ - `.less` -- LessCSS
25
+ - `.sass` -- SASS
26
+
27
+ This means that the following files will be translated accordingly:
28
+
29
+ | products.html.haml | becomes `products.html` (rendered through HAML) |
30
+ | control.css.less | becomes `control.css` (rendered through Less CSS) |
31
+ | site.xml.erb | becomes `site.xml` (rendered through Embedded Ruby) |
32
+
33
+ Example
34
+ -------
35
+
36
+ When creating a new site, have a look at `index.html.haml`.
37
+
38
+ ...
39
+
40
+ Headers
41
+ -------
42
+
43
+ ...
44
+
45
+ Layouts
46
+ -------
47
+
48
+ Layouts are supported for these languages.
49
+
50
+ ...
51
+
52
+ Embedded Ruby features
53
+ ----------------------
54
+
55
+ Some languages (like HAML and ERB) has support for embedding Ruby code in the
56
+ documents. This will let you do some nifty things in Hyde:
57
+
58
+ - Partials
59
+ - Helpers
@@ -4,4 +4,5 @@ title: Site
4
4
  != "<!-- (default layout) -->"
5
5
  %h2 Template
6
6
  %div
7
+ =render_partial 'shared/sidebar'
7
8
  =yield
@@ -0,0 +1,4 @@
1
+ %div#sidebar
2
+ %ul
3
+ %li
4
+ Hello!
@@ -1 +1 @@
1
-
1
+ About page.
@@ -1 +1 @@
1
-
1
+ About page.
@@ -2,6 +2,13 @@
2
2
  <!-- (default layout) -->
3
3
  <h2>Template</h2>
4
4
  <div>
5
+ <div id='sidebar'>
6
+ <ul>
7
+ <li>
8
+ Hello!
9
+ </li>
10
+ </ul>
11
+ </div>
5
12
  This is the index
6
13
  <strong>
7
14
  Welcome to the index page!
@@ -2,6 +2,13 @@
2
2
  <!-- (default layout) -->
3
3
  <h2>Template</h2>
4
4
  <div>
5
+ <div id='sidebar'>
6
+ <ul>
7
+ <li>
8
+ Hello!
9
+ </li>
10
+ </ul>
11
+ </div>
5
12
  This is the index
6
13
  <strong>
7
14
  Welcome to the index page!
@@ -2,6 +2,13 @@
2
2
  <!-- (default layout) -->
3
3
  <h2>Template</h2>
4
4
  <div>
5
+ <div id='sidebar'>
6
+ <ul>
7
+ <li>
8
+ Hello!
9
+ </li>
10
+ </ul>
11
+ </div>
5
12
  <h1 id='markdown_test'>Markdown test</h1>
6
13
 
7
14
  <ul>
@@ -0,0 +1,2 @@
1
+ class CustomExtensionClass
2
+ end
data/test/helper.rb CHANGED
@@ -11,4 +11,12 @@ class Test::Unit::TestCase
11
11
  def assert_same_file(a, b)
12
12
  assert same_file?(a, b)
13
13
  end
14
+
15
+ def get_project(site)
16
+ Hyde::Project.new fixture(site)
17
+ end
18
+
19
+ def fixture(site)
20
+ File.join File.dirname(__FILE__), 'fixtures', site
21
+ end
14
22
  end
@@ -28,13 +28,17 @@ class TestAllFixtures < Test::Unit::TestCase
28
28
  @project = Hyde::Project.new File.join(@@root, site)
29
29
  @project.build
30
30
 
31
- unknown_root = @project.root :site
31
+ unknown_root = @project.root :output
32
32
  control_root = @project.root 'www_control'
33
33
 
34
34
  if not File.directory? control_root
35
35
  flunk "No www_control"
36
36
  else
37
- @project.files.select { |f| File.directory? f }.each do |path|
37
+ @project.files.reject { |f| File.directory? f }.each do |path|
38
+ unknown_path = File.join(unknown_root, path)
39
+ flunk "file #{unknown_path} doesn't exist" \
40
+ unless File.exists?(unknown_path)
41
+
38
42
  unknown = File.open(File.join(unknown_root, path)).read
39
43
  control = File.open(File.join(control_root, path)).read
40
44
 
data/test/test_hyde.rb CHANGED
@@ -5,20 +5,12 @@ class TestHyde < Test::Unit::TestCase
5
5
  @project = get_project site
6
6
  end
7
7
 
8
- def get_project(site)
9
- Hyde::Project.new fixture(site)
10
- end
11
-
12
- def fixture(site)
13
- File.join File.dirname(__FILE__), 'fixtures', site
14
- end
15
-
16
8
  should "return the right paths" do
17
9
  root_path = fixture 'default'
18
10
  assert_same_file root_path, @project.root
19
- assert_same_file File.join(root_path, '_layouts'), \
11
+ assert_same_file File.join(root_path, 'layouts'), \
20
12
  @project.root(:layouts)
21
- assert_same_file File.join(root_path, '_layouts', 'abc'), \
13
+ assert_same_file File.join(root_path, 'layouts', 'abc'), \
22
14
  @project.root(:layouts, 'abc')
23
15
  assert_same_file File.join(root_path, 'layouts', 'abc'), \
24
16
  @project.root('layouts', 'abc')
@@ -35,12 +27,39 @@ class TestHyde < Test::Unit::TestCase
35
27
  end
36
28
  end
37
29
 
30
+ should "load extensions" do
31
+ begin
32
+ CustomExtensionClass # Defined in the site's extensions/custom/custom.rb
33
+ rescue NameError
34
+ flunk "Extension wasn't loaded"
35
+ end
36
+ end
37
+
38
38
  should "use layouts" do
39
39
  output = @project.render 'layout_test.html'
40
40
  assert_match /This is the meta title/, output
41
41
  assert_match /<!-- \(default layout\) -->/, output
42
42
  end
43
43
 
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')
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/')
52
+ end
53
+
54
+ should "get types right" do
55
+ page = @project.get_page('index.html')
56
+ assert page.is_a? Hyde::Page
57
+
58
+ layout = Hyde::Layout.create 'default', @project
59
+ assert layout.is_a? Hyde::Layout
60
+ assert layout.is_a? Hyde::Page
61
+ end
62
+
44
63
  should "list the project files properly" do
45
64
  files = @project.files
46
65
  assert files.include? 'index.html'
data/test/test_page.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ class TestPage < Test::Unit::TestCase
4
+ def setup(site = 'default')
5
+ @project = get_project site
6
+ @page = @project.get_page 'index.html'
7
+ end
8
+
9
+ should "raise a method missing error" do
10
+ assert_raises NoMethodError do
11
+ @page.xxx
12
+ end
13
+
14
+ # Should NOT raise a method missing error
15
+ @page.layout
16
+ @page.filename
17
+ @page.renderer
18
+ @page.meta
19
+ @page.layout
20
+ @page.project
21
+ end
22
+
23
+ should "register the right project" do
24
+ assert_equal @project, @page.project
25
+ end
26
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydeweb
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- - pre
10
- version: 0.0.3.pre
8
+ - 4
9
+ version: 0.0.4
11
10
  platform: ruby
12
11
  authors:
13
12
  - Rico Sta. Cruz
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-05-04 00:00:00 +08:00
18
+ date: 2010-05-25 00:00:00 +08:00
20
19
  default_executable: hyde
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -73,6 +72,8 @@ extra_rdoc_files:
73
72
  files:
74
73
  - .gitignore
75
74
  - .yardopts
75
+ - AUTHORS
76
+ - CHANGELOG
76
77
  - LICENSE
77
78
  - README.md
78
79
  - Rakefile
@@ -83,14 +84,6 @@ files:
83
84
  - data/new_site/hyde.conf
84
85
  - data/new_site/layouts/default.haml
85
86
  - data/new_site/site/index.html.haml
86
- - docs/Extending/ExtendingHyde.md
87
- - docs/Hyde.md
88
- - docs/Introduction/Configuration.md
89
- - docs/Introduction/GettingStarted.md
90
- - docs/Introduction/Installation.md
91
- - docs/Introduction/Layouts.md
92
- - docs/Introduction/Partials.md
93
- - docs/Introduction/TemplateLanguages.md
94
87
  - hydeweb.gemspec
95
88
  - lib/hyde.rb
96
89
  - lib/hyde/clicommand.rb
@@ -100,14 +93,26 @@ files:
100
93
  - lib/hyde/layout.rb
101
94
  - lib/hyde/ostruct.rb
102
95
  - lib/hyde/page.rb
96
+ - lib/hyde/page_factory.rb
97
+ - lib/hyde/partial.rb
103
98
  - lib/hyde/project.rb
104
99
  - lib/hyde/renderer.rb
105
100
  - lib/hyde/renderers.rb
106
101
  - lib/hyde/utils.rb
102
+ - manual/Extending/ExtendingHyde.md
103
+ - manual/Hyde.md
104
+ - manual/Introduction/Configuration.md
105
+ - manual/Introduction/GettingStarted.md
106
+ - manual/Introduction/Installation.md
107
+ - manual/Introduction/Layouts.md
108
+ - manual/Introduction/Metadata.md
109
+ - manual/Introduction/Partials.md
110
+ - manual/Introduction/TemplateLanguages.md
107
111
  - test/fixtures/custom/_config.yml
108
112
  - test/fixtures/custom/extensions/custom/custom.rb
109
113
  - test/fixtures/custom/layouts/default.haml
110
114
  - test/fixtures/custom/layouts/erbtest.erb
115
+ - test/fixtures/custom/layouts/shared/sidebar.haml
111
116
  - test/fixtures/custom/site/about/index.html
112
117
  - test/fixtures/custom/site/assets/common.css.less
113
118
  - test/fixtures/custom/site/assets/style.css.less
@@ -127,6 +132,7 @@ files:
127
132
  - test/fixtures/custom/www_control/markdown.html
128
133
  - test/fixtures/custom/www_control/yes.html
129
134
  - test/fixtures/default/_config.yml
135
+ - test/fixtures/default/extensions/custom/custom.rb
130
136
  - test/fixtures/default/layouts/default.haml
131
137
  - test/fixtures/default/site/about/index.html
132
138
  - test/fixtures/default/site/foo.html.haml
@@ -142,6 +148,7 @@ files:
142
148
  - test/test_all_fixtures.rb
143
149
  - test/test_build.rb
144
150
  - test/test_hyde.rb
151
+ - test/test_page.rb
145
152
  - test/test_utils.rb
146
153
  has_rdoc: true
147
154
  homepage: http://github.com/sinefunc/hyde
@@ -161,13 +168,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
168
  version: "0"
162
169
  required_rubygems_version: !ruby/object:Gem::Requirement
163
170
  requirements:
164
- - - ">"
171
+ - - ">="
165
172
  - !ruby/object:Gem::Version
166
173
  segments:
167
- - 1
168
- - 3
169
- - 1
170
- version: 1.3.1
174
+ - 0
175
+ version: "0"
171
176
  requirements: []
172
177
 
173
178
  rubyforge_project:
@@ -177,8 +182,10 @@ specification_version: 3
177
182
  summary: Website preprocessor
178
183
  test_files:
179
184
  - test/fixtures/custom/extensions/custom/custom.rb
185
+ - test/fixtures/default/extensions/custom/custom.rb
180
186
  - test/helper.rb
181
187
  - test/test_all_fixtures.rb
182
188
  - test/test_build.rb
183
189
  - test/test_hyde.rb
190
+ - test/test_page.rb
184
191
  - test/test_utils.rb
data/docs/Hyde.md DELETED
@@ -1,17 +0,0 @@
1
- Hyde manual
2
- ===========
3
-
4
- Introduction
5
- ------------
6
-
7
- - `++++` {file:Installation Installation}
8
- - `++--` {file:GettingStarted Getting started}
9
- - `+---` {file:TemplateLanguages Template languages}
10
- - `----` {file:Layouts Layouts}
11
- - `----` {file:Partials Partials}
12
- - `----` {file:Configuration Configuration}
13
-
14
- Extending Hyde
15
- --------------
16
-
17
- - `+++-` {file:ExtendingHyde Extending Hyde}
@@ -1,32 +0,0 @@
1
- Getting started
2
- ===============
3
-
4
- Starting your first project
5
- ---------------------------
6
-
7
- Create your first project with:
8
-
9
- hyde create <name>
10
-
11
- Where `<name>` is the name of your project. This will create a folder with that
12
- name, along with some sample files to get you started.
13
-
14
- Starting
15
- --------
16
-
17
- hyde start
18
-
19
- Making your site files
20
- ----------------------
21
-
22
- Edit files under the `site` folder
23
-
24
- (todo)
25
-
26
- Building HTML files
27
- -------------------
28
-
29
- Build your files by typing
30
-
31
- hyde build
32
-
@@ -1,15 +0,0 @@
1
- Template languages
2
- ==================
3
-
4
- Hyde supports the following languages out-of-the-box:
5
-
6
- - HTML template languages
7
- - HAML
8
- - Markdown
9
- - Textile
10
- - ERB
11
- - CSS template languages
12
- - LessCSS
13
- - SASS
14
-
15
-
File without changes
File without changes