static_cms 0.1.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,15 +3,10 @@ require 'static_cms'
3
3
  ::SITE = StaticCms::Site.new
4
4
  task default: :generate
5
5
  desc "Generate all pages."
6
- task generate: SITE.pages.map(&:name)
6
+ task generate: SITE.page_alist.keys
7
7
 
8
- ::SITE.pages.each{|page|
9
- task page.name do
8
+ ::SITE.page_alist.each{|name, page|
9
+ task name do
10
10
  page.generate
11
11
  end
12
12
  }
13
-
14
- desc "Update templates, sources, statics (and more)."
15
- task :update do
16
- ::StaticCms::Command.update
17
- end
@@ -2,5 +2,7 @@
2
2
  %html{lang: :en}
3
3
  = haml(File.read('templates/head.html.haml'))
4
4
  %body
5
- This page is intentionally left blank.
6
- %a{href: @site.www} Please go to the top page.
5
+ %p
6
+ This page is intentionally left blank.
7
+ %nav
8
+ = haml(File.read('templates/nav.html.haml'))
@@ -13,7 +13,4 @@
13
13
  = haml(article.data)
14
14
  %footer
15
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
16
+ = haml(File.read('templates/nav.html.haml'))
@@ -2,5 +2,7 @@
2
2
  %html{lang: :en}
3
3
  = haml(File.read('templates/head.html.haml'))
4
4
  %body
5
- Contents of this page have moved or removed.
6
- %a{href: @site.www} Please go to the top page.
5
+ %p
6
+ Contents of this page have moved or removed.
7
+ %nav
8
+ = haml(File.read('templates/nav.html.haml'))
@@ -0,0 +1,4 @@
1
+ %ul
2
+ - @site.page_alist.sort.select{|_, p| p.visible}.delete_if{|_, p| p.template == 'blank'}.each do |name, page|
3
+ %li
4
+ %a{href: File.join(@site.www, name)}= page.title
@@ -1,3 +1,3 @@
1
1
  module ::StaticCms
2
- VERSION = '0.1.1'
2
+ VERSION = '1.1.1'
3
3
  end
data/lib/static_cms.rb CHANGED
@@ -46,7 +46,7 @@ git commit -m 'Copied from site template.' > #{File::NULL}
46
46
  'charset' => 'utf-8',
47
47
  }
48
48
 
49
- attr_accessor :pages
49
+ attr_accessor :page_alist
50
50
  attr_accessor *(CONFIG_DEFAULT.keys)
51
51
 
52
52
  def initialize
@@ -54,8 +54,12 @@ git commit -m 'Copied from site template.' > #{File::NULL}
54
54
  @www = config.delete('www')
55
55
  @www += '/' unless @www[-1] == '/'
56
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)}
57
+ @page_alist = Hash.new{|h, k| raise KeyError, k}
58
+ YAML.load_file('pages.yaml')\
59
+ .sort\
60
+ .each{|name, params|
61
+ @page_alist[name] = ::StaticCms::Page.new(self, name, params)
62
+ }
59
63
  end
60
64
  end
61
65
 
@@ -73,7 +77,7 @@ git commit -m 'Copied from site template.' > #{File::NULL}
73
77
  'base' => nil,
74
78
  }
75
79
 
76
- attr_accessor :site, :name, :dir
80
+ attr_accessor :site, :name, :dir, :template_file
77
81
  attr_accessor *(PARAMS_DEFAULT.keys)
78
82
 
79
83
  def initialize(site, name, params = {})
@@ -81,7 +85,8 @@ git commit -m 'Copied from site template.' > #{File::NULL}
81
85
  @name = name
82
86
  @dir = File.join("root", @name)
83
87
  params = PARAMS_DEFAULT.merge(params)
84
- @template = File.join('templates', params.delete('template')) + '.html.haml'
88
+ @template = params.delete('template')
89
+ @template_file = File.join('templates', @template) + '.html.haml'
85
90
  @articles = params.delete('articles').map{|name| ::StaticCms::Article.use(self, name)}
86
91
  @statics = params.delete('statics').map{|file| File.join('statics', file)}
87
92
  @sources = params.delete('sources').map{|file| File.join('sources', file)}
@@ -97,14 +102,14 @@ git commit -m 'Copied from site template.' > #{File::NULL}
97
102
  if @visible
98
103
  @statics.each{|file| cp_if_new(file)}
99
104
  @sources.each{|file| compile(file)}
100
- template = @template
105
+ template_file = @template_file
101
106
  else
102
107
  @statics.each{|file| FileUtils.rm_rf(static_target(file))}
103
108
  @sources.each{|file| FileUtils.rm_rf(compile_target(file))}
104
- template = 'templates/moved.html.haml'
109
+ template_file = 'templates/moved.html.haml'
105
110
  end
106
111
 
107
- html = ::Haml::Engine.new(File.read(template)).render(self)
112
+ html = ::Haml::Engine.new(File.read(template_file)).render(self)
108
113
  target = File.join(@dir, 'index.html')
109
114
  open(target, 'w'){|io|
110
115
  io.write(html)
@@ -119,6 +124,11 @@ git commit -m 'Copied from site template.' > #{File::NULL}
119
124
  ::Haml::Engine.new(text).render(self)
120
125
  end
121
126
 
127
+ def nth_page_from_self(n)
128
+ index = (@site.page_alist.to_a.index{|name, page| name == @name} + n)%@site.page_alist.size
129
+ @site.page_alist.to_a[index][1]
130
+ end
131
+
122
132
  def link_to_article(name)
123
133
  article = ::StaticCms::Article.alist[name]
124
134
  page = article.pages.first
@@ -232,5 +242,10 @@ git commit -m 'Copied from site template.' > #{File::NULL}
232
242
  def init(dir = '.')
233
243
  ::StaticCms::Command.init(dir)
234
244
  end
245
+
246
+ desc "update", "Update templates, sources, statics (and more)."
247
+ def update
248
+ ::StaticCms::Command.update
249
+ end
235
250
  end
236
251
  end
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.1.1
4
+ version: 1.1.1
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-02 00:00:00.000000000 Z
12
+ date: 2012-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
16
- requirement: &75260150 !ruby/object:Gem::Requirement
16
+ requirement: &69398750 !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: *75260150
24
+ version_requirements: *69398750
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sass
27
- requirement: &75258430 !ruby/object:Gem::Requirement
27
+ requirement: &69397340 !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: *75258430
35
+ version_requirements: *69397340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby_patch
38
- requirement: &75273040 !ruby/object:Gem::Requirement
38
+ requirement: &69396770 !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: *75273040
46
+ version_requirements: *69396770
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: thor
49
- requirement: &75272260 !ruby/object:Gem::Requirement
49
+ requirement: &69396130 !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: *75272260
57
+ version_requirements: *69396130
58
58
  description: Simple static contents management system based on Haml and Sass.
59
59
  email:
60
60
  executables: