hydeweb 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,13 @@
1
+ v0.1.1
2
+ ------
3
+
4
+ - Default project is now simpler. The site_path is `.`.
5
+ - Implement `Project#build`.
6
+ - If YAML parsing of page metadata fails, treat it as content.
7
+ - All options in `hyde.conf` are now optional (even `hyde_requirement`).
8
+ - Page metadata can now only be a hash.
9
+ - Fix `hyde start`.
10
+
1
11
  v0.1.0
2
12
  ------
3
13
 
data/Rakefile CHANGED
@@ -3,3 +3,9 @@ task :test do
3
3
  end
4
4
 
5
5
  task :default => :test
6
+
7
+ task :gembuild do
8
+ require './lib/hyde'
9
+ v = Hyde.version
10
+ system "joe build && git commit -a -m \"Update to version #{v}.\" && git tag v#{v}"
11
+ end
@@ -1,32 +1,23 @@
1
1
  # This is a Hyde site.
2
2
  # Install the `hydeweb` Ruby gem and type `hyde` for help.
3
-
4
3
  hyde_requirement: 0.1
5
4
 
6
- # Path options
7
- # -------------
8
-
9
- # The folder where the site's main files are kept. (you can set this to '.')
10
- site_path: site
11
-
12
- # The folder where the layout templates (and partials) are kept.
13
- layouts_path: layouts
14
-
15
- # The folder where the optional extensions are kept.
16
- extensions_path: extensions
17
-
18
- # The folder for partials.
19
- partials_path: layouts
5
+ # The folder where the site's source files are kept.
6
+ site_path: .
7
+ output_path: _public
20
8
 
21
- # The folder where the HTML files are to be built when typing `hyde build`.
22
- output_path: public
9
+ # Other paths:
10
+ layouts_path: _layouts
11
+ extensions_path: _extensions
12
+ partials_path: _layouts
23
13
 
24
- # Any files matching these in the site_path will be excluded.
14
+ # Files to be excluded from processing
25
15
  ignore:
26
16
  - **/*~
17
+ - README*
27
18
  - **/_*.scss
28
19
 
29
- # Specify engine options here. These are optional.
20
+ # Optional options for layout engines
30
21
  tilt_options:
31
22
  haml:
32
23
  :escape_html: true
data/lib/hyde/cli.rb CHANGED
@@ -41,22 +41,25 @@ class CLI < Shake
41
41
  pre = project.config.output_path
42
42
 
43
43
  begin
44
- project.pages.each { |page|
44
+ project.build { |page|
45
45
  handler = ''
46
46
  handler = "(#{page.tilt_engine_name})" if page.tilt?
47
47
  puts ("\033[0;33m*\033[0;32m #{pre}\033[0;m%-50s%s" % [ page.path, handler ]).strip
48
- page.write
49
48
  }
50
49
  rescue NoGemError => e
51
50
  err "Error: #{e.message}"
51
+ rescue Error => e
52
+ err "Error: #{e.message}"
52
53
  ensure
53
- project.build_cleanup
54
+ project.send :build_cleanup
54
55
  end
55
56
  end
56
57
 
57
58
  task.description = "Builds the current project"
58
59
 
59
60
  task(:start) do
61
+ project
62
+
60
63
  port = (params.extract('-p') || 4833).to_i
61
64
  host = (params.extract('-o') || '0.0.0.0')
62
65
 
data/lib/hyde/config.rb CHANGED
@@ -2,10 +2,10 @@ class Hyde
2
2
  class Config < OpenStruct
3
3
  DEFAULTS = {
4
4
  :site_path => '.',
5
- :layouts_path => 'layouts',
5
+ :layouts_path => nil,
6
6
  :extensions_path => nil,
7
- :partials_path => 'partials',
8
- :output_path => 'public'
7
+ :partials_path => nil,
8
+ :output_path => nil
9
9
  }
10
10
 
11
11
  def self.load(config_file)
data/lib/hyde/page.rb CHANGED
@@ -3,9 +3,44 @@ class Page
3
3
  attr_reader :project
4
4
  attr_reader :file
5
5
 
6
+ def self.[](id, project=$project)
7
+ site_path = root_path(project)
8
+ return nil if site_path.nil?
9
+
10
+ site = lambda { |*x| File.join site_path, *(x.compact) }
11
+ try = lambda { |id| p = new(id, project); p if p.exists? }
12
+
13
+ # Account for:
14
+ # ~/mysite/site/about/us.html.haml
15
+ # about/us.html.haml => ~/mysite/site/about/us.html.haml
16
+ # about/us.html => ~/mysite/site/about/us.html.*
17
+ # about/us.html => ~/mysite/site/about/us.*
18
+ # about/us => ~/mysite/site/about/us/index.*
19
+ #
20
+ page = try[id]
21
+ page ||= try[site[id]]
22
+ page ||= try[Dir[site["#{id}.*"]].first]
23
+ page ||= try[Dir[site["#{id.to_s.sub(/\.[^\.]*/,'')}.*"]].first]
24
+ page ||= try[Dir[site[id, "index.*"]].first]
25
+
26
+ # Subclass
27
+ if page && page.tilt? && page.meta.type
28
+ klass = Page.get_type(page.meta.type)
29
+ raise Error, "#{page.filepath}: Class for type '#{page.meta.type}' not found" unless klass
30
+ page = klass.new(id, project)
31
+ end
32
+ page
33
+ end
34
+
35
+ def initialize(file, project=$project)
36
+ @file = File.expand_path(file) if file.is_a?(String)
37
+ @project = project
38
+ raise Error if project.nil?
39
+ end
40
+
6
41
  # Returns the URL path for a page.
7
42
  def path
8
- path = @file.sub(root_path, '')
43
+ path = @file.sub(File.expand_path(root_path), '')
9
44
 
10
45
  # if xx.haml (but not xx.html.haml),
11
46
  if tilt?
@@ -16,6 +51,14 @@ class Page
16
51
  path
17
52
  end
18
53
 
54
+ # Returns a short filepath relative to the project path
55
+ def filepath
56
+ root = project.root
57
+ fpath = file
58
+ fpath = fpath[root.size..-1] if fpath[0...root.size] == root
59
+ fpath
60
+ end
61
+
19
62
  def title
20
63
  (meta.title if tilt?) || path
21
64
  end
@@ -58,32 +101,6 @@ class Page
58
101
  end
59
102
  end
60
103
 
61
- def self.[](id, project=$project)
62
- site = lambda { |*x| File.join root_path(project), *(x.compact) }
63
- try = lambda { |id| p = new(id, project); p if p.exists? }
64
-
65
- # Account for:
66
- # ~/mysite/site/about/us.html.haml
67
- # about/us.html.haml => ~/mysite/site/about/us.html.haml
68
- # about/us.html => ~/mysite/site/about/us.html.*
69
- # about/us.html => ~/mysite/site/about/us.*
70
- # about/us => ~/mysite/site/about/us/index.*
71
- #
72
- page = try[id]
73
- page ||= try[site[id]]
74
- page ||= try[Dir[site["#{id}.*"]].first]
75
- page ||= try[Dir[site["#{id.to_s.sub(/\.[^\.]*/,'')}.*"]].first]
76
- page ||= try[Dir[site[id, "index.*"]].first]
77
-
78
- # Subclass
79
- if page && page.tilt? && page.meta.type
80
- klass = Page.get_type(page.meta.type)
81
- raise Error, "Class for type '#{page.meta.type}' not found" unless klass
82
- page = klass.new(id, project)
83
- end
84
- page
85
- end
86
-
87
104
  # Returns a page subtype.
88
105
  # @example Page.get_type('post') => Hyde::Page::Post
89
106
  def self.get_type(type)
@@ -92,12 +109,6 @@ class Page
92
109
  self.const_get(klass) if self.const_defined?(klass)
93
110
  end
94
111
 
95
- def initialize(file, project=$project)
96
- @file = file
97
- @project = project
98
- raise Error if project.nil?
99
- end
100
-
101
112
  def exists?
102
113
  @file and File.file?(@file) and valid?
103
114
  end
@@ -139,7 +150,7 @@ class Page
139
150
  end
140
151
 
141
152
  def meta
142
- @meta ||= Meta.new(YAML::load(parts.first))
153
+ @meta ||= Meta.new(parts.first)
143
154
  end
144
155
 
145
156
  # Writes to the given output file.
@@ -242,7 +253,16 @@ protected
242
253
  @parts ||= begin
243
254
  t = File.open(@file).read.force_encoding('UTF-8')
244
255
  m = t.match(/^(.*)--+\n(.*)$/m)
245
- m.nil? ? ['', t] : [m[1], m[2]]
256
+
257
+ if m.nil?
258
+ [{}, t]
259
+ else
260
+ data = YAML::load(m[1])
261
+ raise ArgumentError unless data.is_a?(Hash)
262
+ [data, m[2]]
263
+ end
264
+ rescue ArgumentError
265
+ [{}, t]
246
266
  end
247
267
  end
248
268
 
data/lib/hyde/project.rb CHANGED
@@ -11,7 +11,8 @@ class Project
11
11
  def validate_version
12
12
  return unless config_file?
13
13
  req = config.hyde_requirement.to_s
14
- if req < "0.1"
14
+ if req.empty?
15
+ elsif req < "0.1"
15
16
  raise LegacyError, "This is a legacy project"
16
17
  elsif req > Hyde.version
17
18
  raise VersionError, "You will need Hyde version >= #{req} for this project."
@@ -53,7 +54,10 @@ class Project
53
54
  end
54
55
 
55
56
  def files
56
- Dir[File.join(path(:site), '**', '*')] - ignored_files
57
+ files = Dir[File.join(path(:site), '**', '*')]
58
+ files = files.select { |f| File.file?(f) }
59
+ files = files.map { |f| File.expand_path(f) }
60
+ files - ignored_files
57
61
  end
58
62
 
59
63
  def ignored_files
@@ -65,6 +69,16 @@ class Project
65
69
  specs.compact.map { |s| Dir[s] }.flatten.uniq
66
70
  end
67
71
 
72
+ def build(&blk)
73
+ pages.each do |page|
74
+ yield page
75
+ page.write
76
+ end
77
+ ensure
78
+ build_cleanup
79
+ end
80
+
81
+ protected
68
82
  def build_cleanup
69
83
  FileUtils.rm_rf '.sass_cache'
70
84
  end
data/lib/hyde/server.rb CHANGED
@@ -21,7 +21,7 @@ class Hyde
21
21
  status = page ? "\033[0;32m[ OK ]" : "\033[0;31m[404 ]"
22
22
  verb = get ? 'GET ' : (post ? 'POST' : '')
23
23
  puts "%s\033[0;m %s %s" % [ status, verb, env['PATH_INFO'] ]
24
- puts " Source: #{page.file.sub(page.project.path(:site), '')} (#{page.tilt_engine_name})" if page.tilt?
24
+ puts " src: #{page.filepath} (#{page.tilt_engine_name})" if page.tilt?
25
25
  end
26
26
  end
27
27
 
@@ -30,9 +30,14 @@ class Hyde
30
30
 
31
31
  define do
32
32
  on default do
33
- page = Hyde::Page[env['PATH_INFO']] or break not_found
34
- res.write page.to_html
35
- show_status page
33
+ begin
34
+ page = Hyde::Page[env['PATH_INFO']] or break not_found
35
+ res['Content-Type'] = page.mime_type
36
+ res.write page.to_html
37
+ show_status page
38
+ rescue => e
39
+ res.write "<h1>#{e.class}: #{e.message}</h1><ul>#{e.backtrace.map{|l|"<li>#{l}</li>"}.join('')}</ul>"
40
+ end
36
41
  end
37
42
  end
38
43
  end
data/lib/hyde.rb CHANGED
@@ -9,7 +9,7 @@ require 'tilt'
9
9
  require 'shake'
10
10
 
11
11
  class Hyde
12
- VERSION = "0.1.0"
12
+ VERSION = "0.1.1"
13
13
  PREFIX = File.expand_path('../', __FILE__)
14
14
 
15
15
  Error = Class.new(StandardError)
@@ -1,6 +1,7 @@
1
1
  hyde_requirement: 0.1
2
2
  site_path: site
3
3
  extensions_path: extensions
4
+ layouts_path: layouts
4
5
  output_path: public
5
6
  ignore:
6
7
  - **/*~
@@ -2,6 +2,7 @@ hyde_requirement: 0.1
2
2
  site_path: site
3
3
  extensions_path: extensions
4
4
  output_path: public
5
+ layouts_path: layouts
5
6
  ignore:
6
7
  - **/*~
7
8
  - **/compass/**/*
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hydeweb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz
@@ -141,10 +141,10 @@ files:
141
141
  - test/unit/extensions_test.rb
142
142
  - test/unit/fixture_test.rb
143
143
  - test/unit/hyde_test.rb
144
+ - data/new_site/_layouts/default.haml
144
145
  - data/new_site/hyde.conf
145
- - data/new_site/layouts/default.haml
146
+ - data/new_site/index.haml
146
147
  - data/new_site/README.md
147
- - data/new_site/site/index.html.haml
148
148
  - HISTORY.md
149
149
  - README.md
150
150
  - Rakefile
File without changes
File without changes