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 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,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'static_cms'
4
+ ::StaticCms::Runner.start
@@ -0,0 +1 @@
1
+ root
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: News
3
+ ...
4
+ %dl
5
+ %dt 120930
6
+ %dd Launch the website.
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Profile (Short Version)
3
+ ...
4
+ %dl
5
+ %dt Name
6
+ %dd John Smith
@@ -0,0 +1,8 @@
1
+ ---
2
+ lang: ja
3
+ www: . # http://www.john_smith.com
4
+ dir: root # john@smith:~/www
5
+ author: John Smith
6
+ robots: noarchive
7
+ favicon: images/favicon.png
8
+ charset: utf-8
@@ -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
@@ -0,0 +1,10 @@
1
+ AddType image/svg+xml .svg
2
+ DirectoryIndex index.html .forbidden_directive
3
+ <Files ~ "^\.">
4
+ deny from all
5
+ </Files>
6
+ <Files ~ "(~|#|\.log)$">
7
+ deny from all
8
+ </Files>
9
+ order allow,deny
10
+ allow from all
@@ -0,0 +1,6 @@
1
+ !!! 5
2
+ %html{lang: :en}
3
+ = haml(File.read('templates/head.html.haml'))
4
+ %body
5
+ This page is intentionally left blank.
6
+ %a{href: @site.www} Please go to the top page.
@@ -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)
@@ -0,0 +1,7 @@
1
+ %head
2
+ %meta{charset: @site.charset}
3
+ %base{href: @base}
4
+ %link{rel: :icon, href: @site.favicon}
5
+ %meta{name: :author, content: @site.author}
6
+ %meta{name: :robots, content: @site.robots}
7
+ %title= @title
@@ -0,0 +1,6 @@
1
+ !!! 5
2
+ %html{lang: :en}
3
+ = haml(File.read('templates/head.html.haml'))
4
+ %body
5
+ Contents of this page have moved or removed.
6
+ %a{href: @site.www} Please go to the top page.
@@ -0,0 +1,3 @@
1
+ module ::StaticCms
2
+ VERSION = '0.0.0'
3
+ end
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
@@ -0,0 +1,10 @@
1
+ require 'ruby_patch'
2
+ require 'rake/testtask'
3
+
4
+ task default: [:test]
5
+
6
+ desc "Run tests."
7
+ ::Rake::TestTask.new do |t|
8
+ t.libs = ['lib', 'test'].map{|dir| File.join(__DIR__, dir)}
9
+ t.pattern = "test/**/test_*.rb"
10
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ require 'minitest/autorun'
2
+
3
+ require 'static_cms'
@@ -0,0 +1,11 @@
1
+ require 'helper_for_test'
2
+ require 'fileutils'
3
+ require 'ruby_patch'
4
+
5
+ class TestGenerate < ::MiniTest::Unit::TestCase
6
+ def test_generate
7
+ FileUtils.cd(File.join(__DIR__, '../data/site_template')){
8
+ assert system "rake -I ../../lib"
9
+ }
10
+ end
11
+ end
data/test/test_init.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'helper_for_test'
2
+
3
+ class TestInitAndGenerate < ::MiniTest::Unit::TestCase
4
+ require 'tmpdir'
5
+
6
+ def test_init
7
+ assert ::StaticCms::Command.init(Dir.mktmpdir)
8
+ end
9
+ end
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: