static_cms 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -0
- data/bin/static_cms +4 -0
- data/data/site_template/.gitignore +1 -0
- data/data/site_template/articles/news.html.yhaml +6 -0
- data/data/site_template/articles/short_profile.html.yhaml +6 -0
- data/data/site_template/config.yaml +8 -0
- data/data/site_template/pages.yaml +18 -0
- data/data/site_template/rakefile +17 -0
- data/data/site_template/sources/default.css.sass +0 -0
- data/data/site_template/statics/favicon.png +0 -0
- data/data/site_template/statics/ht_files/top/.htaccess +10 -0
- data/data/site_template/templates/blank.html.haml +6 -0
- data/data/site_template/templates/default.html.haml +10 -0
- data/data/site_template/templates/head.html.haml +7 -0
- data/data/site_template/templates/moved.html.haml +6 -0
- data/lib/static_cms/version.rb +3 -0
- data/lib/static_cms.rb +170 -0
- data/rakefile +10 -0
- data/static_cms.gemspec +17 -0
- data/test/helper_for_test.rb +3 -0
- data/test/test_generate.rb +11 -0
- data/test/test_init.rb +9 -0
- metadata +114 -0
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= StaticCms
|
2
|
+
|
3
|
+
== Description
|
4
|
+
Simple Static HTML file generation based on Haml and Sass.
|
5
|
+
|
6
|
+
== Features
|
7
|
+
StaticCMS is a very small and simple contents management system based on YAML, Haml and Sass.
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
Please type
|
11
|
+
static_cms init DIR
|
12
|
+
on the command line to initialize DIR directory as a working directory of the StaticCms.
|
13
|
+
Please goto DIR and type
|
14
|
+
rake
|
15
|
+
on the command line to generate site or
|
16
|
+
rake PAGE_NAME
|
17
|
+
to generate individual pages.
|
data/bin/static_cms
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
root
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
.:
|
3
|
+
title: Jon Smith's Website
|
4
|
+
articles:
|
5
|
+
- news
|
6
|
+
- short_profile
|
7
|
+
statics:
|
8
|
+
- ht_files/top/.htaccess
|
9
|
+
sources:
|
10
|
+
- default.css.sass
|
11
|
+
stylesheets:
|
12
|
+
template: blank
|
13
|
+
sources:
|
14
|
+
- default.css.sass
|
15
|
+
images:
|
16
|
+
template: blank
|
17
|
+
statics:
|
18
|
+
- favicon.png
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'static_cms'
|
2
|
+
|
3
|
+
::SITE = StaticCms::Site.new
|
4
|
+
task default: :generate
|
5
|
+
desc "Generate all pages."
|
6
|
+
task generate: SITE.pages.map(&:name)
|
7
|
+
|
8
|
+
::SITE.pages.each{|page|
|
9
|
+
task page.name do
|
10
|
+
page.generate
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
14
|
+
desc "Update templates, sources, statics (and more)."
|
15
|
+
task :update do
|
16
|
+
::StaticCms::Command.update
|
17
|
+
end
|
File without changes
|
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html{lang: @site.lang}
|
3
|
+
= haml(File.read('templates/head.html.haml'))
|
4
|
+
%link{rel: :stylesheet, href: "stylesheets/default.css", type: "text/css"}
|
5
|
+
%body
|
6
|
+
- @articles.each do |article|
|
7
|
+
%article{id: article.name}
|
8
|
+
%header
|
9
|
+
%h1= article.title
|
10
|
+
= haml(article.data)
|
data/lib/static_cms.rb
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
module StaticCms
|
2
|
+
require 'fileutils'
|
3
|
+
require 'ruby_patch'
|
4
|
+
|
5
|
+
SITE_TEMPLATE_DIR = File.join(__DIR__, '../data/site_template')
|
6
|
+
|
7
|
+
module Command
|
8
|
+
def self.init(dir = '.')
|
9
|
+
FileUtils.mkdir_p(dir)
|
10
|
+
success = false
|
11
|
+
FileUtils.cd(dir){|dir|
|
12
|
+
success = system <<-EOS
|
13
|
+
git init > #{File::NULL}
|
14
|
+
git commit --allow-empty -m 'Empty commit.' > #{File::NULL}
|
15
|
+
cp -r #{File.join(SITE_TEMPLATE_DIR, '*')} . > #{File::NULL}
|
16
|
+
git add . > #{File::NULL}
|
17
|
+
git commit -m 'Copied from site template.' > #{File::NULL}
|
18
|
+
EOS
|
19
|
+
}
|
20
|
+
|
21
|
+
success
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.update
|
25
|
+
site_template_dir = File.join(__DIR__, '../data/site_template')
|
26
|
+
FileUtils.cp_r(File.join(site_template_dir, 'templates'), '.')
|
27
|
+
FileUtils.cp_r(File.join(site_template_dir, 'sources'), '.')
|
28
|
+
FileUtils.cp_r(File.join(site_template_dir, 'statics'), '.')
|
29
|
+
FileUtils.cp(File.join(site_template_dir, 'rakefile'), '.')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Site
|
34
|
+
require 'yaml'
|
35
|
+
|
36
|
+
CONFIG_DEFAULT = {
|
37
|
+
'lang' => 'en',
|
38
|
+
'www' => '.',
|
39
|
+
'dir' => File.join(__DIR__, 'root'),
|
40
|
+
'author' => '',
|
41
|
+
'robots' => 'noarchive',
|
42
|
+
'favicon' => 'images/favicon.png',
|
43
|
+
'charset' => 'utf-8',
|
44
|
+
}
|
45
|
+
|
46
|
+
attr_accessor :pages
|
47
|
+
attr_accessor *(CONFIG_DEFAULT.keys)
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
@pages = YAML.load_file('pages.yaml')\
|
51
|
+
.to_a.map{|name, params| ::StaticCms::Page.new(self, name, params)}
|
52
|
+
config = CONFIG_DEFAULT.merge(YAML.load_file('config.yaml'))
|
53
|
+
config.each{|k, v| instance_variable_set("@#{k}", v)}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Page
|
58
|
+
require 'fileutils'
|
59
|
+
require 'haml'
|
60
|
+
|
61
|
+
PARAMS_DEFAULT ={
|
62
|
+
'visible' => true,
|
63
|
+
'titile' => '',
|
64
|
+
'template' => 'default',
|
65
|
+
'articles' => [],
|
66
|
+
'statics' => [],
|
67
|
+
'sources' => [],
|
68
|
+
'base' => ::StaticCms::Site::CONFIG_DEFAULT['www'],
|
69
|
+
}
|
70
|
+
|
71
|
+
attr_accessor :site, :name, :dir
|
72
|
+
attr_accessor *(PARAMS_DEFAULT.keys)
|
73
|
+
|
74
|
+
def initialize(site, name, params = {})
|
75
|
+
@site = site
|
76
|
+
@name = name
|
77
|
+
@dir = File.join("root", @name)
|
78
|
+
params = PARAMS_DEFAULT.merge(params)
|
79
|
+
@template = File.join('templates', params.delete('template')) + '.html.haml'
|
80
|
+
@articles = params.delete('articles').map{|name| ::StaticCms::Article.new(name)}
|
81
|
+
@statics = params.delete('statics').map{|file| File.join('statics', file)}
|
82
|
+
@sources = params.delete('sources').map{|file| File.join('sources', file)}
|
83
|
+
params.each{|k, v|
|
84
|
+
instance_variable_set("@#{k}", v)
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
def generate
|
89
|
+
FileUtils.mkdir_p @dir
|
90
|
+
|
91
|
+
if @visible
|
92
|
+
@statics.each{|file| cp_if_new(file)}
|
93
|
+
@sources.each{|file| compile(file)}
|
94
|
+
template = @template
|
95
|
+
else
|
96
|
+
@statics.each{|file| FileUtils.rm_rf(static_target(file))}
|
97
|
+
@sources.each{|file| FileUtils.rm_rf(compile_target(file))}
|
98
|
+
template = 'templates/moved.html.haml'
|
99
|
+
end
|
100
|
+
|
101
|
+
html = ::Haml::Engine.new(File.read(template)).render(self)
|
102
|
+
target = File.join(@dir, 'index.html')
|
103
|
+
open(target, 'w'){|io|
|
104
|
+
io.write(html)
|
105
|
+
io.flush
|
106
|
+
io.fsync
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def haml(text)
|
113
|
+
::Haml::Engine.new(text).render(self)
|
114
|
+
end
|
115
|
+
|
116
|
+
def cp_if_new(source)
|
117
|
+
target = static_target(source)
|
118
|
+
if !File.file?(target) || File.mtime(source) > File.mtime(target)
|
119
|
+
FileUtils.cp(source, target)
|
120
|
+
FileUtils.chmod(0644, target)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def compile(source)
|
125
|
+
ext = File.extname(source)
|
126
|
+
target = compile_target(source)
|
127
|
+
|
128
|
+
case ext
|
129
|
+
when /\A\.sass\z/
|
130
|
+
system "sass #{source} > #{target}"
|
131
|
+
else
|
132
|
+
raise NotImplementedError, file
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def static_target(source)
|
137
|
+
File.join(@dir, File.basename(source))
|
138
|
+
end
|
139
|
+
|
140
|
+
def compile_target(source)
|
141
|
+
ext = File.extname(source)
|
142
|
+
File.join(@dir, File.basename(source, ext))
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class Article
|
147
|
+
PARAMS_DEFAULT = {
|
148
|
+
'title' => '',
|
149
|
+
}
|
150
|
+
|
151
|
+
attr_accessor :name, :file, :data
|
152
|
+
attr_accessor *(PARAMS_DEFAULT.keys)
|
153
|
+
|
154
|
+
def initialize(name)
|
155
|
+
@name = name
|
156
|
+
@file = File.join('articles', name) + '.html.yhaml'
|
157
|
+
yaml, @data = File.read(@file).split(/^\.\.\.$/, 2)
|
158
|
+
params = PARAMS_DEFAULT.merge(YAML.load(yaml))
|
159
|
+
params.each{|k, v| instance_variable_set("@#{k}", v)}
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
require 'thor'
|
164
|
+
class Runner < Thor
|
165
|
+
desc "init [DIR]", "Initialize DIR directory for StaticCms [default: .]."
|
166
|
+
def init(dir = '.')
|
167
|
+
::StaticCms::Command.init(dir)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/rakefile
ADDED
data/static_cms.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "./lib/static_cms/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.files = `git ls-files`.split
|
5
|
+
s.name = 'static_cms'
|
6
|
+
s.summary = "Simple static contents management system."
|
7
|
+
s.version = StaticCms::VERSION
|
8
|
+
s.add_runtime_dependency 'haml', '~> 3.1'
|
9
|
+
s.add_runtime_dependency 'sass', '~> 3.2'
|
10
|
+
s.add_runtime_dependency 'ruby_patch', '~> 1.1'
|
11
|
+
s.add_runtime_dependency 'thor', '~> 0.16'
|
12
|
+
s.author = 'kshramt'
|
13
|
+
s.description = "Simple static contents management system based on Haml and Sass."
|
14
|
+
s.required_ruby_version = '~> 1.9'
|
15
|
+
s.test_files.concat `git ls-files test`.split.select{|path| path =~ /test_[^\/]*\.rb/}
|
16
|
+
s.executables << 'static_cms'
|
17
|
+
end
|
data/test/test_init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: static_cms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- kshramt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: haml
|
16
|
+
requirement: &81251070 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *81251070
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sass
|
27
|
+
requirement: &81175110 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.2'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *81175110
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: ruby_patch
|
38
|
+
requirement: &81173090 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.1'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *81173090
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: thor
|
49
|
+
requirement: &81172130 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.16'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *81172130
|
58
|
+
description: Simple static contents management system based on Haml and Sass.
|
59
|
+
email:
|
60
|
+
executables:
|
61
|
+
- static_cms
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- README.rdoc
|
66
|
+
- bin/static_cms
|
67
|
+
- data/site_template/.gitignore
|
68
|
+
- data/site_template/articles/news.html.yhaml
|
69
|
+
- data/site_template/articles/short_profile.html.yhaml
|
70
|
+
- data/site_template/config.yaml
|
71
|
+
- data/site_template/pages.yaml
|
72
|
+
- data/site_template/rakefile
|
73
|
+
- data/site_template/sources/default.css.sass
|
74
|
+
- data/site_template/statics/favicon.png
|
75
|
+
- data/site_template/statics/ht_files/top/.htaccess
|
76
|
+
- data/site_template/templates/blank.html.haml
|
77
|
+
- data/site_template/templates/default.html.haml
|
78
|
+
- data/site_template/templates/head.html.haml
|
79
|
+
- data/site_template/templates/moved.html.haml
|
80
|
+
- lib/static_cms.rb
|
81
|
+
- lib/static_cms/version.rb
|
82
|
+
- rakefile
|
83
|
+
- static_cms.gemspec
|
84
|
+
- test/helper_for_test.rb
|
85
|
+
- test/test_generate.rb
|
86
|
+
- test/test_init.rb
|
87
|
+
homepage:
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '1.9'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.11
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Simple static contents management system.
|
111
|
+
test_files:
|
112
|
+
- test/test_generate.rb
|
113
|
+
- test/test_init.rb
|
114
|
+
has_rdoc:
|