clay 1.6 → 1.7
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.md +34 -2
- data/src/clay.rb +57 -29
- data/src/rack/clay.rb +8 -13
- metadata +41 -7
data/README.md
CHANGED
@@ -31,7 +31,8 @@ In your project directory You will find following subdirectories
|
|
31
31
|
|
32
32
|
* layouts
|
33
33
|
* pages
|
34
|
-
*
|
34
|
+
* static
|
35
|
+
* texts
|
35
36
|
|
36
37
|
The _layouts_ directory is for the global layouts of your pages.
|
37
38
|
There must be a layout called default.html
|
@@ -40,11 +41,42 @@ In the _pages_ directory You create each page You want to have.
|
|
40
41
|
The pages are created in html or markdown.
|
41
42
|
The filename of an html page must be <pagename>.html
|
42
43
|
Markdown pages however can be either <pagename>.md or <pagename>.markdown
|
43
|
-
|
44
|
+
|
44
45
|
*NOTE* Your pages may have any names You want. However given your domain
|
45
46
|
name is foo.com, and You want that the main page shows up at http://foo.com
|
46
47
|
You will have to create page named index in the pages directory
|
47
48
|
|
49
|
+
The static files like css stylesheets, javascript files and images/videos
|
50
|
+
all should be placed in the _static_ folder.
|
51
|
+
|
52
|
+
The _texts_ is a directory, in which You can create the texts with images,
|
53
|
+
which will then be available to the layouts and the pages.
|
54
|
+
A text file in _texts_ directory must be written in
|
55
|
+
[markdown](http://daringfireball.net/projects/markdown/) and have the extension
|
56
|
+
of either .md or .markdown in order to be used. You can then use any text with
|
57
|
+
filename *some-article.md* as *{{{text-some-article}}}* in Your pages. Please
|
58
|
+
note, that in pages or layouts You should do a tripple brackets, otherwise
|
59
|
+
the tags will be escaped and You will see html instead of nice formatted text.
|
60
|
+
|
61
|
+
## Configurations
|
62
|
+
|
63
|
+
Clay can be configured to behave specifically to Your development needs.
|
64
|
+
To use this, You can create config.yaml in your project directory with
|
65
|
+
following options:
|
66
|
+
|
67
|
+
* `autoreload: true|false` - This option will autoreload Your site, when you run it via
|
68
|
+
`clay run` and something changes in pages, layouts, texts or static files.
|
69
|
+
This way You can just update the files and immediately see the changes
|
70
|
+
when You reload the page. This is very useful for the page development
|
71
|
+
or when You write some text and want to see how does it actually look
|
72
|
+
like on the page.
|
73
|
+
|
74
|
+
* `target_dir: <custom/target/directory>` - This option makes clay generate the site into
|
75
|
+
a specific location. For example a pubic directory. This directory can be then served
|
76
|
+
by a webserver. This way one can install clay on a remote server and update the site
|
77
|
+
on the fly. It also provides more flexibility in choosing the place of output.
|
78
|
+
Please make sure, that the target is writable.
|
79
|
+
|
48
80
|
----------------------------------------
|
49
81
|
|
50
82
|
## Licence
|
data/src/clay.rb
CHANGED
@@ -6,29 +6,42 @@ require 'fileutils'
|
|
6
6
|
require 'yaml'
|
7
7
|
|
8
8
|
module Clay
|
9
|
-
VERSION = "1.
|
9
|
+
VERSION = "1.7"
|
10
10
|
|
11
|
-
def self.init project_name
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def self.init project_name, silent=false
|
12
|
+
mute(silent) {
|
13
|
+
puts "Creating the folder structure... "
|
14
|
+
project.init project_name
|
15
|
+
puts "OK."
|
16
|
+
}
|
15
17
|
end
|
16
18
|
|
17
|
-
def self.form
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def self.form silent=false
|
20
|
+
mute(silent){
|
21
|
+
puts "Forming... "
|
22
|
+
project.check_consistency
|
23
|
+
project.build
|
24
|
+
puts "OK."
|
25
|
+
}
|
22
26
|
end
|
23
27
|
|
24
|
-
def self.run
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
def self.run silent=false
|
29
|
+
mute(silent) {
|
30
|
+
puts "Starting server on http://localhost:9292/"
|
31
|
+
project.prepare_rack_config
|
32
|
+
exec "rackup config.ru"
|
33
|
+
}
|
28
34
|
end
|
29
35
|
|
30
36
|
private
|
31
37
|
|
38
|
+
def self.mute silent
|
39
|
+
stdout = STDOUT.dup
|
40
|
+
$stdout.reopen(File.open("/dev/null", "w")) if silent
|
41
|
+
yield
|
42
|
+
$stdout.reopen(stdout)
|
43
|
+
end
|
44
|
+
|
32
45
|
def self.project
|
33
46
|
Project.new project_root
|
34
47
|
end
|
@@ -53,16 +66,17 @@ class Project
|
|
53
66
|
end
|
54
67
|
|
55
68
|
def check_consistency
|
56
|
-
init_clay_project? and layouts_exist? and pages_exist? and
|
69
|
+
init_clay_project? and layouts_exist? and pages_exist? and static_exist? and texts_exist?
|
57
70
|
end
|
58
71
|
|
59
72
|
def build
|
60
|
-
|
61
|
-
|
73
|
+
target = configs["target_dir"] ? configs["target_dir"] : "build"
|
74
|
+
unless File.directory?(path(target))
|
75
|
+
create_directory path(target)
|
62
76
|
end
|
63
|
-
|
77
|
+
publish_static target
|
64
78
|
texts = interpret_texts
|
65
|
-
publish_pages texts
|
79
|
+
publish_pages target, texts
|
66
80
|
end
|
67
81
|
|
68
82
|
def prepare_rack_config
|
@@ -72,8 +86,17 @@ class Project
|
|
72
86
|
file.close
|
73
87
|
end
|
74
88
|
end
|
89
|
+
|
90
|
+
def configs
|
91
|
+
result = YAML.load(File.read(path("config.yaml")))
|
92
|
+
conf_options = result.keys - ["autoreload", "target_dir"]
|
93
|
+
raise "ERROR in config.yaml" if conf_options.length > 0
|
94
|
+
result
|
95
|
+
rescue Errno::ENOENT
|
96
|
+
{}
|
97
|
+
end
|
75
98
|
|
76
|
-
|
99
|
+
private
|
77
100
|
|
78
101
|
def init_clay_project?
|
79
102
|
`touch #{path(".clay")}` unless File.exists? path(".clay")
|
@@ -87,8 +110,12 @@ class Project
|
|
87
110
|
create_directory path("pages")
|
88
111
|
end
|
89
112
|
|
90
|
-
def
|
91
|
-
create_directory path("
|
113
|
+
def static_exist?
|
114
|
+
create_directory path("static")
|
115
|
+
end
|
116
|
+
|
117
|
+
def texts_exist?
|
118
|
+
create_directory path("texts")
|
92
119
|
end
|
93
120
|
|
94
121
|
def create_directory dirname
|
@@ -103,8 +130,8 @@ class Project
|
|
103
130
|
end
|
104
131
|
end
|
105
132
|
|
106
|
-
def
|
107
|
-
FileUtils.cp_r(Dir.glob("
|
133
|
+
def publish_static target
|
134
|
+
FileUtils.cp_r(Dir.glob("static/*"), target)
|
108
135
|
end
|
109
136
|
|
110
137
|
def interpret_texts
|
@@ -120,10 +147,10 @@ class Project
|
|
120
147
|
data
|
121
148
|
end
|
122
149
|
|
123
|
-
def publish_pages data=nil
|
150
|
+
def publish_pages target, data=nil
|
124
151
|
Dir.glob("pages/*.*").each { |page_path|
|
125
152
|
begin
|
126
|
-
page = Page.new(page_path, data)
|
153
|
+
page = Page.new(page_path, target, data)
|
127
154
|
File.open(page.target, "w") {|f| f.write page.content }
|
128
155
|
rescue RuntimeError => e
|
129
156
|
puts "Warning: ", e.message
|
@@ -139,12 +166,13 @@ end
|
|
139
166
|
|
140
167
|
class Page
|
141
168
|
attr_reader :content
|
142
|
-
def initialize filename, data=nil
|
169
|
+
def initialize filename, target=nil, data=nil
|
143
170
|
case filename.split(".").last
|
144
171
|
when "md", "markdown" then @page_type = "markdown"
|
145
172
|
when "html" then @page_type = "html"
|
146
|
-
else raise "File type of #{filename} unknown. Shouldn\'t it be in the
|
173
|
+
else raise "File type of #{filename} unknown. Shouldn\'t it be in the static directory?"
|
147
174
|
end
|
175
|
+
@target = target.nil? ? "build" : target
|
148
176
|
@filename = filename_within_pages filename
|
149
177
|
file_content = File.read(filename)
|
150
178
|
data ||= {}
|
@@ -155,7 +183,7 @@ class Page
|
|
155
183
|
|
156
184
|
def target
|
157
185
|
file_base = @filename.split(".")[0..-2].join('.')
|
158
|
-
"
|
186
|
+
"#{@target}/#{file_base}.html"
|
159
187
|
end
|
160
188
|
|
161
189
|
private
|
data/src/rack/clay.rb
CHANGED
@@ -12,19 +12,13 @@ module Rack
|
|
12
12
|
if ::File.exist?(@configfile)
|
13
13
|
puts "Reading configs... "
|
14
14
|
@config = ::YAML.load(::File.read(@configfile))
|
15
|
-
@config =
|
16
|
-
if @config[:destination].nil?
|
17
|
-
@path = opts[:destination].nil? ? "build" : opts[:destination]
|
18
|
-
else
|
19
|
-
opts.merge!(@config)
|
20
|
-
@path = @config[:destination].nil? ? "build" : @config[:destination]
|
21
|
-
end
|
15
|
+
@config = @config ? @config : {}
|
22
16
|
puts @config.inspect
|
23
17
|
puts "Ready."
|
24
18
|
end
|
25
19
|
|
26
20
|
@path = "build"
|
27
|
-
@path = @config["
|
21
|
+
@path = @config["target_dir"] if @config["target_dir"]
|
28
22
|
@mimes = Rack::Mime::MIME_TYPES.map{|k,v| /#{k.gsub('.','\.')}$/i }
|
29
23
|
end
|
30
24
|
def call(env)
|
@@ -82,11 +76,11 @@ module Rack
|
|
82
76
|
new_file_hashes = get_file_hashes
|
83
77
|
changes = compare_file_hashes old_file_hashes, new_file_hashes.to_json
|
84
78
|
unless changes
|
85
|
-
begin
|
86
|
-
require 'clay'
|
87
|
-
::Clay.form
|
88
|
-
rescue LoadError
|
89
|
-
raise "Could not load clay"
|
79
|
+
begin
|
80
|
+
require 'clay'
|
81
|
+
::Clay.form
|
82
|
+
rescue LoadError
|
83
|
+
raise "Could not load clay. Please reinstall: [sudo] gem install clay"
|
90
84
|
end
|
91
85
|
end
|
92
86
|
::File.open(clayfile, "w") {|f| f.write(new_file_hashes.to_json)}
|
@@ -94,6 +88,7 @@ module Rack
|
|
94
88
|
end
|
95
89
|
|
96
90
|
def get_file_hashes
|
91
|
+
return {"Build_Path_Is_Empty"=>true} unless ::File.exists? @path
|
97
92
|
files = ::Dir.glob("**/*") - [@path] - ::Dir.glob(@path + "/**/*")
|
98
93
|
file_hashes_array = files.map {|filename| [filename, file_hash(filename)]}
|
99
94
|
file_hashes = Hash[*file_hashes_array.flatten]
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: "1.
|
8
|
+
- 7
|
9
|
+
version: "1.7"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Pavlo Kerestey
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-11 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -107,7 +107,41 @@ has_rdoc: true
|
|
107
107
|
homepage: http://github.com/kerestey/clay
|
108
108
|
licenses: []
|
109
109
|
|
110
|
-
post_install_message:
|
110
|
+
post_install_message: |
|
111
|
+
**************************************************
|
112
|
+
|
113
|
+
Dear User, Thank you for installing clay - a lightweight cms for static websites.
|
114
|
+
|
115
|
+
IMPORTANT CHANGES WITH THIS RELEASE (ver. 1.7):
|
116
|
+
directory public changed to be static Please rename Your project structure
|
117
|
+
to incorporate this change. This had to be done because of the way some
|
118
|
+
ruby webservers (like passenger for example) deal with the public directory.
|
119
|
+
If You want to further use passenger or nginx to serve your site, You can
|
120
|
+
leave the public directory intact. Just move its contents to the static
|
121
|
+
directory, so the files will be copied over to the build directory when
|
122
|
+
forming the site.
|
123
|
+
|
124
|
+
Additionally You can now specify the build directory in config.yaml file
|
125
|
+
by adding build_directory: "/path/to/the/build/dir". Your site will be
|
126
|
+
served out of this directory when You run $ clay run
|
127
|
+
|
128
|
+
These Changes will allow to use passenger and putting the built site into
|
129
|
+
the public directory so they are served by fast webservers like nginx or
|
130
|
+
apache.
|
131
|
+
|
132
|
+
The users who do not want to change anything, don't worry. All Your data
|
133
|
+
will stay intact. You have to manually change your config.yaml to actually
|
134
|
+
make the public directory be the build target location.
|
135
|
+
|
136
|
+
Please be sure to look at the CHANGES to see what might have changed since
|
137
|
+
the last release:
|
138
|
+
|
139
|
+
https://github.com/kerestey/clay/blob/master/CHANGES.md
|
140
|
+
|
141
|
+
And happy New Year by the way :)
|
142
|
+
|
143
|
+
**************************************************
|
144
|
+
|
111
145
|
rdoc_options: []
|
112
146
|
|
113
147
|
require_paths:
|
@@ -135,9 +169,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
169
|
requirements: []
|
136
170
|
|
137
171
|
rubyforge_project: clay
|
138
|
-
rubygems_version: 1.4.
|
172
|
+
rubygems_version: 1.4.2
|
139
173
|
signing_key:
|
140
174
|
specification_version: 3
|
141
|
-
summary: A
|
175
|
+
summary: A lightweight CMS for static websites
|
142
176
|
test_files: []
|
143
177
|
|