static_cms 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  lang: ja
3
- www: . # http://www.john_smith.com
3
+ www: ./ # http://www.john_smith.com/
4
4
  dir: root # john@smith:~/www
5
5
  author: John Smith
6
6
  robots: noarchive
@@ -9,10 +9,12 @@
9
9
  sources:
10
10
  - default.css.sass
11
11
  stylesheets:
12
+ title: Stylesheets
12
13
  template: blank
13
14
  sources:
14
15
  - default.css.sass
15
16
  images:
17
+ title: Images
16
18
  template: blank
17
19
  statics:
18
20
  - favicon.png
@@ -0,0 +1,7 @@
1
+ pre, code, samp
2
+ white-space: pre-wrap
3
+ img
4
+ width: 100%
5
+ &.mail_address
6
+ width: 27ex
7
+ vertical-align: middle
@@ -1,10 +1,19 @@
1
1
  !!! 5
2
2
  %html{lang: @site.lang}
3
- = haml(File.read('templates/head.html.haml'))
4
- %link{rel: :stylesheet, href: "stylesheets/default.css", type: "text/css"}
3
+ %head
4
+ = haml(File.read('templates/head.html.haml'))
5
+ %link{rel: :stylesheet, href: "stylesheets/default.css", type: "text/css"}
5
6
  %body
7
+ %header
8
+ %h1= @title
6
9
  - @articles.each do |article|
7
10
  %article{id: article.name}
8
11
  %header
9
12
  %h1= article.title
10
13
  = haml(article.data)
14
+ %footer
15
+ %nav
16
+ %ul
17
+ - @site.pages.select{|p| p.visible}.delete_if{|p| p.template == 'blank'}.sort_by{|p| p.name}.each do |p|
18
+ %li
19
+ %a{href: File.join(@site.www, p.name)}= p.title
@@ -1,7 +1,6 @@
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
1
+ %meta{charset: @site.charset}
2
+ %base{href: @base}
3
+ %link{rel: :icon, href: @site.favicon}
4
+ %meta{name: :author, content: @site.author}
5
+ %meta{name: :robots, content: @site.robots}
6
+ %title= @title
File without changes
@@ -0,0 +1,61 @@
1
+ require 'haml'
2
+
3
+ module ::Haml
4
+ module Filters
5
+
6
+ module PreFile
7
+ include ::Haml::Filters::Base
8
+
9
+ def render(file)
10
+ file.strip!
11
+ plain_text = ::StaticCms::Helpers.to_plain(File.read(file))
12
+ "<pre>#{plain_text}</pre>"
13
+ end
14
+ end
15
+
16
+ module SampFile
17
+ include ::Haml::Filters::Base
18
+
19
+ def render(file)
20
+ file.strip!
21
+ plain_text = ::StaticCms::Helpers.to_plain(File.read(file))
22
+ "<pre class='samp'><samp>#{plain_text}</samp></pre>"
23
+ end
24
+
25
+ module RubyCode
26
+ include ::Haml::Filters::Base
27
+
28
+ def render(text)
29
+ ::StaticCms::Helpers.to_code(text, :ruby)
30
+ end
31
+ end
32
+
33
+ module FortranCode
34
+ include ::Haml::Filters::Base
35
+
36
+ def render(text)
37
+ ::StaticCms::Helpers.to_code(text, :fortran)
38
+ end
39
+ end
40
+ end
41
+
42
+ module Code
43
+ include ::Haml::Filters::Base
44
+
45
+ def render(text, lang = :general)
46
+ ::StaticCms::Helpers.to_code(text, lang)
47
+ end
48
+ end
49
+
50
+ module CodeFile
51
+ include ::Haml::Filters::Base
52
+
53
+ def render(file)
54
+ file.strip!
55
+ lang = ::StaticCms::Helpers::EXT_TO_LANG[File.extname(file)]
56
+ text = File.read(file)
57
+ ::StaticCms::Helpers.to_code(text, lang)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ module ::StaticCms::Patch
2
+ %w(
3
+ haml
4
+ ).each{|lib|
5
+ require "static_cms/patch/#{lib}"
6
+ }
7
+ end
@@ -1,3 +1,3 @@
1
1
  module ::StaticCms
2
- VERSION = '0.0.0'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/static_cms.rb CHANGED
@@ -2,6 +2,9 @@ module StaticCms
2
2
  require 'fileutils'
3
3
  require 'ruby_patch'
4
4
 
5
+ require 'static_cms/version'
6
+ require 'static_cms/patch'
7
+
5
8
  SITE_TEMPLATE_DIR = File.join(__DIR__, '../data/site_template')
6
9
 
7
10
  module Command
@@ -35,7 +38,7 @@ git commit -m 'Copied from site template.' > #{File::NULL}
35
38
 
36
39
  CONFIG_DEFAULT = {
37
40
  'lang' => 'en',
38
- 'www' => '.',
41
+ 'www' => nil,
39
42
  'dir' => File.join(__DIR__, 'root'),
40
43
  'author' => '',
41
44
  'robots' => 'noarchive',
@@ -47,10 +50,12 @@ git commit -m 'Copied from site template.' > #{File::NULL}
47
50
  attr_accessor *(CONFIG_DEFAULT.keys)
48
51
 
49
52
  def initialize
50
- @pages = YAML.load_file('pages.yaml')\
51
- .to_a.map{|name, params| ::StaticCms::Page.new(self, name, params)}
52
53
  config = CONFIG_DEFAULT.merge(YAML.load_file('config.yaml'))
54
+ @www = config.delete('www')
55
+ @www += '/' unless @www[-1] == '/'
53
56
  config.each{|k, v| instance_variable_set("@#{k}", v)}
57
+ @pages = YAML.load_file('pages.yaml')\
58
+ .to_a.map{|name, params| ::StaticCms::Page.new(self, name, params)}
54
59
  end
55
60
  end
56
61
 
@@ -60,12 +65,12 @@ git commit -m 'Copied from site template.' > #{File::NULL}
60
65
 
61
66
  PARAMS_DEFAULT ={
62
67
  'visible' => true,
63
- 'titile' => '',
68
+ 'title' => '',
64
69
  'template' => 'default',
65
70
  'articles' => [],
66
71
  'statics' => [],
67
72
  'sources' => [],
68
- 'base' => ::StaticCms::Site::CONFIG_DEFAULT['www'],
73
+ 'base' => nil,
69
74
  }
70
75
 
71
76
  attr_accessor :site, :name, :dir
@@ -77,16 +82,17 @@ git commit -m 'Copied from site template.' > #{File::NULL}
77
82
  @dir = File.join("root", @name)
78
83
  params = PARAMS_DEFAULT.merge(params)
79
84
  @template = File.join('templates', params.delete('template')) + '.html.haml'
80
- @articles = params.delete('articles').map{|name| ::StaticCms::Article.new(name)}
85
+ @articles = params.delete('articles').map{|name| ::StaticCms::Article.use(self, name)}
81
86
  @statics = params.delete('statics').map{|file| File.join('statics', file)}
82
87
  @sources = params.delete('sources').map{|file| File.join('sources', file)}
88
+ @base = params.delete('base') || @site.www
83
89
  params.each{|k, v|
84
90
  instance_variable_set("@#{k}", v)
85
91
  }
86
92
  end
87
93
 
88
94
  def generate
89
- FileUtils.mkdir_p @dir
95
+ FileUtils.mkdir_p(@dir)
90
96
 
91
97
  if @visible
92
98
  @statics.each{|file| cp_if_new(file)}
@@ -113,6 +119,14 @@ git commit -m 'Copied from site template.' > #{File::NULL}
113
119
  ::Haml::Engine.new(text).render(self)
114
120
  end
115
121
 
122
+ def link_to_article(name)
123
+ article = ::StaticCms::Article.alist[name]
124
+ page = article.pages.first
125
+ url = File.join(@site.www, page.name, "index.html\##{name}")
126
+
127
+ "<a href='#{url}'>#{article.title}</a>"
128
+ end
129
+
116
130
  def cp_if_new(source)
117
131
  target = static_target(source)
118
132
  if !File.file?(target) || File.mtime(source) > File.mtime(target)
@@ -143,20 +157,72 @@ git commit -m 'Copied from site template.' > #{File::NULL}
143
157
  end
144
158
  end
145
159
 
160
+ module Helpers
161
+ require 'haml'
162
+
163
+ EXT_TO_LANG = Hash.new(:general)\
164
+ .merge({
165
+ '.f90' => :fortran,
166
+ '.f95' => :fortran,
167
+ '.f03' => :fortran,
168
+ '.f08' => :fortran,
169
+ '.f' => :fortran,
170
+ '.f77' => :fortran,
171
+ '.rb' => :ruby,
172
+ })
173
+
174
+ module_function
175
+
176
+ def to_plain(text)
177
+ escaped_text = ::Haml::Helpers.html_escape(text)
178
+ ::Haml::Helpers.preserve(escaped_text)
179
+ end
180
+
181
+ def to_code(text, lang = :general)
182
+ pre_text = to_plain(text)
183
+ "<pre class='code'><code class='#{lang}'>#{pre_text}</code></pre>"
184
+ end
185
+ end
186
+
146
187
  class Article
188
+ @alist = Hash.new{|h, k| raise KeyError, k.to_s}
189
+
190
+ def self.alist
191
+ @alist
192
+ end
193
+
147
194
  PARAMS_DEFAULT = {
148
195
  'title' => '',
149
196
  }
150
197
 
151
- attr_accessor :name, :file, :data
198
+ attr_accessor :pages, :name, :file, :data
152
199
  attr_accessor *(PARAMS_DEFAULT.keys)
153
200
 
154
201
  def initialize(name)
202
+ @pages = []
155
203
  @name = name
156
204
  @file = File.join('articles', name) + '.html.yhaml'
157
205
  yaml, @data = File.read(@file).split(/^\.\.\.$/, 2)
158
206
  params = PARAMS_DEFAULT.merge(YAML.load(yaml))
159
207
  params.each{|k, v| instance_variable_set("@#{k}", v)}
208
+ self.class.alist[@name] = self
209
+ end
210
+
211
+ def self.load
212
+ `git ls-files articles`.split\
213
+ .select{|f| f =~ /\.html\.yhaml\z/}\
214
+ .map{|f| f.sub(/\Aarticles\//, '')}\
215
+ .map{|f| File.basename(f, '.html.yhaml')}\
216
+ .each{|name| self.new(name)}
217
+ end
218
+
219
+ def self.use(page, name)
220
+ self.load unless self.alist.has_key?(name)
221
+ raise ArgumentError, name unless self.alist.has_key?(name)
222
+
223
+ article = self.alist[name]
224
+ article.pages << page
225
+ article
160
226
  end
161
227
  end
162
228
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-01 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
16
- requirement: &81251070 !ruby/object:Gem::Requirement
16
+ requirement: &71033130 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81251070
24
+ version_requirements: *71033130
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sass
27
- requirement: &81175110 !ruby/object:Gem::Requirement
27
+ requirement: &71031440 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.2'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *81175110
35
+ version_requirements: *71031440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby_patch
38
- requirement: &81173090 !ruby/object:Gem::Requirement
38
+ requirement: &71045200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.1'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *81173090
46
+ version_requirements: *71045200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: thor
49
- requirement: &81172130 !ruby/object:Gem::Requirement
49
+ requirement: &71044240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0.16'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *81172130
57
+ version_requirements: *71044240
58
58
  description: Simple static contents management system based on Haml and Sass.
59
59
  email:
60
60
  executables:
@@ -71,13 +71,15 @@ files:
71
71
  - data/site_template/pages.yaml
72
72
  - data/site_template/rakefile
73
73
  - data/site_template/sources/default.css.sass
74
- - data/site_template/statics/favicon.png
75
74
  - data/site_template/statics/ht_files/top/.htaccess
76
75
  - data/site_template/templates/blank.html.haml
77
76
  - data/site_template/templates/default.html.haml
78
77
  - data/site_template/templates/head.html.haml
79
78
  - data/site_template/templates/moved.html.haml
79
+ - data/site_template/templates/nav.html.haml
80
80
  - lib/static_cms.rb
81
+ - lib/static_cms/patch.rb
82
+ - lib/static_cms/patch/haml.rb
81
83
  - lib/static_cms/version.rb
82
84
  - rakefile
83
85
  - static_cms.gemspec
Binary file