scms 4.0.3 → 4.1.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
- MTE5MWU1NDc5ZTM1MDNmNDQzMzI5M2U2NGZjNThlOTI3ZmQxMGI3NA==
4
+ NTRkMmQ1YTk0OWNlYmUxMTQ5ZWE5N2IwMTE1YmFjZmYzY2E3OWJiNg==
5
5
  data.tar.gz: !binary |-
6
- ZWUwYmE2ZTNmYWQyN2QwNGJjMmMxNTUyZGJlNDEyM2ZhY2I0MTJkOA==
6
+ MzcxZTg1YmMwNThmMjE1MGZhOTk4NDRiZDBkZTY5NjFlNzVlMTNiMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODc5MTRhMDQxNTllOGVmM2NlZTMzNmNmNmVlOTZkMWFiNDg0YTAyNzU0ZTgy
10
- MjE3MDExYzhmMWE5NTE5NDk2YjBkNWE4NDk4MzMwNmVjMDIzZDgzODcxMTY1
11
- NTc4NzMxMGFlNDkyOWMxOTM4MzY1ODY2MzNhNTU2ODJjYTQ1OWQ=
9
+ YTBiZGE3NmYzZTUyMmI5YjAyZWI3NDJjOTYzNGMwM2ZlZWQ1NzhmNzU2NzYz
10
+ MTJmZDIzMmZlMGNiZTM1YTRlMDVlZTE1MmZjZWZkNTVjMWJhZjg3ZDFmODBm
11
+ NTY4NTVkMjQ3MWRmYWY1OWRkYTBjNzA3M2U5ZDU3NDkwNDgzZjk=
12
12
  data.tar.gz: !binary |-
13
- NjY0MmQyY2U4ZjJlZTMzMTQ3MGM3ZDkxMTQ2MDE5YzI0N2IzZWIyNDY0MDA1
14
- MWUzNDEzOWFjYmViZmI1NDI5ZDE2NWU2NmUyZmI1ZTJhMDQzZjRiNjhmYWY4
15
- YTIyN2I4MTU1NzVhYjMwMzJlMDkzYjU1YjhiMTA1NDBlNWY3ODE=
13
+ YzFhZTYyNmVmMjlmODgwMWIzODk3MzEwMGNlZjAwMzBjY2EyYTVmZTdmODk1
14
+ MzlhZGZlNWI4ZDEwYjY2ZjBkMTEwZWU4OTc0NDYwMzM5NjY0NmM4ODQ2NDgw
15
+ Njg2M2JmMDgyNzE0NGM0M2RhZjU4ZDY0YzBjMGM4Nzg2ZmE2M2E=
@@ -37,7 +37,8 @@ $(function() {
37
37
 
38
38
  var addTextMsg = "Double click to add text";
39
39
  $this
40
- .bind("dblclick", function() {
40
+ .bind("dblclick", function(event) {
41
+ event.stopPropagation();
41
42
  editMe(this);
42
43
  })
43
44
  .attr("title", "Double click to edit")
data/lib/scms.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module Scms
2
2
  require "scms/version"
3
- require 'scms/scms-pageoptions.rb'
4
- require 'scms/scms-helpers.rb'
5
3
  require 'scms/scms-utils.rb'
4
+ require 'scms/scms-helpers.rb'
5
+ require 'scms/scms-pageoptions.rb'
6
+ require 'scms/scms-parser.rb'
6
7
  require 'scms/scms-xmlhandler.rb'
7
8
  require 'scms/s3deploy.rb'
8
9
 
@@ -48,7 +49,7 @@ module Scms
48
49
  ScmsUtils.writelog("type NUL > #{bootstrap}", website)
49
50
  end
50
51
  end
51
- Scms.parsePages(website, settings, options)
52
+ Scms.generatePages(website, settings, options)
52
53
  else
53
54
  ScmsUtils.errLog("Config is empty")
54
55
  end
@@ -57,18 +58,17 @@ module Scms
57
58
  ScmsUtils.log(ScmsUtils.uriEncode("file:///#{website}"))
58
59
  end
59
60
 
60
- def Scms.parsePages(website, settings, options)
61
+ def Scms.generatePages(website, settings, options)
61
62
  # build pages defined in config file
62
- Scms.parseSettingsPages(website, settings, options)
63
+ Scms.generateSettingsPages(website, settings, options)
63
64
  # build pages pased on _pages folder
64
- Scms.parseFolderPages(website, settings, options)
65
+ Scms.generateFolderPages(website, settings, options)
65
66
  end
66
67
 
67
- def Scms.parseSettingsPages(website, settings, options)
68
+ def Scms.generateSettingsPages(website, settings, options)
68
69
  if settings["pages"] != nil
69
70
  ScmsUtils.log("Compiling Pages:")
70
71
  settings["pages"].each do |pagedata|
71
- #puts "pagedata: #{pagedata}"
72
72
  if pagedata != nil
73
73
  pagedata.each do |pageOptions|
74
74
  pagename = pageOptions[0]
@@ -79,41 +79,39 @@ module Scms
79
79
 
80
80
  # Dont save a page if no views have been defined (so the config han have pages for nav building)
81
81
  break if views.length < 1
82
- Scms.save(settings, website, pageOptions, views, options)
82
+ Scms.savePage(settings, website, pageOptions, views, options)
83
83
  end
84
84
  end
85
- #ScmsUtils.log( out )
86
85
  end
87
86
  end
88
87
  end
89
88
 
90
89
  def Scms.getSettingsViews(settingsViews, website, pageOptions, options)
91
- views = Hash.new
90
+ views = Hash.new {}
92
91
  if settingsViews != nil
93
92
  settingsViews.each do |view|
94
93
  viewname = view[0]
94
+
95
95
  viewparts = view[1].split("?") # This allows views to have a query string in the config
96
96
  viewpath = viewparts[0]
97
97
  viewqs = viewparts[1]
98
+ viewData = Hash[viewqs.split('&').map{ |q| q.split('=') }] if viewqs != nil
98
99
 
99
- viewModel = Hash.new
100
- viewModel = Hash[viewqs.split('&').map{ |q| q.split('=') }] if viewqs != nil
101
- views[viewname] = Scms.parseView(viewname, viewpath, website, pageOptions, options, viewModel)
100
+ viewmodel = Scms.getViewModel(viewname, viewpath, website, pageOptions, options, viewData)
101
+ views[viewname] = Scms.renderView(viewpath, viewmodel)
102
102
  end
103
103
  end
104
104
  return views
105
105
  end
106
106
 
107
- def Scms.parseFolderPages(website, settings, options)
107
+ def Scms.generateFolderPages(website, settings, options)
108
108
  pagesFolder = File.join(website, "_pages")
109
109
  Dir.glob("#{pagesFolder}/**/*/").each do |pageFolder|
110
110
  pagename = File.basename(pageFolder, ".*")
111
- #puts "pagename: #{pagename}"
112
-
113
111
  pageconfig = nil
114
112
  pageconfig = Scms.getSettings(pageFolder) if File.exists?(File.join(pageFolder, "_config.yml"))
115
113
  pageOptions = PageOptions.new(pagename, website, pageconfig, settings)
116
- views = Hash.new
114
+ views = Hash.new {}
117
115
  if pageconfig != nil
118
116
  views = Scms.getSettingsViews(pageconfig["views"], website, pageOptions, options) if pageconfig["views"] != nil
119
117
  end
@@ -121,172 +119,89 @@ module Scms
121
119
  Dir.glob(File.join(pageFolder, "*")).reject { |f| f =~ /\.yml$/ || File.directory?(f) }.each do |view|
122
120
  viewname = File.basename(view, ".*")
123
121
  viewpath = Pathname.new(view).relative_path_from(Pathname.new(website)).to_s
124
- views[viewname] = Scms.parseView(viewname, viewpath, website, pageOptions, options)
122
+ viewmodel = Scms.getViewModel(viewname, viewpath, website, pageOptions, options)
123
+ views[viewname] = Scms.renderView(viewpath, viewmodel)
125
124
  end
126
- Scms.save(settings, website, pageOptions, views, options)
125
+ Scms.savePage(settings, website, pageOptions, views, options)
127
126
  end
128
127
  end
129
128
 
130
- def Scms.parseView(viewname, viewpath, website, pageOptions, options, viewModel = nil)
129
+ def Scms.getViewModel(viewname, viewpath, website, pageOptions, options, viewData = nil)
131
130
  #puts "parsing view: #{viewname}"
132
131
 
133
- viewhtml = ""
132
+ viewmodel = Hash.new {}
134
133
  viewfullpath = File.join(website, viewpath)
135
134
 
136
135
  if File.exists?(viewfullpath)
137
- begin
138
- htmlsnipet = File.read(viewfullpath)
139
- rescue Exception=>e
140
- ScmsUtils.errLog(e.message)
141
- ScmsUtils.log(e.backtrace.inspect)
142
- end
143
-
144
- if htmlsnipet.empty?
145
- ScmsUtils.log("Empty view: #{viewpath}")
146
- end
147
-
148
- hasHandler = false
149
- if pageOptions.handler != nil
150
- handlerpath = File.join(website, pageOptions.handler)
151
- if File.exists?(handlerpath)
152
- ScmsUtils.log( "Handler found: #{pageOptions.handler}" )
153
- hasHandler = true
154
- begin
155
- require handlerpath
156
- # #hasHandler = ScmsHandler.instance_methods(false).include? :render
157
- # hasHandler = ScmsHandler.method_defined?(:render)
158
- # puts "has render method: #{hasHandler}"
159
- # if !hasHandler
160
- # ScmsUtils.errLog( "Handler doesnt have a render method" )
161
- # end
162
- rescue Exception => e
163
- ScmsUtils.errLog( "Problem running: ScmsHandler: #{e.message}" )
164
- end
165
- else
166
- ScmsUtils.errLog("Handler not found: #{pageOptions.handler}")
167
- ScmsUtils.writelog("::Handler not found #{pageOptions.handler}", website)
168
- ScmsUtils.writelog("type NUL > #{handlerpath}", website)
169
- end
170
- end
171
-
172
- if hasHandler
173
- ScmsUtils.log("Rendering with handler")
174
- begin
175
- viewSnippet = ScmsHandler.render(viewpath)
176
- rescue Exception=>e
177
- ScmsUtils.errLog(e.message)
178
- ScmsUtils.log(e.backtrace.inspect)
179
- end
180
- else
181
- case File.extname(viewpath)
182
- when ".xml"
183
- viewSnippet = ScmsXmlHandler.transform(htmlsnipet)
184
- when ".md"
185
- begin
186
- htmlsnipet = htmlsnipet.encode('UTF-8', :invalid => :replace, :undef => :replace)
187
- doc = Maruku.new(htmlsnipet)
188
- viewSnippet = doc.to_html
189
- rescue Exception => e
190
- viewSnippet = htmlsnipet
191
- ScmsUtils.errLog(e.message)
192
- ScmsUtils.log(e.backtrace.inspect)
193
- end
194
- else
195
- viewSnippet = htmlsnipet
196
- end
197
- end
198
-
199
- viewmodel = Hash.new
200
136
  viewmodel = {
201
137
  :name => pageOptions.name,
202
138
  :title => pageOptions.title,
203
139
  :url => pageOptions.url,
204
140
  :resource => pageOptions.resource,
205
- :rootdir => website,
141
+ :rootdir => website,
142
+ :mode => options[:mode],
143
+ :allowEdit => pageOptions.allowEdit,
206
144
  :view => {
207
145
  :name => viewname,
208
- :path => viewfullpath,
209
- :model => viewModel
146
+ :path => viewpath,
147
+ :data => viewData
210
148
  }
211
149
  }
212
-
213
- if options[:mode] == "cms"
214
- viewhtml = "<div class='cms' data-view='#{viewpath}' data-page='#{pageOptions.url}'>#{Scms.render(viewSnippet, viewmodel)}</div>"
215
- else
216
- viewhtml = Scms.render(viewSnippet, viewmodel)
217
- end
218
150
  else
219
151
  ScmsUtils.errLog("View not found: #{viewname} [#{viewpath}]")
220
152
  ScmsUtils.writelog("::View not found: #{viewname} [#{viewpath}]", website)
221
153
  ScmsUtils.writelog("type NUL > #{viewpath}", website)
222
154
  end
223
155
 
224
- return viewhtml
225
- end
226
-
227
- def Scms.parsetemplate(template, hash = Hash.new)
228
- return Scms.render(template, hash)
156
+ return viewmodel
229
157
  end
230
158
 
231
- def Scms.render(template, hash = Hash.new)
232
- result = ""
233
- if template != nil
234
- begin
235
- if hash.class == OpenStruct
236
- page = hash
237
- else
238
- page = OpenStruct.new(hash)
239
- end
159
+ def Scms.renderView(viewpath, hash = Hash.new)
160
+ #puts "** Rendering: #{viewpath} **"
240
161
 
241
- erb = ERB.new(template)
242
- result = erb.result(page.instance_eval { binding })
243
- rescue StandardError => e
244
- puts "page: #{page}"
245
- ScmsUtils.errLog("Critical Error: Could not parse template")
246
- ScmsUtils.errLog(e.message)
247
-
248
- result = "<code style='border: 1px solid #666; background-color: light-yellow;'><pre>"
249
- result += e.message
250
- result += "\n\n"
251
- result += e.inspect
252
- result += "\n\n"
253
- result += "Invalid Keys in Template\n\n"
254
- result += "Valid Keys are:\n"
255
- hash.each do |key, value|
256
- result += "- page.#{key}\n"
257
- puts "nil value foy key: #{key}" if value == nil
258
- singleton_class.send(:define_method, key) { value }
259
- end
260
- result += "</code></pre>"
261
-
262
-
263
- result += "\n\n"
264
- result += template
162
+ htmlsnipet = ""
163
+ begin
164
+ htmlsnipet = File.read(viewpath)
165
+ rescue Exception=>e
166
+ ScmsUtils.errLog(e.message)
167
+ ScmsUtils.log(e.backtrace.inspect)
168
+ end
169
+ ScmsUtils.log("Empty view: #{viewpath}") if htmlsnipet.empty?
170
+
171
+ template = ""
172
+
173
+ case File.extname(viewpath)
174
+ when ".xml"
175
+ template = ScmsXmlHandler.transform(htmlsnipet)
176
+ when ".md"
177
+ begin
178
+ htmlsnipet = htmlsnipet.encode('UTF-8', :invalid => :replace, :undef => :replace)
179
+ doc = Maruku.new(htmlsnipet)
180
+ template = doc.to_html
265
181
  rescue Exception => e
266
- puts "Problem with template - check property exists"
182
+ template = htmlsnipet
183
+ ScmsUtils.errLog(e.message)
184
+ ScmsUtils.log(e.backtrace.inspect)
267
185
  end
268
186
  else
269
- ScmsUtils.log("Error: Can not parse template. Template is empty")
187
+ template = htmlsnipet
270
188
  end
271
-
272
- return result
189
+
190
+ parser = ScmsParser.new(template, hash)
191
+ return parser.parse(viewpath)
273
192
  end
274
193
 
275
- def Scms.save(settings, website, pageOptions, views, options)
194
+ def Scms.savePage(settings, website, pageOptions, views, options)
276
195
  fileName = File.join(website, File.join(pageOptions.url.sub('~/','')))
277
196
  erb = File.join(website, pageOptions.template)
278
197
  #ScmsUtils.log("Generating: #{fileName} with #{pageOptions.template}")
279
198
 
280
199
  if File.exists?(erb)
281
- # Build bundle model
282
- bundleModel = Scms.bundleModel(website, settings, options)
283
- # Build navigation model
284
- navModel = Scms.navModel(website, settings, options)
285
- #puts "navModel: #{navModel}"
200
+ bundleModel = Scms.getBundleModel(website, settings, options)# Build bundle model
201
+ navModel = Scms.getNavModel(website, settings, options)# Build navigation model
286
202
 
287
203
  websiteroot = '/'
288
204
  websiteroot = settings["rooturl"] if settings["rooturl"] != nil
289
- #puts "On save mode: #{options[:mode]}"
290
205
  websiteroot = ScmsUtils.uriEncode("file:///#{website}/") if options[:mode] == "cms"
291
206
 
292
207
  monkeyhook = "";
@@ -297,7 +212,7 @@ module Scms
297
212
  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
213
  end
299
214
 
300
- pagemodel = Hash.new
215
+ pagemodel = Hash.new {}
301
216
  pagemodel = {
302
217
  :name => pageOptions.name,
303
218
  :title => pageOptions.title,
@@ -313,17 +228,13 @@ module Scms
313
228
  :livereload => livereload
314
229
  }
315
230
 
316
- #puts "pagemodel:"
317
- #puts pagemodel
318
-
319
231
  pubsubdir = File.dirname(fileName)
320
232
  Dir.mkdir(pubsubdir, 755) unless File::directory?(pubsubdir)
321
233
 
322
234
  erbtemplate = File.read(erb)
323
235
 
324
- #puts "pagemodel: #{pagemodel}"
325
- #html = ""
326
- html = Scms.render(erbtemplate, pagemodel)
236
+ parser = ScmsParser.new(erbtemplate, pagemodel)
237
+ html = parser.parse()
327
238
  html = html.gsub('~/', websiteroot)
328
239
  begin
329
240
  File.open(fileName, 'w') {|f| f.write(html) }
@@ -339,7 +250,7 @@ module Scms
339
250
  end
340
251
  end
341
252
 
342
- def Scms.navModel(website, settings, options)
253
+ def Scms.getNavModel(website, settings, options)
343
254
  websiteroot = '/'
344
255
  websiteroot = settings["rooturl"] unless settings["rooturl"] == nil
345
256
  websiteroot = ScmsUtils.uriEncode("file:///#{website}/") if options[:mode] == "cms"
@@ -392,8 +303,8 @@ module Scms
392
303
  return navModel
393
304
  end
394
305
 
395
- def Scms.bundleModel(website, settings, options)
396
- bundleModel = Hash.new
306
+ def Scms.getBundleModel(website, settings, options)
307
+ bundleModel = Hash.new {}
397
308
  bundleConfig = settings["bundles"]
398
309
  if bundleConfig != nil
399
310
  bundleConfig.each do |bundle|
@@ -3,7 +3,7 @@ module Scms
3
3
  require 'scms/scms-utils.rb'
4
4
 
5
5
  class PageOptions
6
- attr_accessor :name, :template, :url, :title, :keywords, :description, :resource, :handler
6
+ attr_accessor :name, :template, :url, :title, :keywords, :description, :resource, :handler, :allowEdit
7
7
 
8
8
  def name= name
9
9
  @name = name
@@ -37,6 +37,10 @@ module Scms
37
37
  @handler = handler
38
38
  end
39
39
 
40
+ def allowEdit= allowEdit
41
+ @allowEdit = allowEdit
42
+ end
43
+
40
44
  def initialize (name, website, pageconfig, siteConfig)
41
45
  @name = name
42
46
  @template = siteConfig["template"]
@@ -46,6 +50,7 @@ module Scms
46
50
  @description = ""
47
51
  @resource = Hash.new
48
52
  @handler = nil
53
+ @allowEdit = true
49
54
 
50
55
  if pageconfig != nil
51
56
  @template = pageconfig["template"] unless pageconfig["template"] == nil
@@ -59,6 +64,7 @@ module Scms
59
64
  @description = pageconfig["description"] if pageconfig["description"] != nil
60
65
  @handler = pageconfig["handler"]
61
66
  @resource = getResource(website, pageconfig["resource"])
67
+ @allowEdit = pageconfig["allowEdit"] if pageconfig["allowEdit"] != nil
62
68
  end
63
69
  end
64
70
 
@@ -0,0 +1,76 @@
1
+ module Scms
2
+ require 'scms/scms-utils.rb'
3
+
4
+ require 'erb'
5
+ require 'ostruct'
6
+
7
+ class ScmsParser
8
+ attr_accessor :template, :model
9
+
10
+ def template= template
11
+ @template = template
12
+ end
13
+
14
+ def model= model
15
+ @model = model
16
+ end
17
+
18
+ def initialize (template, model = Hash.new)
19
+ @template = template
20
+
21
+ if model.class == OpenStruct
22
+ @model = model
23
+ else
24
+ @model = OpenStruct.new(model.clone)
25
+ end
26
+ end
27
+
28
+ def parse(viewpath = nil)
29
+ result = ""
30
+ if @template != nil
31
+ begin
32
+ page = @model
33
+ erb = ERB.new(@template)
34
+ result = erb.result(page.instance_eval { binding })
35
+
36
+ # only do cms click edit on sub views not layout templates
37
+ if page.view != nil
38
+ if page.mode == "cms"
39
+ if viewpath != nil
40
+ result = "<div class='cms' data-view='#{viewpath}' data-page='#{page.url}'>#{result}</div>" if page.allowEdit
41
+ end
42
+ end
43
+ end
44
+
45
+ rescue StandardError => e
46
+ #puts "page: #{page}"
47
+ ScmsUtils.errLog("Critical Error: Could not parse template")
48
+ #ScmsUtils.errLog(e.message)
49
+
50
+ result = "<code style='border: 1px solid #666; background-color: light-yellow;'><pre>"
51
+ result += e.message
52
+ result += "\n\n"
53
+ result += e.inspect
54
+ result += "\n\n"
55
+ result += "Invalid Keys in Template\n\n"
56
+ result += "Valid Keys are:\n"
57
+ @model.each do |key, value|
58
+ result += "- page.#{key}\n"
59
+ puts "nil value foy key: #{key}" if value == nil
60
+ singleton_class.send(:define_method, key) { value }
61
+ end
62
+ result += "</code></pre>"
63
+
64
+ result += "\n\n"
65
+ result += template
66
+ rescue Exception => e
67
+ puts "Problem with template - check property exists"
68
+ end
69
+ else
70
+ ScmsUtils.log("Error: Can not parse template. Template is empty")
71
+ end
72
+
73
+ return result
74
+ end
75
+ end
76
+ end
data/lib/scms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Scms
2
- VERSION = "4.0.3"
2
+ VERSION = "4.1.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: 4.0.3
4
+ version: 4.1.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-25 00:00:00.000000000 Z
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cprobert-s3sync
@@ -192,6 +192,7 @@ files:
192
192
  - lib/scms/scms-helpers.rb
193
193
  - lib/scms/scms-httpserver.rb
194
194
  - lib/scms/scms-pageoptions.rb
195
+ - lib/scms/scms-parser.rb
195
196
  - lib/scms/scms-utils.rb
196
197
  - lib/scms/scms-watcher.rb
197
198
  - lib/scms/scms-xmlhandler.rb