milk 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -171,7 +171,9 @@ module Milk
171
171
  @resp.write page.view
172
172
  when :view
173
173
  Milk::Application.join_tree(@page, self)
174
- @resp.write @page.view
174
+ html = @page.view
175
+ @page.save_to_cache(html) if Milk::USE_CACHE
176
+ @resp.write html
175
177
  when :https_redirect
176
178
  @resp.redirect('https://' + @req.host + @req.fullpath)
177
179
  when :http_redirect
@@ -205,7 +207,6 @@ module Milk
205
207
  # method that walks an object linking Milk objects to eachother
206
208
  def self.join_tree(obj, parent)
207
209
  if [Milk::Page, Milk::Component, Milk::Application].any? {|klass| obj.kind_of? klass}
208
- puts "Setting #{obj}'s parent to #{parent}"
209
210
  obj.parent = parent
210
211
  obj.instance_variables.each do |name|
211
212
  var = obj.instance_variable_get(name)
@@ -236,7 +236,7 @@
236
236
  contentType: "application/json",
237
237
  data: jsonify($("form")[0]),
238
238
  success: function(msg){
239
- window.location = $("form")[0].action;
239
+ window.location = $("form")[0].action.replace('https://', 'http://');
240
240
  }
241
241
  });
242
242
  });
@@ -22,7 +22,7 @@ module Milk
22
22
  end
23
23
  end
24
24
 
25
- # Compile haxe binary is nonexistant/outdated
25
+ # Compile haxe binary if nonexistant/outdated
26
26
  # if a swfmill resource exists, it can outdate the main swf too
27
27
  if (not (File.file?(@haxe_swf)) \
28
28
  or (File.mtime(@haxe) > File.mtime(@haxe_swf)) \
@@ -7,15 +7,30 @@ module Milk
7
7
  attr_reader :pagename
8
8
  attr_accessor :parent
9
9
  @parent = nil
10
+
11
+ PATH_TO_NAME_REGEXP = Regexp.new("#{Milk::PAGES_DIR}\/(.*)\.yaml")
10
12
 
11
- def self.find(pagename)
12
- yaml_file = Milk::PAGES_DIR + "/" + pagename + ".yaml"
13
- raise PageNotFoundError unless File.readable? yaml_file
13
+ def self.each_page
14
+ Dir.glob(Milk::PAGES_DIR + "/**/*.yaml").each do |yaml_file|
15
+ p = load_file(yaml_file)
16
+ Milk::Application.join_tree(p, nil)
17
+ yield p
18
+ end
19
+ end
20
+
21
+ def self.load_file(yaml_file, pagename=nil)
22
+ pagename ||= PATH_TO_NAME_REGEXP.match(yaml_file)[1]
14
23
  page = YAML.load_file(yaml_file)
15
24
  page.instance_variable_set('@pagename', pagename)
16
25
  page.load_settings
17
26
  page
18
27
  end
28
+
29
+ def self.find(pagename)
30
+ yaml_file = Milk::PAGES_DIR + "/" + pagename + ".yaml"
31
+ raise PageNotFoundError unless File.readable? yaml_file
32
+ load_file(yaml_file, pagename)
33
+ end
19
34
 
20
35
  def self.haml(filename, context, extras)
21
36
  if block_given?
@@ -85,7 +100,6 @@ module Milk
85
100
  def preview
86
101
  haml(Milk::COMPONENTS_DIR + "/page.haml", self) do
87
102
  (@components.collect do |component|
88
- print "component #{component}\n"
89
103
  component.view
90
104
  end).join("")
91
105
  end
@@ -113,7 +127,6 @@ module Milk
113
127
  html ||= view
114
128
  folder = Milk::PUBLIC_DIR + "/cache/" + @pagename
115
129
  cache_file = folder + "/index.html"
116
-
117
130
  # Make the folder if it doesn't exist
118
131
  FileUtils.mkdir_p folder
119
132
  open(cache_file, "w") { |file| file.write html }
@@ -5,43 +5,6 @@ task :environment do |t|
5
5
  require "milk"
6
6
  end
7
7
 
8
- desc "Build the site from scratch if needed"
9
- task :default => [:install, :sass]
10
-
11
- desc "Create the skeleton structure, install the rackup file, and init the bzr repo"
12
- task :install => :environment do
13
-
14
-
15
- # Create missing directories
16
- [ Milk::COMPONENTS_DIR + "/haxe", \
17
- Milk::PAGES_DIR + "/global", \
18
- Milk::PUBLIC_DIR + "/cache", \
19
- Milk::PUBLIC_DIR + "/images", \
20
- Milk::PUBLIC_DIR + "/style", \
21
- MILK_ROOT + "/tmp", \
22
- ].each do |path|
23
- FileUtils.mkdir_p(path, :verbose=>true) unless File.directory?(path)
24
- end
25
-
26
- # Install/update some template files
27
- [ ["rackup", MILK_ROOT + "/config.ru"], \
28
- ["bzrignore", MILK_ROOT + "/.bzrignore"], \
29
- ["rakefile", MILK_ROOT + "/Rakefile"], \
30
- ["restart", MILK_ROOT+"/tmp/restart.txt"] \
31
- ].each do |pair|
32
- source = Milk::LIB_DIR+"/milk/templates/" + pair.first
33
- target = pair.last
34
- FileUtils.install(source, target, :verbose=>true, :preserve => true) \
35
- unless (File.file?(target) && File.mtime(source) <= File.mtime(target))
36
- end
37
-
38
- # Set up bzr repository
39
- if !File.directory? MILK_ROOT+"/.bzr"
40
- exec("cd #{MILK_ROOT} && bzr init && bzr add && bzr ci -m 'Commit initial Milk structure'")
41
- end
42
-
43
- end
44
-
45
8
  desc "Compile all the sass files in the component dir and merge into style.css"
46
9
  task :sass => :environment do
47
10
  style_file = Milk::PUBLIC_DIR + "/style/style.css"
@@ -57,12 +20,14 @@ task :sass => :environment do
57
20
  end
58
21
  end
59
22
 
60
- desc "Delete the cache files and the generated style file"
61
- task :clean => :environment do
23
+ desc "Rebuild the page cache files"
24
+ task :cache => :environment do
62
25
  cachedir = Milk::PUBLIC_DIR+"/cache"
63
26
  FileUtils.rm_rf(cachedir, :verbose=>true)
64
- FileUtils.mkdir_p(cachedir, :verbose=>true)
65
- FileUtils.rm(Milk::PUBLIC_DIR+"/style/style.css", :verbose=>true)
27
+ Milk::Page.each_page do |page|
28
+ puts "saving #{page.pagename}"
29
+ page.save_to_cache
30
+ end
66
31
  end
67
32
 
68
33
  desc "Start up an interactive ruby session with Milk preloaded"
@@ -77,7 +42,7 @@ end
77
42
 
78
43
  desc "Start up a development server using thin"
79
44
  task :server do
80
- exec "rackup -s thin"
45
+ exec "thin -R config.ru start"
81
46
  end
82
47
 
83
48
 
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  tastes great with and without cookies. The public facing aspect is static html
7
7
  files, and the admin side is super easy to use."
8
8
  s.requirements << 'none'
9
- s.version = "0.0.7"
9
+ s.version = "0.0.8"
10
10
  s.author = "Tim Caswell"
11
11
  s.email = "tim@creationix.com"
12
12
  s.homepage = "http://milk.rubyforge.org"
@@ -25,7 +25,7 @@ SECRET: "098f6bcd4621d373cade4e832627b4f6ad0234829205b9033196ba818f7a872b"
25
25
  # # Enable loading page cache files directly
26
26
  # rewrite ^/$ /cache/Home/index.html;
27
27
  # rewrite ^((/[A-Z][A-Za-z]*)+)$ /cache/$1/index.html;
28
- USE_CACHE: false
28
+ USE_CACHE: true
29
29
 
30
30
  # This is used in some views to show the site name
31
31
  SITE_NAME: "Sample Site"
@@ -7,7 +7,6 @@ class Button < Milk::Component
7
7
 
8
8
  # highlight if current page shares base folder with target of link
9
9
  def css_class
10
- print "self #{self}\n"
11
10
  (page.link_to.split('/')[1] == @href.split('/')[1] || page.link_to?(@href)) && "active"
12
11
  end
13
12
 
@@ -0,0 +1,42 @@
1
+ <?xml version='1.0' encoding='utf-8' ?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
4
+ <head>
5
+ <meta content='application/xhtml+xml; charset=UTF-8' http-equiv='content-type' />
6
+ <link href='/favicon.ico' rel='shortcut icon' type='image/x-icon' />
7
+ <link href='/style/style.css' media='screen' rel='stylesheet' type='text/css' />
8
+ <title>About Us - Sample Site</title>
9
+ </head>
10
+ <body>
11
+ <div class='container_12'>
12
+ <ul class='grid_12' id='head'>
13
+ <li>
14
+ <a class='ui-corner-all' href='/Home' title='Description of home page'>
15
+ Home
16
+ </a>
17
+ </li>
18
+ <li>
19
+ <a class='ui-corner-all' href='/News' title='Description of news page'>
20
+ News
21
+ </a>
22
+ </li>
23
+ <li>
24
+ <a class='ui-corner-all' href='/Products' title='Description of products page'>
25
+ Products
26
+ </a>
27
+ </li>
28
+ <li>
29
+ <a class='active ui-corner-all' href='/About' title='Description of about page'>
30
+ About Us
31
+ </a>
32
+ </li>
33
+ </ul>
34
+ <div class='grid_12 body'>
35
+ <h1 id='about_us'>About Us</h1>
36
+
37
+ <p>Description of about page</p>
38
+ </div>
39
+ <div class='grid_12' id='foot'><p>© 2009 Your company name here. - Hosted on the <a href='http://milk.rubyforge.org/'>Milk</a> framework.</p></div>
40
+ </div>
41
+ </body>
42
+ </html>
@@ -0,0 +1,44 @@
1
+ <?xml version='1.0' encoding='utf-8' ?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
4
+ <head>
5
+ <meta content='application/xhtml+xml; charset=UTF-8' http-equiv='content-type' />
6
+ <link href='/favicon.ico' rel='shortcut icon' type='image/x-icon' />
7
+ <meta content='keywords, that, are, relevent, to, search, engines' name='keywords' />
8
+ <meta content='This is a description of this site.' name='description' />
9
+ <link href='/style/style.css' media='screen' rel='stylesheet' type='text/css' />
10
+ <title>Home - Sample Site</title>
11
+ </head>
12
+ <body>
13
+ <div class='container_12'>
14
+ <ul class='grid_12' id='head'>
15
+ <li>
16
+ <a class='active ui-corner-all' href='/Home' title='Description of home page'>
17
+ Home
18
+ </a>
19
+ </li>
20
+ <li>
21
+ <a class='ui-corner-all' href='/News' title='Description of news page'>
22
+ News
23
+ </a>
24
+ </li>
25
+ <li>
26
+ <a class='ui-corner-all' href='/Products' title='Description of products page'>
27
+ Products
28
+ </a>
29
+ </li>
30
+ <li>
31
+ <a class='ui-corner-all' href='/About' title='Description of about page'>
32
+ About Us
33
+ </a>
34
+ </li>
35
+ </ul>
36
+ <div class='grid_12 body'>
37
+ <h1 id='home'>Home</h1>
38
+
39
+ <p>Description of home page</p>
40
+ </div>
41
+ <div class='grid_12' id='foot'><p>© 2009 Your company name here. - Hosted on the <a href='http://milk.rubyforge.org/'>Milk</a> framework.</p></div>
42
+ </div>
43
+ </body>
44
+ </html>
@@ -0,0 +1,42 @@
1
+ <?xml version='1.0' encoding='utf-8' ?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
4
+ <head>
5
+ <meta content='application/xhtml+xml; charset=UTF-8' http-equiv='content-type' />
6
+ <link href='/favicon.ico' rel='shortcut icon' type='image/x-icon' />
7
+ <link href='/style/style.css' media='screen' rel='stylesheet' type='text/css' />
8
+ <title>News - Sample Site</title>
9
+ </head>
10
+ <body>
11
+ <div class='container_12'>
12
+ <ul class='grid_12' id='head'>
13
+ <li>
14
+ <a class='ui-corner-all' href='/Home' title='Description of home page'>
15
+ Home
16
+ </a>
17
+ </li>
18
+ <li>
19
+ <a class='active ui-corner-all' href='/News' title='Description of news page'>
20
+ News
21
+ </a>
22
+ </li>
23
+ <li>
24
+ <a class='ui-corner-all' href='/Products' title='Description of products page'>
25
+ Products
26
+ </a>
27
+ </li>
28
+ <li>
29
+ <a class='ui-corner-all' href='/About' title='Description of about page'>
30
+ About Us
31
+ </a>
32
+ </li>
33
+ </ul>
34
+ <div class='grid_12 body'>
35
+ <h1 id='news'>News</h1>
36
+
37
+ <p>Description of news page</p>
38
+ </div>
39
+ <div class='grid_12' id='foot'><p>© 2009 Your company name here. - Hosted on the <a href='http://milk.rubyforge.org/'>Milk</a> framework.</p></div>
40
+ </div>
41
+ </body>
42
+ </html>
@@ -0,0 +1,42 @@
1
+ <?xml version='1.0' encoding='utf-8' ?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
4
+ <head>
5
+ <meta content='application/xhtml+xml; charset=UTF-8' http-equiv='content-type' />
6
+ <link href='/favicon.ico' rel='shortcut icon' type='image/x-icon' />
7
+ <link href='/style/style.css' media='screen' rel='stylesheet' type='text/css' />
8
+ <title>Products - Sample Site</title>
9
+ </head>
10
+ <body>
11
+ <div class='container_12'>
12
+ <ul class='grid_12' id='head'>
13
+ <li>
14
+ <a class='ui-corner-all' href='/Home' title='Description of home page'>
15
+ Home
16
+ </a>
17
+ </li>
18
+ <li>
19
+ <a class='ui-corner-all' href='/News' title='Description of news page'>
20
+ News
21
+ </a>
22
+ </li>
23
+ <li>
24
+ <a class='active ui-corner-all' href='/Products' title='Description of products page'>
25
+ Products
26
+ </a>
27
+ </li>
28
+ <li>
29
+ <a class='ui-corner-all' href='/About' title='Description of about page'>
30
+ About Us
31
+ </a>
32
+ </li>
33
+ </ul>
34
+ <div class='grid_12 body'>
35
+ <h1 id='products'>Products</h1>
36
+
37
+ <p>Description of products page</p>
38
+ </div>
39
+ <div class='grid_12' id='foot'><p>© 2009 Your company name here. - Hosted on the <a href='http://milk.rubyforge.org/'>Milk</a> framework.</p></div>
40
+ </div>
41
+ </body>
42
+ </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Caswell
@@ -79,6 +79,15 @@ files:
79
79
  - site_template/public/js/jquery-ui-1.7.2.custom.min.js
80
80
  - site_template/public/images
81
81
  - site_template/public/images/README.txt
82
+ - site_template/public/cache
83
+ - site_template/public/cache/Home
84
+ - site_template/public/cache/Home/index.html
85
+ - site_template/public/cache/Products
86
+ - site_template/public/cache/Products/index.html
87
+ - site_template/public/cache/News
88
+ - site_template/public/cache/News/index.html
89
+ - site_template/public/cache/About
90
+ - site_template/public/cache/About/index.html
82
91
  - site_template/public/favicon.ico
83
92
  - site_template/tmp
84
93
  - site_template/tmp/restart.txt