hydeweb 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -6
- data/data/new_site/config.ru +10 -0
- data/lib/hyde.rb +9 -1
- data/lib/hyde/cli.rb +4 -0
- data/lib/hyde/config.rb +32 -7
- data/lib/hyde/helpers.rb +92 -2
- data/lib/hyde/meta.rb +5 -0
- data/lib/hyde/page.rb +4 -1
- data/lib/hyde/project.rb +45 -16
- data/lib/hyde/server.rb +3 -0
- data/lib/hyde/set.rb +12 -3
- data/lib/hyde/version.rb +7 -1
- metadata +2 -2
data/Rakefile
CHANGED
data/data/new_site/config.ru
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# This file exists to make this project Rack-compatible.
|
2
2
|
# You may delete it if you're not concerned about this.
|
3
3
|
|
4
|
+
if File.file?('Gemfile') && File.file?('Gemfile.lock')
|
5
|
+
# Use Bundler to load hydeweb, if a Gemfile is around.
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.setup
|
8
|
+
else
|
9
|
+
# Else, just go Rubygems.
|
10
|
+
require 'rubygems' unless defined?(::Gem)
|
11
|
+
gem 'hydeweb', '~> 0.2.0'
|
12
|
+
end
|
13
|
+
|
4
14
|
require 'hyde'
|
5
15
|
require 'hyde/server'
|
6
16
|
|
data/lib/hyde.rb
CHANGED
@@ -13,6 +13,9 @@ Encoding.default_external = 'utf-8' if defined?(::Encoding)
|
|
13
13
|
# HTML files as ERB
|
14
14
|
Tilt.mappings['html'] = Tilt.mappings['erb']
|
15
15
|
|
16
|
+
# Class: Hyde
|
17
|
+
# The Hyde class.
|
18
|
+
|
16
19
|
class Hyde
|
17
20
|
PREFIX = File.expand_path('../', __FILE__)
|
18
21
|
|
@@ -36,7 +39,12 @@ class Hyde
|
|
36
39
|
require "#{PREFIX}/hyde/version"
|
37
40
|
|
38
41
|
class << self
|
39
|
-
#
|
42
|
+
# Attribute: project (Hyde)
|
43
|
+
# Returns the latest project.
|
44
|
+
#
|
45
|
+
# ## Example
|
46
|
+
# Hyde.project.path(:site)
|
47
|
+
|
40
48
|
attr_accessor :project
|
41
49
|
end
|
42
50
|
end
|
data/lib/hyde/cli.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# Class: Hyde::CLI (Hyde)
|
2
|
+
# Command line runner.
|
3
|
+
|
1
4
|
class Hyde
|
2
5
|
class CLI < Shake
|
3
6
|
autoload :Helpers, "#{PREFIX}/hyde/cli/helpers"
|
@@ -192,6 +195,7 @@ class CLI < Shake
|
|
192
195
|
|
193
196
|
def self.run!(options={})
|
194
197
|
@hydefile = options[:file]
|
198
|
+
project rescue nil
|
195
199
|
super *[]
|
196
200
|
end
|
197
201
|
end
|
data/lib/hyde/config.rb
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
class Hyde
|
2
|
+
# Class: Hyde::Config
|
2
3
|
# Configuration.
|
3
4
|
#
|
4
|
-
#
|
5
|
+
# ## Common usage
|
5
6
|
#
|
6
|
-
#
|
7
|
-
# Hyde.project.config.tilt_options('sass')[:load_path]
|
7
|
+
# Access it via `Hyde.project`.
|
8
8
|
#
|
9
|
-
#
|
10
|
-
#
|
9
|
+
# Hyde.project.config
|
10
|
+
#
|
11
|
+
# You may access config variables as attributes.
|
12
|
+
#
|
13
|
+
# Hyde.project.config.site_path
|
14
|
+
# Hyde.project.config.layouts_path
|
15
|
+
# Hyde.project.config.extensions_path
|
16
|
+
# Hyde.project.config.output_path
|
17
|
+
#
|
18
|
+
# Tilt options:
|
19
|
+
#
|
20
|
+
# Hyde.project.config.tilt_options('sass')[:load_path]
|
21
|
+
# Hyde.project.config.tilt_options_for('filename.haml')[:style]
|
11
22
|
#
|
12
23
|
class Config
|
13
24
|
DEFAULTS = {
|
@@ -60,8 +71,15 @@ class Config
|
|
60
71
|
@table.send meth, *args
|
61
72
|
end
|
62
73
|
|
74
|
+
# Method: tilt_options_for (Hyde::Config)
|
63
75
|
# Returns tilt options for a given file.
|
64
|
-
#
|
76
|
+
#
|
77
|
+
# ## Usage
|
78
|
+
# tilt_options_for(filename, options={})
|
79
|
+
#
|
80
|
+
# ## Example
|
81
|
+
# tilt_options_for('index.haml') # { :escape_html => ... }
|
82
|
+
#
|
65
83
|
def tilt_options_for(file, options={})
|
66
84
|
ext = file.split('.').last.downcase
|
67
85
|
opts = tilt_options(ext) || Hash.new
|
@@ -70,8 +88,15 @@ class Config
|
|
70
88
|
to_hash opts
|
71
89
|
end
|
72
90
|
|
91
|
+
# Method: tilt_options (Hyde::Config)
|
73
92
|
# Returns tilt options for a given engine.
|
74
|
-
#
|
93
|
+
#
|
94
|
+
# ## Usage
|
95
|
+
# tilt_options(engine_name)
|
96
|
+
#
|
97
|
+
# ## Example
|
98
|
+
# tilt_options('haml') # { :escape_html => ... }
|
99
|
+
#
|
75
100
|
def tilt_options(what, key=:tilt_options)
|
76
101
|
@table[key] ||= Hash.new
|
77
102
|
@table[key][what.to_s] ||= Hash.new
|
data/lib/hyde/helpers.rb
CHANGED
@@ -1,16 +1,84 @@
|
|
1
|
+
# Module: Hyde::Helpers (Hyde)
|
2
|
+
# Helpers you can use in your pages.
|
3
|
+
#
|
4
|
+
# ## Creating your own helpers
|
5
|
+
# To create for own helpers, make an extension. See [Extending Hyde:
|
6
|
+
# Helpers][1] for more info.
|
7
|
+
#
|
8
|
+
# [1]: /extending/helpers.html
|
9
|
+
|
1
10
|
class Hyde
|
2
11
|
module Helpers
|
12
|
+
|
13
|
+
# Method: partial (Hyde::Helpers)
|
14
|
+
# Renders a partial.
|
15
|
+
#
|
16
|
+
# ## Usage
|
17
|
+
# <%= partial path, locals %>
|
18
|
+
#
|
19
|
+
# ## Description
|
20
|
+
# See [Introduction: Partials](/introduction/partials.html) for more
|
21
|
+
# info.
|
22
|
+
#
|
23
|
+
# ## Example
|
24
|
+
#
|
25
|
+
# If your `_layouts/_banner.erb` looks like this:
|
26
|
+
#
|
27
|
+
# <div class='banner'>
|
28
|
+
# Welcome to <%= start.title %>
|
29
|
+
# </div>
|
30
|
+
#
|
31
|
+
# ...Then this will embed the partial `_layouts/_nav.erb`. The partial
|
32
|
+
# will be rendered with `start` being set to the current page.
|
33
|
+
#
|
34
|
+
# <%= partial '_banner', :start => page %>
|
35
|
+
#
|
3
36
|
def partial(path, locals={})
|
4
37
|
partial = Partial[path.to_s, page] or return ''
|
5
38
|
partial.to_html locals.merge(:page => self)
|
6
39
|
end
|
7
40
|
|
41
|
+
# Method: rel (Hyde::Helpers)
|
42
|
+
# Turns a path into a relative path.
|
43
|
+
#
|
44
|
+
# ## Usage
|
45
|
+
# <%= rel(path) %>
|
46
|
+
#
|
47
|
+
# ## Description
|
48
|
+
# `rel` takes a given absolute path that begins with a `/` (for instance,
|
49
|
+
# `/x/y/z.html`) and returns a relative path (maybe `../y/z.html`). This is
|
50
|
+
# useful if your site will not be be hosted on it's own domain.
|
51
|
+
#
|
52
|
+
# ## Example
|
53
|
+
# <% page.children.each do |child| %>
|
54
|
+
# <a href="<%= rel(child.path) %>">
|
55
|
+
# <%= child.title %>
|
56
|
+
# </a>
|
57
|
+
# <% end %>
|
58
|
+
#
|
59
|
+
# This may output:
|
60
|
+
#
|
61
|
+
# <a href="../../foo.html">
|
62
|
+
# Foobar
|
63
|
+
# </a>
|
64
|
+
#
|
65
|
+
# ...where the `../../` depends on the current page's path.
|
66
|
+
#
|
8
67
|
def rel(path)
|
9
|
-
depth = page.
|
10
|
-
dotdot = depth > 1 ? ('../' * (
|
68
|
+
depth = page.path.count('/')
|
69
|
+
dotdot = depth > 1 ? ('../' * (depth-1)) : './'
|
11
70
|
(dotdot[0...-1] + path)
|
12
71
|
end
|
13
72
|
|
73
|
+
# Method: content_for (Hyde::Helpers)
|
74
|
+
# Content for.
|
75
|
+
#
|
76
|
+
# ## See also
|
77
|
+
#
|
78
|
+
# * {Hyde::Helpers::has_content?}
|
79
|
+
# * {Hyde::Helpers::content_for}
|
80
|
+
# * {Hyde::Helpers::yield_content}
|
81
|
+
#
|
14
82
|
def content_for(key, &blk)
|
15
83
|
content_blocks[key.to_sym] = blk
|
16
84
|
end
|
@@ -20,10 +88,32 @@ module Helpers
|
|
20
88
|
$content_blocks[page.path] ||= Hash.new
|
21
89
|
end
|
22
90
|
|
91
|
+
# Method: has_content? (Hyde::Helpers)
|
92
|
+
# Checks if there's something defined for a given content block.
|
93
|
+
#
|
94
|
+
# ## Example
|
95
|
+
# See {Hyde::Helpers::content_for} for an example.
|
96
|
+
#
|
97
|
+
# ## See also
|
98
|
+
# * {Hyde::Helpers::has_content?}
|
99
|
+
# * {Hyde::Helpers::content_for}
|
100
|
+
# * {Hyde::Helpers::yield_content}
|
101
|
+
#
|
23
102
|
def has_content?(key)
|
24
103
|
content_blocks.member? key.to_sym
|
25
104
|
end
|
26
105
|
|
106
|
+
# Method: yield_content (Hyde::Helpers)
|
107
|
+
# Yield
|
108
|
+
#
|
109
|
+
# ## Example
|
110
|
+
# See {Hyde::Helpers::content_for} for an example.
|
111
|
+
#
|
112
|
+
# ## See also
|
113
|
+
# * {Hyde::Helpers::has_content?}
|
114
|
+
# * {Hyde::Helpers::content_for}
|
115
|
+
# * {Hyde::Helpers::yield_content}
|
116
|
+
#
|
27
117
|
def yield_content(key, *args)
|
28
118
|
content = content_blocks[key.to_sym]
|
29
119
|
if respond_to?(:block_is_haml?) && block_is_haml?(content)
|
data/lib/hyde/meta.rb
CHANGED
data/lib/hyde/page.rb
CHANGED
@@ -298,7 +298,10 @@ class Page
|
|
298
298
|
File.expand_path("../#{base}/*", @file)
|
299
299
|
end
|
300
300
|
|
301
|
-
Set.new Dir[files].
|
301
|
+
Set.new Dir[files].
|
302
|
+
reject { |f| f == @file || project.ignored_files.include?(f) }.
|
303
|
+
map { |f| self.class[f, project] }.
|
304
|
+
compact.sort
|
302
305
|
end
|
303
306
|
|
304
307
|
def siblings
|
data/lib/hyde/project.rb
CHANGED
@@ -1,39 +1,42 @@
|
|
1
1
|
class Hyde
|
2
|
+
# Class: Hyde::Project
|
2
3
|
# A project.
|
3
4
|
#
|
5
|
+
# ## Common usage
|
6
|
+
#
|
4
7
|
# Instanciating:
|
5
8
|
#
|
6
|
-
#
|
7
|
-
#
|
9
|
+
# project = Project.new('~/spur')
|
10
|
+
# project == Hyde.project # the last defined project
|
8
11
|
#
|
9
12
|
# Building:
|
10
13
|
#
|
11
|
-
#
|
12
|
-
#
|
14
|
+
# project.build
|
15
|
+
# project.build { |file| puts "Building #{file}..." }
|
13
16
|
#
|
14
17
|
# Getting pages:
|
15
18
|
#
|
16
|
-
#
|
19
|
+
# Hyde::Page['/index.html'] # ~/spur/index.md; uses Hyde.project
|
17
20
|
#
|
18
21
|
# Configuration:
|
19
22
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
+
# project.config_file # ~/spur/hyde.conf
|
24
|
+
# project.config # Config from above file (OpenStruct)
|
25
|
+
# project.config.site_path
|
23
26
|
#
|
24
27
|
# Paths:
|
25
28
|
#
|
26
|
-
#
|
27
|
-
#
|
29
|
+
# project.path(:site) # ~/spur/site (based on config site_path)
|
30
|
+
# project.path(:extensions)
|
28
31
|
#
|
29
|
-
#
|
32
|
+
# project.root('a/b', 'c') # ~/spur/a/b/c
|
30
33
|
#
|
31
34
|
# Indexing:
|
32
35
|
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
36
|
+
# project.pages # [<#Page>, <#Page>, ...]
|
37
|
+
# project.files # ['/index.md', '/style.sass', ...]
|
38
|
+
# # (only site files)
|
39
|
+
# project.ignored_files
|
37
40
|
#
|
38
41
|
class Project
|
39
42
|
def initialize(root=Dir.pwd)
|
@@ -69,6 +72,9 @@ class Project
|
|
69
72
|
).sort.each { |f| require f } if path
|
70
73
|
end
|
71
74
|
|
75
|
+
# Method: config_file (Hyde::Project)
|
76
|
+
# Returns the configuration file for the project.
|
77
|
+
|
72
78
|
def config_file
|
73
79
|
try = lambda { |path| p = root(path); p if File.file?(p) }
|
74
80
|
try['hyde.conf'] || try['.hyderc']
|
@@ -78,26 +84,43 @@ class Project
|
|
78
84
|
config_file
|
79
85
|
end
|
80
86
|
|
87
|
+
# Method: config (Hyde::Project)
|
88
|
+
# Returns a Hyde::Config instance.
|
89
|
+
|
81
90
|
def config
|
82
91
|
@config ||= Config.load(config_file)
|
83
92
|
end
|
84
93
|
|
94
|
+
# Method: path (Hyde::Project)
|
85
95
|
# Returns the path for a certain aspect.
|
86
|
-
#
|
96
|
+
#
|
97
|
+
# ## Example
|
98
|
+
#
|
99
|
+
# Hyde.project.path(:site)
|
100
|
+
#
|
87
101
|
def path(what, *a)
|
88
102
|
return nil unless [:output, :site, :layouts, :extensions, :partials].include?(what)
|
89
103
|
path = config.send(:"#{what}_path")
|
90
104
|
root path, *a if path
|
91
105
|
end
|
92
106
|
|
107
|
+
# Method: root (Hyde::Project)
|
108
|
+
# Returns the root path of the project.
|
109
|
+
|
93
110
|
def root(*args)
|
94
111
|
File.join @root, *(args.compact)
|
95
112
|
end
|
96
113
|
|
114
|
+
# Method: pages (Hyde::Project)
|
115
|
+
# Returns the pages for the project.
|
116
|
+
|
97
117
|
def pages
|
98
118
|
files.map { |f| Page[f, self] }.compact
|
99
119
|
end
|
100
120
|
|
121
|
+
# Method: files (Hyde::Project)
|
122
|
+
# Returns the site files for the project, free from the ignored files.
|
123
|
+
|
101
124
|
def files
|
102
125
|
files = Dir[File.join(path(:site), '**', '*')]
|
103
126
|
files = files.select { |f| File.file?(f) }
|
@@ -105,6 +128,9 @@ class Project
|
|
105
128
|
files - ignored_files
|
106
129
|
end
|
107
130
|
|
131
|
+
# Method: ignored_files (Hyde::Project)
|
132
|
+
# Returns the files to be ignored for the project.
|
133
|
+
|
108
134
|
def ignored_files
|
109
135
|
specs = [*config.ignore].map { |s| root(s) }
|
110
136
|
specs << config_file
|
@@ -120,6 +146,9 @@ class Project
|
|
120
146
|
specs.compact.map { |s| glob(s) }.flatten.uniq
|
121
147
|
end
|
122
148
|
|
149
|
+
# Method: build (Hyde::Project)
|
150
|
+
# Builds.
|
151
|
+
|
123
152
|
def build(&blk)
|
124
153
|
pages.each do |page|
|
125
154
|
yield page
|
data/lib/hyde/server.rb
CHANGED
data/lib/hyde/set.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# Class: Hyde::Set
|
2
|
+
# A set of pages.
|
3
|
+
|
1
4
|
class Hyde
|
2
5
|
class Set < Array
|
6
|
+
# Method: find (Hyde::Set)
|
3
7
|
# Filters a set by given metadata criteria.
|
4
8
|
#
|
5
|
-
#
|
6
|
-
#
|
9
|
+
# ## Example
|
10
|
+
# Page['/'].children.find(layout: 'default')
|
7
11
|
#
|
8
12
|
def find(by={})
|
9
13
|
self.class.new(select do |page|
|
@@ -11,8 +15,13 @@ class Set < Array
|
|
11
15
|
end)
|
12
16
|
end
|
13
17
|
|
18
|
+
# Method: except (Hyde::Set)
|
14
19
|
# Filters a set by removing items matching the given metadata criteria.
|
15
|
-
#
|
20
|
+
#
|
21
|
+
# This is the opposite of {Hyde::Set::find}.
|
22
|
+
#
|
23
|
+
# ## Example
|
24
|
+
# Page['/'].children.find(layout: 'default')
|
16
25
|
#
|
17
26
|
def except(by={})
|
18
27
|
self.class.new(reject do |page|
|
data/lib/hyde/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: hydeweb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Rico Sta. Cruz
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-20 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|