scms 3.2.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTQyZDcwZTdiYzYyZmM4YzQyY2Q2NTNlMWRkNjQ0ZjQ1ZDFkNTVkNA==
4
+ NDRkYmE3ODg1NzQzMDQ3NjcwYjJlNTAxNTk4YWJiYzg4MzQ5MmI0MA==
5
5
  data.tar.gz: !binary |-
6
- YWNhMDA4Y2QxOGRmODJkYTExZDE2N2UzMWNiYjI3M2M5ZWM5ZWMyYQ==
6
+ YjliNjY2YzNhNTFmYzg1NjI2Y2I1ZjE3NTg0NmExMDY4ODA2ZWJkZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTdkNTc3ZjNmMTgxNjNlNGVjZGRlZDdiMWEwMzIwMzY4YzBhMDQwZGIwYjQ1
10
- ZjZmODY5NDliMzg3ZDA5YjRlMmVkZWM3ZTJhMjBjM2IxYzgyNmVmYzgwZjUw
11
- MTI4MWFjYTA0YTU1OTM4ZmJhOGRjZjljOWY0NGQxN2UwZWMyZjQ=
9
+ ODdlZWEzZGM0MDQ2NTA5MzczOTQzZDMwYzY2Y2Q2NTA5Nzg0NzExYjE3NzA3
10
+ NGU5OGQzYjEyNmZhMWY4NTA1NWVkNmFhNDUwYjJjYzZiYjA3NTI5ZTM3N2Q2
11
+ MDA3NmRmYjE3NDViNTY4OWE3ZjdlNTkwODY4M2M1NTg3N2IxZWU=
12
12
  data.tar.gz: !binary |-
13
- NGVmNjYzYmUzN2ZkNGRhMmIzNTRkM2M0MjY0NzBmYjgzZjYzYjYyNDliYmZk
14
- NTJiNjkxZTZhZDEwYjI3NDFjY2U1YjYyOTY0YjY0ZjA1NDA5ZWFiMDVkNTQw
15
- ZTM1ZTk1OTkzNTViZWQ2ZTU5NWY5NTkzYmM1NDg1OWFjMDZkZDM=
13
+ NTMyYTMwMGVlMzNiODZjZDg2MmUzOTk4MTMxZTRjMDFkMWZmZjRmMGUyOWIw
14
+ M2YyY2RiZmQzYWUyNjRiYzczOTI1YWQ4OTVmN2Q2ZmU2MzQ2Y2Y1NzM2MjMw
15
+ M2E4OTRjNGQyZWM2NGFlYTA3OWRmZjI2YmMxZjczZTAxYzhhY2Q=
data/bin/scms CHANGED
@@ -118,18 +118,20 @@ if options[:create] != nil
118
118
  exit
119
119
  end
120
120
 
121
- monkeyhook = File.join(Folders[:website], "scripts", "air-monkey-hook.js")
121
+ monkeyhookDir = File.join(Folders[:website], "scripts")
122
+ monkeyhook = File.join(monkeyhookDir, "air-monkey-hook.js")
122
123
  if options[:mode] == "cms"
124
+ Dir.mkdir(monkeyhookDir, 755) unless File::directory?(monkeyhookDir)
123
125
  FileUtils.cp(File.join(Folders[:assets], "air-monkey-hook.js"), monkeyhook)
124
126
  else
125
127
  FileUtils.rm(monkeyhook) if File.exist?(monkeyhook) && options[:publish]
126
128
  end
127
129
 
128
- settings = Scms.getsettings(Folders[:config])
130
+ settings = Scms.getSettings(Folders[:config])
129
131
  Scms.sassall(Folders[:website])
130
132
  Scms.bundle(settings, Folders[:website])
131
- Scms.build(Folders[:website], settings, options[:mode])
132
- Scms.copywebsite(Folders[:website], Folders[:destination]) if Folders[:destination] != ''
133
+ Scms.build(Folders[:website], settings, options)
134
+ Scms.copyWebsite(Folders[:website], Folders[:destination]) if Folders[:destination] != ''
133
135
 
134
136
  if options[:watch]
135
137
  ScmsWatcher.watch(settings, options, Folders[:config])
data/lib/scms.rb CHANGED
@@ -1,11 +1,13 @@
1
- require "scms/version"
2
-
3
1
  module Scms
2
+ require "scms/version"
3
+ require 'scms/scms-pageoptions.rb'
4
4
  require 'scms/scms-helpers.rb'
5
5
  require 'scms/scms-utils.rb'
6
6
  require 'scms/scms-xmlhandler.rb'
7
7
  require 'scms/s3deploy.rb'
8
8
 
9
+ require 'fileutils'
10
+ require 'pathname'
9
11
  require 'erb'
10
12
  require 'ostruct'
11
13
  require 'yaml'
@@ -15,7 +17,7 @@ module Scms
15
17
 
16
18
  include YAML
17
19
 
18
- def Scms.getsettings(configdir)
20
+ def Scms.getSettings(configdir)
19
21
  yamlpath=File.join(configdir, "_config.yml")
20
22
  settings = ScmsUtils.readyaml(yamlpath)
21
23
  if settings
@@ -25,9 +27,8 @@ module Scms
25
27
  end
26
28
  end
27
29
 
28
- def Scms.build(website, settings, mode = "pub")
29
- @mode = mode
30
- #ScmsUtils.log("Mode: #{mode}")
30
+ def Scms.build(website, settings, options)
31
+
31
32
 
32
33
  ScmsUtils.boldlog("Compiling #{website}")
33
34
 
@@ -49,7 +50,7 @@ module Scms
49
50
  ScmsUtils.writelog("type NUL > #{bootstrap}", website)
50
51
  end
51
52
  end
52
- Scms.parsepages(settings, website)
53
+ Scms.parsePages(website, settings, options)
53
54
  else
54
55
  ScmsUtils.errLog("Config is empty")
55
56
  end
@@ -58,232 +59,179 @@ module Scms
58
59
  ScmsUtils.log(ScmsUtils.uriEncode("file:///#{website}"))
59
60
  end
60
61
 
61
- def Scms.parsepages(settings, website)
62
- # build views from templates
63
-
64
- if settings["pages"] != nil
62
+ def Scms.parsePages(website, settings, options)
63
+ # build pages defined in config file
64
+ Scms.parseSettingsPages(website, settings, options)
65
+ # build pages pased on _pages folder
66
+ Scms.parseFolderPages(website, settings, options)
67
+ end
65
68
 
66
- # Build bundle model
67
- bundlemodel = Scms.bundlemodel(settings)
68
- # Build navigation model
69
- navmodel = Scms.navmodel(settings)
70
- #puts "navmodel: #{navmodel}"
69
+ def Scms.parseSettingsPages(website, settings, options)
70
+ if settings["pages"] != nil
71
71
 
72
72
  ScmsUtils.log("Compiling Pages:")
73
73
  settings["pages"].each do |pagedata|
74
74
  #puts "pagedata: #{pagedata}"
75
75
  if pagedata != nil
76
- pagedata.each do |pageoptions|
77
- pagename = pageoptions[0]
78
- pageconfig = pageoptions[1]
79
- pageurl = pageconfig["generate"]
80
- title = pagename
81
- title = pageconfig["title"] unless pageconfig["title"] == nil
82
- description = ""
83
- description = pageconfig["description"] if pageconfig["description"] != nil
84
- keywords = ""
85
- keywords = pageconfig["keywords"] if pageconfig["keywords"] != nil
86
- skin = settings["template"]
87
- skin = pageconfig["template"] unless pageconfig["template"] == nil
88
-
89
- resource = Hash.new
90
- if pageconfig["resource"] != nil
91
- resourcepath = File.join(website, pageconfig["resource"])
92
- if File.exists?(resourcepath)
93
- #ScmsUtils.log( "_Resource found: #{pageconfig["resource"]}_" )
94
- begin
95
- resource = YAML.load_file(resourcepath)
96
- rescue Exception=>e
97
- ScmsUtils.errLog(e.message)
98
- ScmsUtils.log(e.backtrace.inspect)
99
- end
100
- else
101
- ScmsUtils.errLog("Resource not found: #{pageconfig["resource"]}")
102
- ScmsUtils.writelog("::Resource not found #{pageconfig["resource"]}", website)
103
- ScmsUtils.writelog("type NUL > #{resourcepath}", website)
104
- end
105
- end
106
-
107
- hasHandler = false
108
- if pageconfig["handler"] != nil
109
- handlerpath = File.join(website, pageconfig["handler"])
110
- if File.exists?(handlerpath)
111
- ScmsUtils.log( "Handler found: #{pageconfig["handler"]}" )
112
- hasHandler = true
113
- begin
114
- require handlerpath
115
- # #hasHandler = ScmsHandler.instance_methods(false).include? :render
116
- # hasHandler = ScmsHandler.method_defined?(:render)
117
- # puts "has render method: #{hasHandler}"
118
- # if !hasHandler
119
- # ScmsUtils.errLog( "Handler doesnt have a render method" )
120
- # end
121
- rescue Exception => e
122
- ScmsUtils.errLog( "Problem running: ScmsHandler: #{e.message}" )
123
- end
124
- else
125
- ScmsUtils.errLog("Handler not found: #{pageconfig["handler"]}")
126
- ScmsUtils.writelog("::Handler not found #{pageconfig["handler"]}", website)
127
- ScmsUtils.writelog("type NUL > #{handlerpath}", website)
128
- end
129
- end
130
-
131
- views = Hash.new
132
- if pageconfig["views"] != nil
133
- pageconfig["views"].each do |view|
134
- views[view[0]] = ""
135
- viewparts = view[1].split("?") # This allows views to have a query string in the config
136
- viewname = viewparts[0]
137
- viewqs = viewparts[1]
138
-
139
- #puts "viewname: #{viewname}, viewqs: #{viewqs}"
140
-
141
- viewpath = File.join(website, viewname)
142
-
143
-
144
- if File.exists?(viewpath)
145
- begin
146
- htmlsnipet = File.read(viewpath)
147
- rescue Exception=>e
148
- ScmsUtils.errLog(e.message)
149
- ScmsUtils.log(e.backtrace.inspect)
150
- end
151
-
152
- if htmlsnipet.empty?
153
- ScmsUtils.log("Empty view: #{view[1]}")
154
- end
155
-
156
- model = Hash.new
157
- model = Hash[viewqs.split('&').map{ |q| q.split('=') }] if viewqs != nil
158
-
159
- viewmodel = Hash.new
160
- viewmodel = {
161
- :name => pagename,
162
- :title => title,
163
- :url => pageurl,
164
- :data => pagedata,
165
- :rootdir => website,
166
- :resource => resource,
167
- :view => {
168
- :name => viewname,
169
- :model => model
170
- }
171
- }
172
-
173
- if hasHandler
174
- ScmsUtils.log("Rendering with handler")
175
- begin
176
- viewSnippet = ScmsHandler.render(viewpath)
177
- rescue Exception=>e
178
- ScmsUtils.errLog(e.message)
179
- ScmsUtils.log(e.backtrace.inspect)
180
- end
181
-
182
- else
183
- #todo: why not use htmlsnipet
184
- snnipetCode = File.read(viewpath)
185
-
186
- case File.extname(view[1])
187
- when ".xml"
188
- viewSnippet = ScmsXmlHandler.transform(snnipetCode)
189
- when ".md"
190
- begin
191
- snnipetCode = snnipetCode.encode('UTF-8', :invalid => :replace, :undef => :replace)
192
- doc = Maruku.new(snnipetCode)
193
- viewSnippet = doc.to_html
194
- rescue Exception => e
195
- viewSnippet = snnipetCode
196
- ScmsUtils.errLog(e.message)
197
- ScmsUtils.log(e.backtrace.inspect)
198
- end
199
- else
200
- viewSnippet = snnipetCode
201
- end
202
- end
203
-
204
- if @mode == "cms"
205
- views[view[0]] = "<div class='cms' data-view='#{view[1]}' data-page='#{pageurl}'>#{Scms.parsetemplate(viewSnippet, viewmodel)}</div>"
206
- else
207
- views[view[0]] = Scms.parsetemplate(viewSnippet, viewmodel)
208
- end
209
- else
210
- ScmsUtils.errLog("View not found: #{view[0]} - #{view[1]} [#{viewpath}]")
211
- ScmsUtils.writelog("::View not found: #{view[0]} - #{view[1]} [#{viewpath}]", website)
212
- ScmsUtils.writelog("type NUL > #{viewpath}", website)
213
- end
214
- #ScmsUtils.log( "view = #{view[0]} - #{view[1]}" )
215
- end
216
- end
76
+ pagedata.each do |pageOptions|
77
+ pagename = pageOptions[0]
78
+ pageconfig = pageOptions[1]
217
79
 
218
- monkeyhook = "";
219
- monkeyhook = "<script src='scripts/air-monkey-hook.js'></script>" if @mode == "cms"
80
+ pageOptions = PageOptions.new(pagename, website, pageconfig, settings)
81
+ views = Scms.getSettingsViews(pageconfig["views"], website, pageOptions, options)
220
82
 
221
- livereload = ""
222
- if @mode != "deploy"
223
- livereload = "<script>document.write('<script src=\"http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1\"></' + 'script>')</script>" if @mode != "cms"
224
- end
225
-
226
- pagemodel = Hash.new
227
- pagemodel = {
228
- :name => pagename,
229
- :title => title,
230
- :description => description,
231
- :keywords => keywords,
232
- :url => pageurl,
233
- :views => views,
234
- :resource => resource,
235
- :config => pageconfig,
236
- :bundles => bundlemodel,
237
- :navigation => navmodel,
238
- :data => pagedata,
239
- :rootdir => website,
240
- :monkeyhook => monkeyhook,
241
- :livereload => livereload
242
- }
243
-
244
- break if pageconfig["generate"] == nil
245
-
246
- erb = File.join(website, skin)
247
- out = File.join(website, File.join(pageconfig["generate"].sub('~/','')))
248
-
249
- #ScmsUtils.log("Generating: #{pageurl} with #{skin}")
83
+ # Dont save a page if no views have been defined (so the config han have pages for nav building)
84
+ break if views.length < 1
85
+ Scms.save(settings, website, pageOptions, views, options)
86
+ end
87
+ end
88
+ #ScmsUtils.log( out )
89
+ end
90
+ end
91
+ end
250
92
 
251
- if File.exists?(erb)
252
- pubsubdir = File.dirname(out)
253
- Dir.mkdir(pubsubdir, 755) unless File::directory?(pubsubdir)
93
+ def Scms.getSettingsViews(settingsViews, website, pageOptions, options)
94
+ views = Hash.new
95
+ if settingsViews != nil
96
+ settingsViews.each do |view|
97
+ viewname = view[0]
98
+ viewparts = view[1].split("?") # This allows views to have a query string in the config
99
+ viewpath = viewparts[0]
100
+ viewqs = viewparts[1]
101
+
102
+ viewModel = Hash.new
103
+ viewModel = Hash[viewqs.split('&').map{ |q| q.split('=') }] if viewqs != nil
104
+ views[viewname] = Scms.parseView(viewname, viewpath, website, pageOptions, options, viewModel)
105
+ end
106
+ end
107
+ return views
108
+ end
254
109
 
255
- erbtemplate = File.read(erb)
110
+ def Scms.parseFolderPages(website, settings, options)
111
+ pagesFolder = File.join(website, "_pages")
112
+ Dir.glob("#{pagesFolder}/**/*/").each do |pageFolder|
113
+ pagename = File.basename(pageFolder, ".*")
114
+ #puts "pagename: #{pagename}"
115
+
116
+ pageconfig = nil
117
+ pageconfig = Scms.getSettings(pageFolder) if File.exists?(File.join(pageFolder, "_config.yml"))
118
+ pageOptions = PageOptions.new(pagename, website, pageconfig, settings)
119
+ views = Hash.new
120
+ if pageconfig != nil
121
+ views = Scms.getSettingsViews(pageconfig["views"], website, pageOptions, options) if pageconfig["views"] != nil
122
+ end
123
+
124
+ Dir.glob(File.join(pageFolder, "*")).reject { |f| f =~ /\.yml$/ || File.directory?(f) }.each do |view|
125
+ viewname = File.basename(view, ".*")
126
+ viewpath = Pathname.new(view).relative_path_from(Pathname.new(website)).to_s
127
+ views[viewname] = Scms.parseView(viewname, viewpath, website, pageOptions, options)
128
+ end
129
+ Scms.save(settings, website, pageOptions, views, options)
130
+ end
131
+ end
256
132
 
257
- #puts "pagemodel: #{pagemodel}"
258
- #html = ""
259
- html = Scms.parsetemplate(erbtemplate, pagemodel)
133
+ def Scms.parseView(viewname, viewpath, website, pageOptions, options, viewModel = nil)
134
+ #puts "parsing view: #{viewname}"
260
135
 
261
- html = html.gsub('~/', ScmsUtils.uriEncode("file:///#{website}/")) if @mode == "cms"
262
- websiteroot = '/'
263
- websiteroot = settings["url"] unless settings["rooturl"] == nil
136
+ viewhtml = ""
137
+ viewfullpath = File.join(website, viewpath)
264
138
 
265
- html = html.gsub('~/', websiteroot)
266
- begin
267
- File.open(out, 'w') {|f| f.write(html) }
268
- rescue Exception=>e
269
- ScmsUtils.errLog(e.message)
270
- ScmsUtils.log(e.backtrace.inspect)
271
- end
272
- else
273
- ScmsUtils.errLog("Template doesn't exist: #{skin}")
274
- ScmsUtils.writelog("::Template doesn't exist #{skin}", website)
275
- ScmsUtils.writelog("type NUL > #{erb}", website)
276
- end
139
+ if File.exists?(viewfullpath)
140
+ begin
141
+ htmlsnipet = File.read(viewfullpath)
142
+ rescue Exception=>e
143
+ ScmsUtils.errLog(e.message)
144
+ ScmsUtils.log(e.backtrace.inspect)
145
+ end
146
+
147
+ if htmlsnipet.empty?
148
+ ScmsUtils.log("Empty view: #{viewpath}")
149
+ end
277
150
 
278
- ScmsUtils.successLog("Generated: #{pageurl}")
151
+ hasHandler = false
152
+ if pageOptions.handler != nil
153
+ handlerpath = File.join(website, pageOptions.handler)
154
+ if File.exists?(handlerpath)
155
+ ScmsUtils.log( "Handler found: #{pageOptions.handler}" )
156
+ hasHandler = true
157
+ begin
158
+ require handlerpath
159
+ # #hasHandler = ScmsHandler.instance_methods(false).include? :render
160
+ # hasHandler = ScmsHandler.method_defined?(:render)
161
+ # puts "has render method: #{hasHandler}"
162
+ # if !hasHandler
163
+ # ScmsUtils.errLog( "Handler doesnt have a render method" )
164
+ # end
165
+ rescue Exception => e
166
+ ScmsUtils.errLog( "Problem running: ScmsHandler: #{e.message}" )
279
167
  end
168
+ else
169
+ ScmsUtils.errLog("Handler not found: #{pageOptions.handler}")
170
+ ScmsUtils.writelog("::Handler not found #{pageOptions.handler}", website)
171
+ ScmsUtils.writelog("type NUL > #{handlerpath}", website)
280
172
  end
281
- #ScmsUtils.log( out )
282
173
  end
174
+
175
+ if hasHandler
176
+ ScmsUtils.log("Rendering with handler")
177
+ begin
178
+ viewSnippet = ScmsHandler.render(viewpath)
179
+ rescue Exception=>e
180
+ ScmsUtils.errLog(e.message)
181
+ ScmsUtils.log(e.backtrace.inspect)
182
+ end
183
+ else
184
+ case File.extname(viewpath)
185
+ when ".xml"
186
+ viewSnippet = ScmsXmlHandler.transform(htmlsnipet)
187
+ when ".md"
188
+ begin
189
+ htmlsnipet = htmlsnipet.encode('UTF-8', :invalid => :replace, :undef => :replace)
190
+ doc = Maruku.new(htmlsnipet)
191
+ viewSnippet = doc.to_html
192
+ rescue Exception => e
193
+ viewSnippet = htmlsnipet
194
+ ScmsUtils.errLog(e.message)
195
+ ScmsUtils.log(e.backtrace.inspect)
196
+ end
197
+ else
198
+ viewSnippet = htmlsnipet
199
+ end
200
+ end
201
+
202
+ viewmodel = Hash.new
203
+ viewmodel = {
204
+ :name => pageOptions.name,
205
+ :title => pageOptions.title,
206
+ :url => pageOptions.url,
207
+ :resource => pageOptions.resource,
208
+ :rootdir => website,
209
+ :view => {
210
+ :name => viewname,
211
+ :path => viewfullpath,
212
+ :model => viewModel
213
+ }
214
+ }
215
+
216
+ if options[:mode] == "cms"
217
+ viewhtml = "<div class='cms' data-view='#{viewpath}' data-page='#{pageOptions.url}'>#{Scms.render(viewSnippet, viewmodel)}</div>"
218
+ else
219
+ viewhtml = Scms.render(viewSnippet, viewmodel)
220
+ end
221
+ else
222
+ ScmsUtils.errLog("View not found: #{viewname} [#{viewpath}]")
223
+ ScmsUtils.writelog("::View not found: #{viewname} [#{viewpath}]", website)
224
+ ScmsUtils.writelog("type NUL > #{viewpath}", website)
283
225
  end
226
+
227
+ return viewhtml
284
228
  end
285
229
 
286
230
  def Scms.parsetemplate(template, hash = Hash.new)
231
+ return Scms.render(template, hash)
232
+ end
233
+
234
+ def Scms.render(template, hash = Hash.new)
287
235
  result = ""
288
236
  if template != nil
289
237
  begin
@@ -291,22 +239,29 @@ module Scms
291
239
  page = hash
292
240
  else
293
241
  page = OpenStruct.new(hash)
294
- end
242
+ end
295
243
 
296
244
  erb = ERB.new(template)
297
245
  result = erb.result(page.instance_eval { binding })
298
246
  rescue StandardError => e
247
+ puts "page: #{page}"
299
248
  ScmsUtils.errLog("Critical Error: Could not parse template")
300
- #ScmsUtils.errLog(e.message)
301
- #puts e.inspect
249
+ ScmsUtils.errLog(e.message)
302
250
 
303
- result = "Invalid Keys in Template\n\n"
251
+ result = "<code style='border: 1px solid #666; background-color: light-yellow;'><pre>"
252
+ result += e.message
253
+ result += "\n\n"
254
+ result += e.inspect
255
+ result += "\n\n"
256
+ result += "Invalid Keys in Template\n\n"
304
257
  result += "Valid Keys are:\n"
305
258
  hash.each do |key, value|
306
259
  result += "- page.#{key}\n"
307
260
  puts "nil value foy key: #{key}" if value == nil
308
261
  singleton_class.send(:define_method, key) { value }
309
262
  end
263
+ result = "</code></pre>"
264
+
310
265
 
311
266
  result += "\n\n"
312
267
  result += template
@@ -320,41 +275,140 @@ module Scms
320
275
  return result
321
276
  end
322
277
 
323
- def Scms.bundlemodel(settings)
324
- puts "Bundeling Assets"
325
- bundlemodel = Hash.new
278
+ def Scms.save(settings, website, pageOptions, views, options)
279
+
280
+ fileName = File.join(website, File.join(pageOptions.url.sub('~/','')))
281
+ erb = File.join(website, pageOptions.template)
282
+ #ScmsUtils.log("Generating: #{fileName} with #{pageOptions.template}")
283
+
284
+ if File.exists?(erb)
285
+
286
+ # Build bundle model
287
+ bundleModel = Scms.bundleModel(website, settings, options)
288
+ # Build navigation model
289
+ navModel = Scms.navModel(website, settings, options)
290
+ #puts "navModel: #{navModel}"
291
+
292
+ monkeyhook = "";
293
+ monkeyhook = "<script src='scripts/air-monkey-hook.js'></script>" if options[:mode] == "cms"
294
+
295
+ livereload = ""
296
+ if options[:watch]
297
+ livereload = "<script async='true' defer='true'>document.write('<script src=\"http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1\"></' + 'script>')</script>" if options[:mode] != "cms"
298
+ end
299
+
300
+ pagemodel = Hash.new
301
+ pagemodel = {
302
+ :name => pageOptions.name,
303
+ :title => pageOptions.title,
304
+ :description => pageOptions.description,
305
+ :keywords => pageOptions.keywords,
306
+ :url => pageOptions.url,
307
+ :resource => pageOptions.resource,
308
+ :bundles => bundleModel,
309
+ :navigation => navModel,
310
+ :views => views,
311
+ :rootdir => website,
312
+ :monkeyhook => monkeyhook,
313
+ :livereload => livereload
314
+ }
315
+
316
+ #puts "pagemodel:"
317
+ #puts pagemodel
318
+
319
+ pubsubdir = File.dirname(fileName)
320
+ Dir.mkdir(pubsubdir, 755) unless File::directory?(pubsubdir)
321
+
322
+ erbtemplate = File.read(erb)
323
+
324
+ #puts "pagemodel: #{pagemodel}"
325
+ #html = ""
326
+ html = Scms.render(erbtemplate, pagemodel)
327
+
328
+
329
+ websiteroot = '/'
330
+ websiteroot = settings["rooturl"] if settings["rooturl"] != nil
331
+ #puts "On save mode: #{options[:mode]}"
332
+ websiteroot = ScmsUtils.uriEncode("file:///#{website}/") if options[:mode] == "cms"
333
+
334
+ html = html.gsub('~/', websiteroot)
335
+ begin
336
+ File.open(fileName, 'w') {|f| f.write(html) }
337
+ ScmsUtils.successLog("Generated: #{pageOptions.url}")
338
+ rescue Exception=>e
339
+ ScmsUtils.errLog(e.message)
340
+ ScmsUtils.log(e.backtrace.inspect)
341
+ end
342
+ else
343
+ ScmsUtils.errLog("Template doesn't exist: #{pageOptions.template}")
344
+ ScmsUtils.writelog("::Template doesn't exist #{pageOptions.template}", website)
345
+ ScmsUtils.writelog("type NUL > #{erb}", website)
346
+ end
347
+ end
348
+
349
+ def Scms.navModel(website, settings, options)
350
+ websiteroot = '/'
351
+ websiteroot = settings["rooturl"] unless settings["rooturl"] == nil
352
+ websiteroot = ScmsUtils.uriEncode("file:///#{website}/") if options[:mode] == "cms"
353
+
354
+ navModel = Array.new
355
+ if settings["pages"] != nil
356
+ settings["pages"].each do |pagedata|
357
+ if pagedata != nil
358
+ pagedata.each do |pageoptions|
359
+ pagename = pageoptions[0]
360
+ pageconfig = pageoptions[1]
361
+ pageurl = "about:blank"
362
+ pageurl = pageconfig["generate"]
363
+ pageurl = pageconfig["url"] unless pageconfig["url"] == nil
364
+ navtext = pageconfig["navigation"]
365
+ navmeta = pageconfig["navigation_meta"]
366
+ navModel.push({"text" => navtext, "url" => pageurl.gsub("~/", websiteroot), "pagename" => pagename, "meta" => navmeta}) unless navtext == nil
367
+ end
368
+ end
369
+ end
370
+ end
371
+ if settings["nav"] != nil
372
+ settings["nav"].each do |pagedata|
373
+ if pagedata != nil
374
+ pagedata.each do |pageoptions|
375
+ pagename = pageoptions[0]
376
+ pageconfig = pageoptions[1]
377
+ pageurl = "about:blank"
378
+ pageurl = pageconfig["url"] unless pageconfig["url"] == nil
379
+ navtext = pagename
380
+ navtext = pageconfig["text"]
381
+ navmeta = pageconfig["meta"]
382
+ navModel.push({"text" => navtext, "url" => pageurl.gsub("~/", websiteroot), "pagename" => pagename, "meta" => navmeta})
383
+ end
384
+ end
385
+ end
386
+ end
387
+ return navModel
388
+ end
389
+
390
+ def Scms.bundleModel(website, settings, options)
391
+ bundleModel = Hash.new
326
392
  bundleConfig = settings["bundles"]
327
393
  if bundleConfig != nil
328
394
  bundleConfig.each do |bundle|
329
395
  #ScmsUtils.log( "bundle (#{bundle.class}) = #{bundle}" )
396
+
397
+ websiteroot = '/'
398
+ websiteroot = settings["rooturl"] unless settings["rooturl"] == nil
399
+ websiteroot = ScmsUtils.uriEncode("file:///#{website}/") if options[:mode] == "cms"
400
+
330
401
  bundle.each do |option|
331
402
  name = option[0]
332
- bundleName = File.join(option[1]["generate"])
333
- bundlemodel[name] = bundleName
334
- end
335
- end
336
- end
337
- return bundlemodel
338
- end
403
+ config = option[1]
339
404
 
340
- def Scms.navmodel(settings)
341
- navmodel = Array.new
342
- settings["pages"].each do |pagedata|
343
- if pagedata != nil
344
- pagedata.each do |pageoptions|
345
- pagename = pageoptions[0]
346
- pageconfig = pageoptions[1]
347
- pageurl = "about:blank"
348
- pageurl = pageconfig["generate"]
349
- pageurl = pageconfig["url"] unless pageconfig["url"] == nil
350
- navtext = pageconfig["navigation"]
351
- navmeta = pageconfig["navigation_meta"]
352
- navmodel.push({"text" => navtext, "url" => pageurl, "pagename" => pagename, "meta" => navmeta}) unless navtext == nil
405
+ bundleName = File.join(config["generate"])
406
+ bundleModel[name] = bundleName.gsub("~/", websiteroot)
353
407
  end
354
408
  end
355
409
  end
356
- return navmodel
357
- end
410
+ return bundleModel
411
+ end
358
412
 
359
413
  def Scms.bundle(settings, website)
360
414
  bundleConfig = settings["bundles"]
@@ -364,12 +418,14 @@ module Scms
364
418
  #ScmsUtils.log( "bundle (#{bundle.class}) = #{bundle}" )
365
419
  bundle.each do |option|
366
420
  name = option[0]
367
- bundleName = File.join(option[1]["generate"])
421
+ config = option[1]
422
+
423
+ bundleName = File.join(config["generate"].gsub("~/",""))
368
424
  ScmsUtils.boldlog("Bundeling:")
369
425
 
370
426
  content = ""
371
427
  assetList = ""
372
- files = option[1]["files"]
428
+ files = config["files"]
373
429
  if files != nil
374
430
  files.each do |asset|
375
431
  assetList += " - #{asset}\n"
@@ -462,7 +518,7 @@ module Scms
462
518
  end
463
519
  end
464
520
 
465
- def Scms.copywebsite(website, pub)
521
+ def Scms.copyWebsite(website, pub)
466
522
  if pub.to_s.strip.length != 0
467
523
  FileUtils.mkdir pub unless Dir.exists? pub
468
524
  source = File.join(website)
@@ -0,0 +1,87 @@
1
+ module Scms
2
+ require 'fileutils'
3
+ require 'scms/scms-utils.rb'
4
+
5
+ class PageOptions
6
+ attr_accessor :name, :template, :url, :title, :keywords, :description, :resource, :handler
7
+
8
+ def name= name
9
+ @name = name
10
+ end
11
+
12
+ def template= template
13
+ @template = template
14
+ end
15
+
16
+ def url= url
17
+ @url = url
18
+ end
19
+
20
+ def title= title
21
+ @title = title
22
+ end
23
+
24
+ def keywords= keywords
25
+ @keywords = keywords
26
+ end
27
+
28
+ def description= description
29
+ @description = description
30
+ end
31
+
32
+ def resource= resource
33
+ @resource = resource
34
+ end
35
+
36
+ def handler= handler
37
+ @handler = handler
38
+ end
39
+
40
+ def initialize (name, website, pageconfig, siteConfig)
41
+ @name = name
42
+ @template = siteConfig["template"]
43
+ @url = "#{name}.html"
44
+ @title = name
45
+ @keywords = ""
46
+ @description = ""
47
+ @resource = Hash.new
48
+ @handler = nil
49
+
50
+ if pageconfig != nil
51
+ @template = pageconfig["template"] unless pageconfig["template"] == nil
52
+
53
+ @url = "#{name}/index.html" if pageconfig["cleanurl"] == true
54
+ @url = pageconfig["generate"] if pageconfig["generate"] != nil #depreciated
55
+ @url = pageconfig["url"] if pageconfig["url"] != nil
56
+
57
+ @title = pageconfig["title"] unless pageconfig["title"] == nil
58
+ @keywords = pageconfig["keywords"] if pageconfig["keywords"] != nil
59
+ @description = pageconfig["description"] if pageconfig["description"] != nil
60
+ @handler = pageconfig["handler"]
61
+ @resource = getResource(website, pageconfig["resource"])
62
+ end
63
+ end
64
+
65
+
66
+ def getResource(website, resource)
67
+ ymlresource = Hash.new
68
+ if resource != nil
69
+ resourcepath = File.join(website, resource)
70
+ if File.exists?(resourcepath)
71
+ #ScmsUtils.log( "_Resource found: #{pageOptions.resource}_" )
72
+ begin
73
+ ymlresource = YAML.load_file(resourcepath)
74
+ rescue Exception=>e
75
+ ScmsUtils.errLog(e.message)
76
+ ScmsUtils.log(e.backtrace.inspect)
77
+ end
78
+ else
79
+ ScmsUtils.errLog("Resource not found: #{resource}")
80
+ ScmsUtils.writelog("::Resource not found #{resource}", website)
81
+ ScmsUtils.writelog("type NUL > #{resourcepath}", website)
82
+ end
83
+ end
84
+ return ymlresource
85
+ end
86
+ end
87
+ end
@@ -20,17 +20,7 @@ module ScmsUtils
20
20
  end
21
21
 
22
22
  def ScmsUtils.readyaml(yamlpath)
23
- ScmsUtils.log("Loading yaml: #{ScmsUtils.uriEncode("file:///#{yamlpath}")}")
24
23
  config = nil
25
-
26
- ##http://snk.tuxfamily.org/log/yaml-json-validation-kwalify-ruby19.html
27
- #'kwalify'
28
- #schema = Kwalify::Yaml.load_file('some_complex_schema.yaml')
29
- #validator = Kwalify::Validator.new(schema)
30
- #parser = Kwalify::Yaml::Parser.new(validator)
31
- #yaml = some_complex_object.to_yaml # machine-generate
32
- #data = parser.parse(yaml) # parse & validate <== FAIL
33
-
34
24
  if File.exist?(yamlpath)
35
25
  tree = File.read(yamlpath)
36
26
  begin
@@ -40,6 +30,7 @@ module ScmsUtils
40
30
  #config = YAML.load_file(yamlpath)
41
31
  rescue Exception => e
42
32
  ScmsUtils.errLog("Error Loading _config.yml (check there are no tabs in the file)")
33
+ ScmsUtils.log("Yaml: #{ScmsUtils.uriEncode("file:///#{yamlpath}")}")
43
34
  ScmsUtils.log( "Verify your config")
44
35
  ScmsUtils.log( "http://yaml-online-parser.appspot.com/")
45
36
  ScmsUtils.errLog( e.message )
@@ -14,13 +14,15 @@ module ScmsWatcher
14
14
  puts "***********************************"
15
15
  puts ""
16
16
 
17
- settings = Scms.getsettings(configdir)
17
+ settings = Scms.getSettings(configdir)
18
18
  Scms.bundle(settings, Folders[:website])
19
- Scms.build(Folders[:website], settings, options[:mode])
19
+ Scms.build(Folders[:website], settings, options)
20
20
  end
21
21
  }
22
22
 
23
+ # [todo] Create this by getting all directories that start with _
23
24
  psst = []
25
+ psst.push("_pages") if File.directory? "_pages" # .html .htm .md .xml .erb, etc
24
26
  psst.push("_views") if File.directory? "_views" # .html .htm .md .xml .erb, etc
25
27
  psst.push("_layouts") if File.directory? "_layouts" # .html .htm .erb
26
28
  psst.push("_templates") if File.directory? "_templates" # .html .htm .erb
@@ -29,15 +31,46 @@ module ScmsWatcher
29
31
 
30
32
  puts "Listening to #{psst}"
31
33
  listener = Listen.to(psst, force_polling: true) do |modified, added, removed|
32
- # puts "modified: #{modified}" if modified.length > 0
33
- # puts "added: #{added}" if added.length > 0
34
- # puts "removed: #{removed}" if removed.length > 0
35
34
 
36
- if modified.length > 0
37
- sassfile = false
38
- bundlefile = false
39
- buildfile = true
35
+ sassfile = false
36
+ bundlefile = false
37
+ buildfile = false
38
+
39
+ if removed.length > 0
40
+ removed.each{|filename|
41
+ removedfile = Pathname.new(filename).relative_path_from(Pathname.new(Folders[:website])).to_s
42
+ #ext = File.extname(removedfile)
43
+
44
+ puts ""
45
+ puts "***********************************************"
46
+ puts " Deleted: #{removedfile}"
47
+ puts "***********************************************"
48
+ puts ""
49
+
50
+ if removedfile.start_with?('_pages/')
51
+ buildfile = true
52
+ end
53
+ }
54
+ end
55
+
56
+ if added.length > 0
57
+ added.each{|filename|
58
+ addedfile = Pathname.new(filename).relative_path_from(Pathname.new(Folders[:website])).to_s
59
+ #ext = File.extname(addedfile)
60
+
61
+ puts ""
62
+ puts "***********************************************"
63
+ puts " Added: #{addedfile}"
64
+ puts "***********************************************"
65
+ puts ""
40
66
 
67
+ if addedfile.start_with?('_pages/')
68
+ buildfile = true
69
+ end
70
+ }
71
+ end
72
+
73
+ if modified.length > 0
41
74
  modified.each{|filename|
42
75
  modifiedfile = Pathname.new(filename).relative_path_from(Pathname.new(Folders[:website])).to_s
43
76
  ext = File.extname(modifiedfile)
@@ -48,6 +81,8 @@ module ScmsWatcher
48
81
  puts "***********************************************"
49
82
  puts ""
50
83
 
84
+ buildfile = true
85
+
51
86
  if modifiedfile.start_with?('_source/')
52
87
  bundlefile = true
53
88
  buildfile = false
@@ -60,12 +95,13 @@ module ScmsWatcher
60
95
  break
61
96
  end
62
97
  }
63
-
64
- Scms.sassall(Folders[:website]) if sassfile
65
- Scms.bundle(settings, Folders[:website]) if bundlefile
66
- Scms.build(Folders[:website], settings, options[:mode]) if buildfile
67
98
  end
99
+
100
+ Scms.sassall(Folders[:website]) if sassfile
101
+ Scms.bundle(settings, Folders[:website]) if bundlefile
102
+ Scms.build(Folders[:website], settings, options) if buildfile
68
103
  end
104
+
69
105
  listener.start # not blocking
70
106
  listener.ignore! /\.png/
71
107
  listener.ignore! /\.gif/
data/lib/scms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Scms
2
- VERSION = "3.2.0"
2
+ VERSION = "4.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scms
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Courtenay Probert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cprobert-s3sync
@@ -191,6 +191,7 @@ files:
191
191
  - lib/scms/s3deploy.rb
192
192
  - lib/scms/scms-helpers.rb
193
193
  - lib/scms/scms-httpserver.rb
194
+ - lib/scms/scms-pageoptions.rb
194
195
  - lib/scms/scms-utils.rb
195
196
  - lib/scms/scms-watcher.rb
196
197
  - lib/scms/scms-xmlhandler.rb