pekky 0.1 → 0.2
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.
- data/README +6 -2
- data/lib/pekky/builder.rb +1 -0
- data/lib/pekky/context.rb +32 -2
- data/lib/pekky/pages.rb +20 -2
- data/lib/pekky/site_config.rb +4 -0
- data/lib/pekky/tree.rb +9 -1
- metadata +3 -3
data/README
CHANGED
@@ -35,8 +35,12 @@
|
|
35
35
|
|
36
36
|
TODO
|
37
37
|
* Get specs up to speed
|
38
|
-
*
|
39
|
-
*
|
38
|
+
* Add the option of naming pages
|
39
|
+
* Support shared content
|
40
|
+
* Add helpers for slurping up a collection of shared content i.e. news feed
|
41
|
+
* Support alternate formats correctly
|
42
|
+
* Compile stylesheets with less or sass
|
43
|
+
* Compile javascripts with Coffee
|
40
44
|
|
41
45
|
|
42
46
|
CAVEATS
|
data/lib/pekky/builder.rb
CHANGED
data/lib/pekky/context.rb
CHANGED
@@ -2,11 +2,37 @@ module Pekky
|
|
2
2
|
class Context
|
3
3
|
attr_writer :view_output, :is_layout
|
4
4
|
|
5
|
+
@shared = {}
|
6
|
+
|
7
|
+
def self.flush!
|
8
|
+
@shared.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.get(name, sort)
|
12
|
+
@shared[name] ||= begin
|
13
|
+
path = File.join(SiteConfig[:content_dir], name)
|
14
|
+
if File.directory?(path)
|
15
|
+
collection = Dir[path + '/*.yml'].inject([]) do |a, y|
|
16
|
+
a << YAML.load_file(y)
|
17
|
+
a
|
18
|
+
end
|
19
|
+
collection.sort! {|a, b| a[sort] <=> b[sort]} if sort
|
20
|
+
collection
|
21
|
+
else
|
22
|
+
YAML.load_file(path + ".yml")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
5
27
|
def initialize(page)
|
6
28
|
@page = page
|
7
29
|
@is_layout = false
|
8
30
|
end
|
9
31
|
|
32
|
+
def get(name, sort = nil)
|
33
|
+
self.class.get(name, sort)
|
34
|
+
end
|
35
|
+
|
10
36
|
def config
|
11
37
|
SiteConfig
|
12
38
|
end
|
@@ -98,7 +124,7 @@ module Pekky
|
|
98
124
|
end
|
99
125
|
|
100
126
|
def qualify_path(path)
|
101
|
-
if Pekky.exporting? and SiteConfig[:path_prefix]
|
127
|
+
if !path.match(/^http/) and Pekky.exporting? and SiteConfig[:path_prefix]
|
102
128
|
SiteConfig[:path_prefix] + path
|
103
129
|
else
|
104
130
|
path
|
@@ -108,7 +134,11 @@ module Pekky
|
|
108
134
|
def nav
|
109
135
|
Pekky.tree.pages.reject {|p| p.hidden? }
|
110
136
|
end
|
111
|
-
|
137
|
+
|
138
|
+
def page(name)
|
139
|
+
Pekky.tree[name]
|
140
|
+
end
|
141
|
+
|
112
142
|
def pages
|
113
143
|
Pekky.tree.pages
|
114
144
|
end
|
data/lib/pekky/pages.rb
CHANGED
@@ -12,13 +12,23 @@ module Pekky
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Page
|
15
|
-
attr_reader :path, :children, :content, :opts, :file_name
|
15
|
+
attr_reader :path, :children, :content, :opts, :file_name, :name
|
16
16
|
attr_accessor :parent
|
17
17
|
|
18
18
|
def initialize(path, content, opts)
|
19
19
|
@path = path
|
20
20
|
@opts = opts
|
21
21
|
|
22
|
+
# Calculate a name for the page
|
23
|
+
@name = if opts[:name]
|
24
|
+
opts.delete(:name).to_sym
|
25
|
+
elsif path == '/'
|
26
|
+
:root
|
27
|
+
else
|
28
|
+
|
29
|
+
path.match(/^\/(\S+)/)[1].gsub(/[\/\-]/, '_').to_sym
|
30
|
+
end
|
31
|
+
|
22
32
|
@content = if content.is_a? String
|
23
33
|
content_path = File.join(SiteConfig[:content_dir], "#{content}.yml")
|
24
34
|
YAML.load_file(content_path)
|
@@ -90,9 +100,11 @@ module Pekky
|
|
90
100
|
@pages
|
91
101
|
end
|
92
102
|
|
93
|
-
def render(template, opts)
|
103
|
+
def render(template, opts = {})
|
94
104
|
content = opts[:content] || {}
|
95
105
|
|
106
|
+
opts[:view] = template
|
107
|
+
|
96
108
|
path = @path.dup
|
97
109
|
@path_params.each do |p|
|
98
110
|
path.gsub!(/:#{p}/, opts[p.to_sym].to_s)
|
@@ -100,5 +112,11 @@ module Pekky
|
|
100
112
|
|
101
113
|
@pages << Page.new(path, content, opts)
|
102
114
|
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def get(name, sort = nil)
|
119
|
+
Context.get(name, sort)
|
120
|
+
end
|
103
121
|
end
|
104
122
|
end
|
data/lib/pekky/site_config.rb
CHANGED
data/lib/pekky/tree.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
module Pekky
|
2
2
|
module Tree
|
3
3
|
@pages = []
|
4
|
+
@map = {}
|
5
|
+
|
6
|
+
def self.[](name)
|
7
|
+
@map[name]
|
8
|
+
end
|
4
9
|
|
5
10
|
def self.pages
|
6
11
|
@pages
|
@@ -8,7 +13,10 @@ module Pekky
|
|
8
13
|
|
9
14
|
def self.add(pages)
|
10
15
|
@pages.clear
|
11
|
-
pages.each
|
16
|
+
pages.each do |p|
|
17
|
+
@map[p.name] = p
|
18
|
+
add_to_tree(p, pages)
|
19
|
+
end
|
12
20
|
end
|
13
21
|
|
14
22
|
private
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 2
|
8
|
+
version: "0.2"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Luke Matthew Sutton
|
@@ -80,6 +80,6 @@ rubyforge_project:
|
|
80
80
|
rubygems_version: 1.3.6
|
81
81
|
signing_key:
|
82
82
|
specification_version: 2
|
83
|
-
summary:
|
83
|
+
summary: "Pekky\xE2\x80\x99s main strengths come from the fact that it chooses explicitness over magic, that it\xE2\x80\x99s defaults are configurable and that it doesn\xE2\x80\x99t assume all content is derived from files on disk. For example Pekky can generate pages from databases, CSV files or web API calls."
|
84
84
|
test_files: []
|
85
85
|
|