clay 1.7.1 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/src/clay.rb +28 -21
- metadata +5 -5
data/src/clay.rb
CHANGED
@@ -6,8 +6,8 @@ require 'fileutils'
|
|
6
6
|
require 'yaml'
|
7
7
|
|
8
8
|
module Clay
|
9
|
-
VERSION = "1.7.
|
10
|
-
|
9
|
+
VERSION = "1.7.2"
|
10
|
+
|
11
11
|
def self.init project_name, silent=false
|
12
12
|
mute(silent) {
|
13
13
|
puts "Creating the folder structure... "
|
@@ -15,7 +15,7 @@ module Clay
|
|
15
15
|
puts "OK."
|
16
16
|
}
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def self.form silent=false
|
20
20
|
mute(silent){
|
21
21
|
puts "Forming... "
|
@@ -24,7 +24,7 @@ module Clay
|
|
24
24
|
puts "OK."
|
25
25
|
}
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def self.run silent=false
|
29
29
|
mute(silent) {
|
30
30
|
puts "Starting server on http://localhost:9292/"
|
@@ -41,7 +41,7 @@ module Clay
|
|
41
41
|
yield
|
42
42
|
$stdout.reopen(stdout)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def self.project
|
46
46
|
Project.new project_root
|
47
47
|
end
|
@@ -52,6 +52,12 @@ module Clay
|
|
52
52
|
|
53
53
|
end
|
54
54
|
|
55
|
+
class Hash
|
56
|
+
def deep_copy
|
57
|
+
Marshal.load(Marshal.dump(self))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
55
61
|
class Project
|
56
62
|
def initialize project_root
|
57
63
|
@project_root = project_root
|
@@ -68,7 +74,7 @@ class Project
|
|
68
74
|
def check_consistency
|
69
75
|
init_clay_project? and layouts_exist? and pages_exist? and static_exist? and texts_exist?
|
70
76
|
end
|
71
|
-
|
77
|
+
|
72
78
|
def build
|
73
79
|
target = configs["target_dir"] ? configs["target_dir"] : "build"
|
74
80
|
unless File.directory?(path(target))
|
@@ -78,7 +84,7 @@ class Project
|
|
78
84
|
texts = interpret_texts
|
79
85
|
publish_pages target, texts
|
80
86
|
end
|
81
|
-
|
87
|
+
|
82
88
|
def prepare_rack_config
|
83
89
|
unless File.exists? path("config.ru")
|
84
90
|
file = File.open(path("config.ru"), "w")
|
@@ -95,17 +101,17 @@ class Project
|
|
95
101
|
rescue Errno::ENOENT
|
96
102
|
{}
|
97
103
|
end
|
98
|
-
|
104
|
+
|
99
105
|
private
|
100
|
-
|
106
|
+
|
101
107
|
def init_clay_project?
|
102
108
|
`touch #{path(".clay")}` unless File.exists? path(".clay")
|
103
109
|
end
|
104
|
-
|
110
|
+
|
105
111
|
def layouts_exist?
|
106
112
|
create_directory path("layouts")
|
107
113
|
end
|
108
|
-
|
114
|
+
|
109
115
|
def pages_exist?
|
110
116
|
create_directory path("pages")
|
111
117
|
end
|
@@ -117,7 +123,7 @@ private
|
|
117
123
|
def texts_exist?
|
118
124
|
create_directory path("texts")
|
119
125
|
end
|
120
|
-
|
126
|
+
|
121
127
|
def create_directory dirname
|
122
128
|
return if dirname.nil? || dirname.empty?
|
123
129
|
unless File.directory?(dirname)
|
@@ -133,13 +139,13 @@ private
|
|
133
139
|
def publish_static target
|
134
140
|
FileUtils.cp_r(Dir.glob("static/*"), target)
|
135
141
|
end
|
136
|
-
|
142
|
+
|
137
143
|
def interpret_texts
|
138
144
|
data = {}
|
139
|
-
texts = Dir.glob("texts/*")
|
140
|
-
texts.each do |filename|
|
145
|
+
texts = Dir.glob("texts/*") # =>
|
146
|
+
texts.each do |filename|
|
141
147
|
begin
|
142
|
-
data.merge! Text.new(filename).to_h
|
148
|
+
data.merge! Text.new(filename).to_h
|
143
149
|
rescue RuntimeError => e
|
144
150
|
puts "Warning: ", e.message
|
145
151
|
end
|
@@ -147,9 +153,10 @@ private
|
|
147
153
|
data
|
148
154
|
end
|
149
155
|
|
150
|
-
def publish_pages target,
|
156
|
+
def publish_pages target, initial_data=nil
|
151
157
|
Dir.glob("pages/*.*").each { |page_path|
|
152
158
|
begin
|
159
|
+
data = initial_data.deep_copy
|
153
160
|
page = Page.new(page_path, target, data)
|
154
161
|
File.open(page.target, "w") {|f| f.write page.content }
|
155
162
|
rescue RuntimeError => e
|
@@ -180,18 +187,18 @@ class Page
|
|
180
187
|
data.merge! new_data
|
181
188
|
@content = render raw_content, layout, @page_type, data
|
182
189
|
end
|
183
|
-
|
190
|
+
|
184
191
|
def target
|
185
192
|
file_base = @filename.split(".")[0..-2].join('.')
|
186
193
|
"#{@target}/#{file_base}.html"
|
187
194
|
end
|
188
|
-
|
195
|
+
|
189
196
|
private
|
190
197
|
def filename_within_pages filename
|
191
198
|
filename.split("/", 2)[1]
|
192
199
|
end
|
193
|
-
|
194
|
-
def render content, layout, page_type, data
|
200
|
+
|
201
|
+
def render content, layout, page_type, data
|
195
202
|
data['content'] = parsed_content content, data
|
196
203
|
begin
|
197
204
|
layout_content = File.read(layout)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 1.7.
|
9
|
+
- 2
|
10
|
+
version: 1.7.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pavlo Kerestey
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-13 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
requirements: []
|
171
171
|
|
172
172
|
rubyforge_project: clay
|
173
|
-
rubygems_version: 1.
|
173
|
+
rubygems_version: 1.5.0
|
174
174
|
signing_key:
|
175
175
|
specification_version: 3
|
176
176
|
summary: A lightweight CMS for static websites
|