scms 1.7.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +0 -0
  3. data/assets/blank-app-template/application.xml +57 -0
  4. data/assets/blank-app-template/cert.p12 +0 -0
  5. data/assets/blank-app-template/config.yml +32 -0
  6. data/assets/blank-app-template/debug.cmd +6 -0
  7. data/assets/blank-app-template/package.cmd +16 -0
  8. data/assets/blank-app-template/public/ico/favicon.ico +0 -0
  9. data/assets/blank-app-template/public/ico/logo-128.png +0 -0
  10. data/assets/blank-app-template/public/ico/logo-16.png +0 -0
  11. data/assets/blank-app-template/public/ico/logo-32.png +0 -0
  12. data/assets/blank-app-template/public/ico/logo-48.png +0 -0
  13. data/assets/blank-app-template/public/images/glyphicons-halflings-white.png +0 -0
  14. data/assets/blank-app-template/public/images/glyphicons-halflings.png +0 -0
  15. data/assets/blank-app-template/public/robots.txt +4 -0
  16. data/assets/blank-app-template/public/scripts/air/AIRAliases.js +240 -0
  17. data/assets/blank-app-template/public/scripts/air/AIRIntrospector.js +1949 -0
  18. data/assets/blank-app-template/public/scripts/air/AIRMenuBuilder.js +1322 -0
  19. data/assets/blank-app-template/public/scripts/air/applicationupdater.swf +0 -0
  20. data/assets/blank-app-template/public/scripts/air/applicationupdater_ui.swf +0 -0
  21. data/assets/blank-app-template/public/scripts/air/servicemonitor.swf +0 -0
  22. data/assets/blank-app-template/public/scripts/libs/bootstrap.js +2027 -0
  23. data/assets/blank-app-template/public/scripts/libs/jquery-1.8.2.min.js +2 -0
  24. data/assets/blank-app-template/public/scripts/libs/jquery.fn.custom.js +67 -0
  25. data/assets/blank-app-template/public/scripts/libs/knockout-2.1.0-min.js +86 -0
  26. data/assets/blank-app-template/public/scripts/presenters/dashboard-presenter.js +3 -0
  27. data/assets/blank-app-template/public/scripts/presenters/global-presenter.js +8 -0
  28. data/assets/blank-app-template/public/scripts/shared/data-persistance.js +22 -0
  29. data/assets/blank-app-template/public/scripts/shared/utils.js +107 -0
  30. data/assets/blank-app-template/public/stylesheets/bootstrap-responsive.css +1058 -0
  31. data/assets/blank-app-template/public/stylesheets/bootstrap.css +5774 -0
  32. data/assets/blank-app-template/public/stylesheets/style.css +0 -0
  33. data/assets/blank-app-template/s3config.template.yml +9 -0
  34. data/assets/blank-app-template/templates/menu.xml +5 -0
  35. data/assets/blank-app-template/templates/skin.erb.html +84 -0
  36. data/assets/blank-app-template/tools/msxsl.exe +0 -0
  37. data/assets/blank-app-template/tools/update-descriptor.xsl +18 -0
  38. data/assets/blank-app-template/tools/version.xsl +10 -0
  39. data/assets/blank-app-template/views/about.html +15 -0
  40. data/assets/blank-app-template/views/dashboard.html +7 -0
  41. data/assets/blank-template/config.yml +30 -0
  42. data/assets/blank-template/public/images/glyphicons-halflings-white.png +0 -0
  43. data/assets/blank-template/public/images/glyphicons-halflings.png +0 -0
  44. data/assets/blank-template/public/robots.txt +4 -0
  45. data/assets/blank-template/public/scripts/air-monkey-hook.js +63 -0
  46. data/assets/blank-template/public/scripts/bootstrap.js +2027 -0
  47. data/assets/blank-template/public/scripts/jquery-1.8.2.min.js +2 -0
  48. data/assets/blank-template/public/scripts/script.js +0 -0
  49. data/assets/blank-template/public/stylesheets/bootstrap-responsive.css +1058 -0
  50. data/assets/blank-template/public/stylesheets/bootstrap.css +5774 -0
  51. data/assets/blank-template/public/stylesheets/style.css +0 -0
  52. data/assets/blank-template/s3config.template.yml +10 -0
  53. data/assets/blank-template/templates/menu.xml +5 -0
  54. data/assets/blank-template/templates/skin.erb.html +108 -0
  55. data/assets/blank-template/views/about-intro.html +1 -0
  56. data/assets/blank-template/views/about-main.html +2 -0
  57. data/assets/blank-template/views/home-intro.html +3 -0
  58. data/assets/blank-template/views/home-main.html +15 -0
  59. data/assets/mime.types +68 -0
  60. data/bin/scms +127 -0
  61. data/lib/scms.rb +426 -0
  62. data/lib/scms/s3deploy.rb +45 -0
  63. data/lib/scms/scms_utils.rb +73 -0
  64. data/lib/scms/version.rb +3 -0
  65. data/scms.gemspec +24 -0
  66. data/scripts/build.bat +4 -0
  67. data/staticcms.sublime-project +8 -0
  68. data/staticcms.sublime-workspace +417 -0
  69. metadata +180 -0
@@ -0,0 +1,10 @@
1
+ bucket: yours3.bucket
2
+ AWS_ACCESS_KEY_ID: yourkeyhjere
3
+ AWS_SECRET_ACCESS_KEY: yoursecretpassword
4
+
5
+ cache:
6
+ - scripts
7
+ - stylesheets
8
+ - images
9
+
10
+ #uri: http://www.yourwebsite.com
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1"?>
2
+ <menu>
3
+ <page href="index.html">Home</page>
4
+ <page href="about.html">About</page>
5
+ </menu>
@@ -0,0 +1,108 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Static-CMS</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="description" content="">
8
+ <meta name="author" content="">
9
+
10
+ <script src='scripts/jquery-1.8.2.min.js'></script>
11
+ <!-- Le styles -->
12
+ <link href='<%= data.stylesheets["style"] %>' rel="stylesheet">
13
+ <style type="text/css">
14
+ body {
15
+ padding-top: 60px;
16
+ padding-bottom: 40px;
17
+ }
18
+ </style>
19
+
20
+ <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
21
+ <!--[if lt IE 9]>
22
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
23
+ <![endif]-->
24
+ </head>
25
+
26
+ <body>
27
+
28
+ <div class="navbar navbar navbar-fixed-top">
29
+ <div class="navbar-inner">
30
+ <div class="container">
31
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
32
+ <span class="icon-bar"></span>
33
+ <span class="icon-bar"></span>
34
+ <span class="icon-bar"></span>
35
+ </a>
36
+ <a class="brand" href="index.html">Project name</a>
37
+ <div class="nav-collapse collapse">
38
+ <ul class="nav">
39
+
40
+ <%
41
+ @page = data.page
42
+ @page = "/" if @page == "index.html"
43
+ def isActive(href)
44
+ if @page == href
45
+ return "active"
46
+ end
47
+ end
48
+
49
+ require 'nokogiri'
50
+ xml_doc = Nokogiri::XML(File.read(File.join(data.sitedir, "templates", "menu.xml")))
51
+ xml_doc.xpath('/menu/page').each do |link|
52
+ %>
53
+ <li><a href='<%= link.attr("href") %>' class='<%=isActive(link.attr("href"))%> <%= link.attr("class") %>'>
54
+ <%= link.content %>
55
+ </a></li>
56
+ <% end %>
57
+
58
+ <li class="dropdown">
59
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
60
+ <ul class="dropdown-menu">
61
+ <li><a href="#">Action</a></li>
62
+ <li><a href="#">Another action</a></li>
63
+ <li><a href="#">Something else here</a></li>
64
+ <li class="divider"></li>
65
+ <li class="nav-header">Nav header</li>
66
+ <li><a href="#">Separated link</a></li>
67
+ <li><a href="#">One more separated link</a></li>
68
+ </ul>
69
+ </li>
70
+ </ul>
71
+ <form class="navbar-form pull-right">
72
+ <input class="span2" type="text" placeholder="Email">
73
+ <input class="span2" type="password" placeholder="Password">
74
+ <button type="submit" class="btn">Sign in</button>
75
+ </form>
76
+ </div><!--/.nav-collapse -->
77
+ </div>
78
+ </div>
79
+ </div>
80
+
81
+ <div class="container">
82
+
83
+ <!-- Main hero unit for a primary marketing message or call to action -->
84
+ <div class="hero-unit">
85
+ <%= data.views["intro"] %>
86
+ </div>
87
+
88
+ <!-- Example row of columns -->
89
+ <div class="row">
90
+ <%= data.views["main"] %>
91
+ </div>
92
+
93
+ <hr>
94
+
95
+ <footer>
96
+ <p>&copy; Company <%= Time.now.strftime("%Y") %></p>
97
+ </footer>
98
+
99
+ </div> <!-- /container -->
100
+
101
+ <!-- Le javascript
102
+ ================================================== -->
103
+ <!-- Placed at the end of the document so the pages load faster -->
104
+ <script src='<%= data.scripts["script"] %>'></script>
105
+
106
+ <%= data.monkeyhook %>
107
+ </body>
108
+ </html>
@@ -0,0 +1 @@
1
+ <a href="index.html">goto home page</a></p>
@@ -0,0 +1,2 @@
1
+ <h1>Second Page</h1>
2
+ <p>Add your text here</p>
@@ -0,0 +1,3 @@
1
+ <h1>Hello, world!</h1>
2
+ <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
3
+ <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
@@ -0,0 +1,15 @@
1
+ <div class="span4">
2
+ <h2>Heading</h2>
3
+ <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
4
+ <p><a class="btn" href="#">View details &raquo;</a></p>
5
+ </div>
6
+ <div class="span4">
7
+ <h2>Heading</h2>
8
+ <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
9
+ <p><a class="btn" href="#">View details &raquo;</a></p>
10
+ </div>
11
+ <div class="span4">
12
+ <h2>Heading</h2>
13
+ <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
14
+ <p><a class="btn" href="#">View details &raquo;</a></p>
15
+ </div>
data/assets/mime.types ADDED
@@ -0,0 +1,68 @@
1
+ text/plain txt
2
+ text/html htm html shtml
3
+ text/javascript js
4
+ text/css css
5
+ text/xml xml
6
+
7
+ image/gif gif
8
+ image/jpeg jpeg jpe jpg
9
+ image/tiff tiff tif
10
+ image/png png
11
+ image/vnd.wap.wbmp wbmp
12
+ image/x-icon ico
13
+ image/x-jng jng
14
+ image/x-ms-bmp bmp
15
+ image/svg+xml svg svgz
16
+ image/webp webp
17
+
18
+ font/otf otf
19
+ application/x-font-woff woff
20
+
21
+ video/mpeg mpeg mpg
22
+ video/webm webm
23
+ audio/aac aac
24
+ video/mp4 mp4
25
+ video/ogg ogv
26
+ video/3gpp 3gpp 3gp
27
+ video/quicktime mov
28
+ video/x-flv flv
29
+ video/x-m4v m4v
30
+ video/x-mng mng
31
+ video/x-ms-asf asx asf
32
+ video/x-ms-wmv wmv
33
+ video/x-msvideo avi
34
+
35
+ audio/mpeg mp3
36
+ audio/ogg oga ogg
37
+ audio/wav wav
38
+ audio/midi mid midi kar
39
+ audio/x-m4a m4a
40
+ audio/x-realaudio ra
41
+
42
+ application/x-xpinstall xpi
43
+ application/xhtml+xml xhtml
44
+ application/x-shockwave-flash swf
45
+ application/atom+xml atom
46
+ application/rss+xml rss
47
+ application/rtf rtf
48
+ application/postscript ps eps ai
49
+ application/pdf pdf
50
+ application/zip zip
51
+ application/x-tar tar
52
+ application/x-7z-compressed 7z
53
+ application/x-rar-compressed rar
54
+ application/x-stuffit sit
55
+ application/octet-stream dmg
56
+ application/octet-stream eot
57
+ application/octet-stream iso img
58
+ application/octet-stream msi msp msm
59
+ application/msword doc dot
60
+ application/vnd.ms-excel xls xlt xla
61
+ application/vnd.ms-powerpoint ppt pot pps ppa
62
+
63
+ application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
64
+ application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
65
+ application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
66
+ application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
67
+ application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
68
+
data/bin/scms ADDED
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env ruby
2
+ # This software code is made available "AS IS" without warranties of any
3
+ # kind. You may copy, display, modify and redistribute the software
4
+ # code either by itself or as incorporated into your code; provided that
5
+ # you do not remove any proprietary notices. Your use of this software
6
+ # code is at your own risk and you waive any claim against the author
7
+ # with respect to your use of this software code.
8
+ # (c) 2007 Static-CMS
9
+
10
+ require 'optparse'
11
+ require 'fileutils'
12
+ require 'scms'
13
+
14
+ options = {}
15
+ optparse = OptionParser.new do|opts|
16
+ # Set a banner, displayed at the top
17
+ # of the help screen.
18
+ opts.banner = "Usage: static-cms.rb [options]"
19
+
20
+ # Define the options, and what they do
21
+ opts.on('-w', '--website WEBSITE', "Website directory (full path)") do |w|
22
+ options[:website] = w
23
+ end
24
+
25
+ opts.on('-o', '--output BuildDIR', "Website build dir (full path)") do |o|
26
+ options[:pub] = o
27
+ end
28
+
29
+ options[:action] = "build"
30
+ opts.on( '-a', '--action ACTION', 'Build, Deploy, Create or Clean' ) do|a|
31
+ options[:action] = a
32
+ end
33
+
34
+ options[:mode] = "pub"
35
+ opts.on( '-m', '--mode MODE', 'CMS or Publish' ) do|m|
36
+ options[:mode] = m
37
+ end
38
+
39
+ options[:html] = "true"
40
+ opts.on( '-f', '--html HTML', 'true or false' ) do|h|
41
+ options[:html] = h
42
+ end
43
+
44
+ options[:verbose] = false
45
+ opts.on( '-v', '--verbose', 'Output more information' ) do
46
+ options[:verbose] = true
47
+ end
48
+ # This displays the help screen, all programs are
49
+ # assumed to have this option.
50
+ opts.on( '-h', '--help', 'Display this screen' ) do
51
+ puts opts
52
+ exit
53
+ end
54
+ end
55
+ optparse.parse!
56
+ #Now raise an exception if we have not found a website option
57
+ if options[:website].nil?
58
+ puts "Please specify a website directory, e.g."
59
+ puts "staticcms -w ~/websites/mystaticwebsite"
60
+ raise OptionParser::MissingArgument
61
+ end
62
+
63
+ $stdout.sync = true
64
+ root_folder = File.expand_path("../", File.dirname(__FILE__))
65
+ @pub = File.join("#{options[:website]}/compiled")
66
+ unless options[:pub].nil?
67
+ @pub = options[:pub]
68
+ end
69
+
70
+ Folders = {
71
+ :root => root_folder,
72
+ :website => File.join(options[:website]),
73
+ :pub => (ENV["SCMS_PUBLISH_FOLDER"] or @pub),
74
+ :assets => (ENV["SCMS_STATICCMS_FOLDER"] or File.join(root_folder, "assets")),
75
+ :config => (ENV["SCMS_CONFIG_FOLDER"] or File.join(options[:website]))
76
+ }
77
+
78
+ if options[:action] == "create"
79
+ if Dir.exists? Folders[:website]
80
+ throw "Website already exists!!!"
81
+ else
82
+ puts "Making website: #{Folders[:website]}"
83
+ FileUtils.mkdir_p Folders[:website]
84
+ Dir.chdir(File.join(Folders[:assets], "blank-template")) do
85
+ files = Dir.glob('*')
86
+ FileUtils.cp_r files, Folders[:website]
87
+ end
88
+ end
89
+ exit
90
+ end
91
+
92
+ if options[:action] == "createapp"
93
+ if Dir.exists? Folders[:website]
94
+ throw "App already exists!!!"
95
+ else
96
+ puts "Making Air app: #{Folders[:website]}"
97
+ FileUtils.mkdir_p Folders[:website]
98
+ Dir.chdir(File.join(Folders[:assets], "blank-app-template")) do
99
+ files = Dir.glob('*')
100
+ FileUtils.cp_r files, Folders[:website]
101
+ end
102
+ end
103
+ exit
104
+ end
105
+
106
+ raise "No website in folder #{Folders[:website]}" if !File::directory?(Folders[:website])
107
+
108
+ #puts "System root folder = #{Folders[:root]}"
109
+ #puts "Website folder = #{Folders[:website]}"
110
+ #puts "Pub dir = #{Folders[:pub]}"
111
+ #puts "Config dir = #{Folders[:config]}"
112
+ #puts "Mode = #{options[:mode]}"
113
+
114
+ ##Set globals
115
+ $website = Folders[:website]
116
+ $html = (ENV["SCMS_HTML_OUT"] or "false")
117
+
118
+ deployDir = StaticCMS.build(Folders[:pub], Folders[:config], options[:mode])
119
+
120
+ if options[:action] == "crunch"
121
+ StaticCMS.crunch(deployDir)
122
+ end
123
+ #puts "deployDir = #{deployDir}"
124
+ if options[:action] == "deploy"
125
+ StaticCMS.crunch(deployDir)
126
+ StaticCMS.deploy(deployDir, Folders[:config])
127
+ end
data/lib/scms.rb ADDED
@@ -0,0 +1,426 @@
1
+ module StaticCMS
2
+ VERSION = '1.1.0'
3
+ require 'scms/scms_utils.rb'
4
+ require 'scms/s3deploy.rb'
5
+
6
+ require 'erb'
7
+ require 'ostruct'
8
+ require 'yaml'
9
+ require 'sass'
10
+ require 'packr'
11
+
12
+ include YAML
13
+
14
+ def StaticCMS.build(pub, config, mode)
15
+ @pub = pub
16
+ @cleanpub = true
17
+ @configdir = config
18
+ @mode = mode
19
+ @webroot = "public"
20
+
21
+ ScmsUtils.log("_Mode: #{mode}_")
22
+
23
+ yamlpath=File.join(@configdir, "config.yml")
24
+ ScmsUtils.log("**[Getting Config](#{ScmsUtils.uriEncode("file:///#{yamlpath}")})**")
25
+ $settings = StaticCMS.getsettings(yamlpath)
26
+ if $settings
27
+ if $settings["options"] != nil
28
+ if ENV["SCMS_PUBLISH_FOLDER"] == nil && $settings["options"]["build_dir"] != nil
29
+ ScmsUtils.log("_Setting pub dir from config.yml_")
30
+ @pub = $settings["options"]["build_dir"]
31
+ end
32
+ if $settings["options"]["clean_build_dir"] == false
33
+ @cleanpub = false
34
+ end
35
+ end
36
+
37
+ if @cleanpub
38
+ StaticCMS.cleanpubdir(@pub)
39
+ @cleanpub = false
40
+ else
41
+ ScmsUtils.log("Skipping cleaning \n#{@pub}")
42
+ end
43
+
44
+ #Bootstrap here
45
+ if $settings["bootstrap"] != nil
46
+ bootstrap = File.join($website, $settings["bootstrap"])
47
+ #ScmsUtils.log("Bootstrap is: #{$settings["bootstrap"]}")
48
+ if File.exists?(bootstrap)
49
+ begin
50
+ require_relative bootstrap
51
+ rescue Exception=>e
52
+ ScmsUtils.errLog( e )
53
+ end
54
+ else
55
+ ScmsUtils.log("_Bootstrap does not exist #{bootstrap}_")
56
+ end
57
+ end
58
+
59
+ #Bundle resources
60
+ scripts = StaticCMS.bundlescripts($settings["scripts"])
61
+ stylesheets = StaticCMS.bundlestylesheets($settings["stylesheets"])
62
+ #Generate pages
63
+ StaticCMS.parsetemplates(scripts, stylesheets)
64
+ else
65
+ ScmsUtils.errLog("Config is empty")
66
+ end
67
+
68
+ webroot = File.join($website, @webroot)
69
+ if File.exists?(webroot)
70
+ ScmsUtils.log("_Merging 'public' folder_")
71
+
72
+ if @cleanpub
73
+ StaticCMS.cleanpubdir(@pub)
74
+ end
75
+
76
+ FileUtils.mkdir @pub unless Dir.exists? @pub
77
+ Dir.chdir(webroot) do
78
+ #files = Dir.glob('*')
79
+ #FileUtils.cp_r files, @pub
80
+
81
+ Dir.glob("**/*").reject{|f| f['.svn']}.each do |oldfile|
82
+ newfile = File.join(@pub, oldfile.sub(webroot, ''))
83
+ #puts newfile
84
+ File.file?(oldfile) ? FileUtils.copy(oldfile, newfile) : FileUtils.mkdir(newfile) unless File.exist? newfile
85
+ end
86
+ end
87
+ else
88
+ ScmsUtils.log("**No 'public' folder in #{$webroot} - skiping merge**")
89
+ end
90
+
91
+ ScmsUtils.successLog("**Compiled :)**")
92
+ ScmsUtils.log("[_#{@pub}_](#{ScmsUtils.uriEncode("file:///#{@pub}")})")
93
+
94
+ return @pub
95
+ end
96
+
97
+ def StaticCMS.parsetemplates(scripts, stylesheets)
98
+ # build views from templates
99
+ @template = $settings["template"]
100
+ if $settings["pages"] != nil
101
+ ScmsUtils.log("**Compiling Pages:**")
102
+ $settings["pages"].each do |page|
103
+ if page != nil
104
+ page.each do |option|
105
+ #ScmsUtils.log( "option (#{option.class}) = #{option[0]}" )
106
+ pageconfig = option[1]
107
+ #ScmsUtils.log( "Pageconfig = #{pageconfig}" )
108
+
109
+ if pageconfig["template"] == nil
110
+ skin = @template
111
+ else
112
+ skin = pageconfig["template"]
113
+ end
114
+
115
+ page = pageconfig["generate"]
116
+ ScmsUtils.successLog("#{page}")
117
+
118
+ resource = Hash.new
119
+ if pageconfig["resource"] != nil
120
+ resourcepath = File.join($website, pageconfig["resource"])
121
+ if File.exists?(resourcepath)
122
+ #ScmsUtils.log( "_Resource found: #{pageconfig["resource"]}_" )
123
+ resource = YAML.load_file(resourcepath)
124
+ else
125
+ ScmsUtils.errLog( "Resource not found: #{resourcepath}" )
126
+ end
127
+ end
128
+
129
+ hasHandler = nil
130
+ if pageconfig["handler"] != nil
131
+ handlerpath = File.join($website, pageconfig["handler"])
132
+ if File.exists?(handlerpath)
133
+ #ScmsUtils.log( "Handler found: #{pageconfig["handler"]}" )
134
+ require handlerpath
135
+ funDefined = defined? Handler.render
136
+ if funDefined != nil
137
+ hasHandler = "yes"
138
+ else
139
+ ScmsUtils.errLog( "Handler doesnt have a render method" )
140
+ end
141
+ else
142
+ ScmsUtils.errLog( "**Handler not found: #{handlerpath}**" )
143
+ end
144
+ end
145
+
146
+ views = Hash.new
147
+ pageconfig["views"].each do |view|
148
+ views[view[0]] = ""
149
+ viewpath = File.join($website, view[1])
150
+ if File.exists?(viewpath)
151
+ htmlsnipet = File.read(viewpath)
152
+ if !htmlsnipet.empty?
153
+ model = Hash.new
154
+ model = { :page => page, :sitedir => $website, :resource => resource }
155
+ if hasHandler == "yes"
156
+ ScmsUtils.log("_Rendering with handler_")
157
+ viewSnippet = Handler.render(viewpath)
158
+ else
159
+ viewSnippet = File.read(viewpath)
160
+ end
161
+
162
+ if @mode == "cms"
163
+ views[view[0]] = "<div class='cms' data-view='#{view[1]}' data-page='#{page}'>#{StaticCMS.parsetemplate(viewSnippet, model)}</div>"
164
+ else
165
+ views[view[0]] = StaticCMS.parsetemplate(viewSnippet, model)
166
+ end
167
+ else
168
+ ScmsUtils.writelog(@pub, "Empty file: #{viewpath}")
169
+ end
170
+ else
171
+ ScmsUtils.errLog("View not found: #{view[0]} - #{view[1]} [#{viewpath}]")
172
+ ScmsUtils.writelog(@pub, "View not found: #{view[0]} - #{view[1]} [#{viewpath}]")
173
+ end
174
+ #ScmsUtils.log( "view = #{view[0]} - #{view[1]}" )
175
+ end
176
+
177
+ monkeyhook = "";
178
+ if @mode == "cms"
179
+ monkeyhook = "<script src='scripts/air-monkey-hook.js'></script>"
180
+ end
181
+
182
+ hash = {
183
+ :page => page,
184
+ :views => views,
185
+ :resource => resource,
186
+ :config => pageconfig,
187
+ :scripts => scripts,
188
+ :stylesheets => stylesheets,
189
+ :sitedir => $website,
190
+ :monkeyhook => monkeyhook
191
+ }
192
+
193
+ erb = File.join($website, skin)
194
+ out = File.join(@pub, pageconfig["generate"])
195
+
196
+ if File.exists?(erb)
197
+ pubsubdir = File.dirname(out)
198
+ Dir.mkdir(pubsubdir, 755) unless File::directory?(pubsubdir)
199
+ html = StaticCMS.parsetemplate(File.read(erb), hash)
200
+ File.open(out, 'w') {|f| f.write(html) }
201
+ else
202
+ ScmsUtils.errLog("Template doesn't exist: #{erb}")
203
+ end
204
+
205
+
206
+ end
207
+ end
208
+ #ScmsUtils.log( out )
209
+ end
210
+ end
211
+ end
212
+
213
+ def StaticCMS.bundlescripts(scriptsConfig)
214
+ scripts = Hash.new
215
+ if scriptsConfig != nil
216
+ ScmsUtils.log("**Bundeling Scripts:**")
217
+ scriptsConfig.each do |script|
218
+ #ScmsUtils.log( "script (#{script.class}) = #{script}" )
219
+ script.each do |option|
220
+ name = option[0]
221
+ if option[1]["version"] != nil
222
+ scriptversion = option[1]["version"]
223
+ else
224
+ scriptversion = 1
225
+ end
226
+ scriptname = "#{name}-v#{scriptversion}.js"
227
+ scriptsdir = File.join(@pub, "scripts")
228
+
229
+ puts scriptsdir
230
+ FileUtils.mkdir_p(scriptsdir) unless File::directory?(scriptsdir)
231
+ #Dir.mkdir_p(scriptsdir, 755 ) if !File::directory?(scriptsdir)
232
+ out = File.join(scriptsdir, scriptname)
233
+
234
+ ScmsUtils.successLog("#{scriptname}")
235
+ content = ""
236
+
237
+ assetList = ""
238
+ bundle = option[1]["bundle"]
239
+ bundle.each do |asset|
240
+ assetList += "\t#{asset}\n"
241
+ assetname = File.join($website, @webroot, asset)
242
+ if File::exists?(assetname)
243
+ content = content + "\n" + File.read(assetname)
244
+ else
245
+ ScmsUtils.errLog( "Error: No such file #{assetname}" )
246
+ end
247
+ end
248
+ ScmsUtils.log("#{assetList}")
249
+
250
+ scripts[name] = "scripts/#{scriptname}"
251
+ File.open(out, 'w') {|f| f.write(content) }
252
+ end
253
+ end
254
+ end
255
+ return scripts
256
+ end
257
+
258
+ def StaticCMS.bundlestylesheets(styleConfig)
259
+ stylesheets = Hash.new
260
+ if styleConfig != nil
261
+ ScmsUtils.log("**Bundeling Stylesheets:**")
262
+ styleConfig.each do |stylesheet|
263
+ #ScmsUtils.log( "stylesheet (#{stylesheet.class}) = #{stylesheet}" )
264
+ stylesheet.each do |option|
265
+ name = option[0]
266
+ if option[1]["version"] != nil
267
+ stylesheetversion = option[1]["version"]
268
+ else
269
+ stylesheetversion = 1
270
+ end
271
+ stylesheetname = "#{name}-v#{stylesheetversion}.css"
272
+
273
+ Dir.mkdir(File.join(@pub, "stylesheets"), 755 ) if ! File::directory?(File.join(@pub, "stylesheets"))
274
+ out = File.join(@pub, "stylesheets", stylesheetname)
275
+
276
+ ScmsUtils.successLog("#{stylesheetname}")
277
+ content = ""
278
+
279
+ bundle = option[1]["bundle"]
280
+ assetList = ""
281
+ bundle.each do |asset|
282
+ assetList += "\t #{asset}\n"
283
+ assetname = File.join($website, @webroot, asset)
284
+ if File::exists?(assetname)
285
+ content = content + "\n" + File.read(assetname)
286
+ else
287
+ ScmsUtils.errLog( "Error: No such file #{assetname}" )
288
+ end
289
+ end
290
+ ScmsUtils.log( "#{assetList}" )
291
+
292
+ stylesheets[name] = "stylesheets/#{stylesheetname}"
293
+ File.open(out, 'w') {|f| f.write(content) }
294
+ end
295
+ end
296
+ end
297
+ return stylesheets
298
+ end
299
+
300
+ def StaticCMS.parsetemplate(template, hash)
301
+ data = OpenStruct.new(hash)
302
+ result = ""
303
+
304
+ begin
305
+ result = ERB.new(template).result(data.instance_eval { binding })
306
+ rescue Exception => e
307
+ ScmsUtils.errLog("**Critical Error: Could not parse template**")
308
+ ScmsUtils.log( "_(if your using resources make sure their not empty)_" )
309
+ ScmsUtils.errLog( e.message )
310
+ end
311
+
312
+ return result
313
+ end
314
+
315
+ def StaticCMS.getsettings(yamlpath)
316
+ config = nil
317
+
318
+ if File.exist?(yamlpath)
319
+ tree = File.read(yamlpath)
320
+ begin
321
+ myconfig = ERB.new(tree).result()
322
+ #puts "Conf = #{myconfig}"
323
+ config = YAML.load(myconfig)
324
+ #config = YAML.load_file(yamlpath)
325
+ rescue Exception => e
326
+ ScmsUtils.errLog("Error Loading config.yml (check there are no tabs in the file)")
327
+ ScmsUtils.log( "_[Verify your config](http://yaml-online-parser.appspot.com/)_")
328
+ ScmsUtils.errLog( e.message )
329
+ ScmsUtils.errLog( e.backtrace.inspect )
330
+ end
331
+ else
332
+ ScmsUtils.errLog("Config file does not exist: #{yamlpath}")
333
+ end
334
+
335
+ return config
336
+ end
337
+
338
+ def StaticCMS.cleanpubdir(pub)
339
+ ScmsUtils.log("_Cleaning pub folder #{pub}_")
340
+ FileUtils.rm_rf pub
341
+ #FileUtils.remove_dir(pub, force = true)
342
+ sleep 0.5 # seconds
343
+ FileUtils.mkdir_p(pub) unless File.exist? pub
344
+ FileUtils.chmod 0755, pub
345
+ end
346
+
347
+ def StaticCMS.crunch(crunchDir)
348
+ ScmsUtils.log( "Starting crunching CSS and JavaScript in:\n#{crunchDir}\n\n" )
349
+
350
+ Dir.chdir(crunchDir) do
351
+ Dir.glob("**/*.{css,scss}").reject{|f| /-min/.match(f) != nil || /\.min/.match(f) != nil }.each do |asset|
352
+ StaticCMS.sass(asset)
353
+ end
354
+ Dir.glob("**/*.js").reject{|f| /-min/.match(f) != nil || /\.min/.match(f) != nil }.each do |asset|
355
+ StaticCMS.packr(asset)
356
+ end
357
+ #Dir.glob("**/*.{css, js}").each do |asset|
358
+ # #fullFileName = File.basename(asset)
359
+ # #ScmsUtils.log( "Crunching #{fullFileName}" )
360
+ # ext = File.extname(asset)
361
+ # StaticCMS.yuicompress(asset, ext)
362
+ #end
363
+ end
364
+ end
365
+
366
+ def StaticCMS.sass(asset)
367
+ if File.exists?(asset)
368
+ begin
369
+ template = File.read(asset)
370
+ sass_engine = Sass::Engine.new(template, {
371
+ :style => :compressed,
372
+ :cache => false,
373
+ :syntax => :scss
374
+ }.freeze)
375
+ output = sass_engine.to_css
376
+ File.open(asset, 'w') { |file| file.write(output) }
377
+ ScmsUtils.log( "_Sassed #{File.basename(asset)}_" )
378
+ rescue Exception => e
379
+ ScmsUtils.errLog( "Error processing: #{asset}" )
380
+ ScmsUtils.errLog( e.message )
381
+ end
382
+ end
383
+ end
384
+
385
+ def StaticCMS.packr(asset)
386
+ if File.exists?(asset)
387
+ begin
388
+ code = File.read(asset)
389
+ compressed = Packr.pack(code)
390
+ File.open(asset, 'w') { |f| f.write(compressed) }
391
+ ScmsUtils.log( "_Packed #{File.basename(asset)}_" )
392
+ rescue Exception => e
393
+ ScmsUtils.errLog( "Error processing: #{asset}" )
394
+ ScmsUtils.errLog( e.message )
395
+ end
396
+ end
397
+ end
398
+
399
+ def StaticCMS.yuicompress(asset, ext)
400
+ if File.exists?(asset)
401
+ #ScmsUtils.log( " Encoding: #{asset.encoding}" )
402
+ enc = "--charset utf-8"
403
+ enc = ""
404
+ cmd = "java"
405
+ params = "-jar \"#{File.join(Folders[:tools], "yuicompressor", "yuicompressor-2.4.7.jar")}\" #{enc} --type #{ext.gsub(".","")} \"#{asset}\" -o \"#{asset}\""
406
+ ##Need to check if asset exists
407
+ if system("#{cmd} #{params}")
408
+ ScmsUtils.log( "_Crunched #{File.basename(asset)}_" )
409
+ else
410
+ ScmsUtils.errLog( "Error crunching: #{asset}" )
411
+ end
412
+ else
413
+ ScmsUtils.errLog( "#{asset} does not exist" )
414
+ end
415
+ end
416
+
417
+ def StaticCMS.deploy(pub, config)
418
+ yamlpath=File.join(config, "s3config.yml")
419
+ if File.exists?(yamlpath)
420
+ S3Deploy.sync(pub, config)
421
+ else
422
+ raise "The following file doesn't exist #{yamlpath}"
423
+ end
424
+
425
+ end
426
+ end