milk 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ spec = Gem::Specification.new do |s|
5
5
  s.summary = "Milk is a rack based content management system built for ease of use and simplicity. Milk tastes great with and without cookies."
6
6
  s.description= File.read(File.join(File.dirname(__FILE__), 'README'))
7
7
  s.requirements << 'none'
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
  s.author = "Tim Caswell"
10
10
  s.email = "tim@creationix.com"
11
11
  s.homepage = "http://milk.rubyforge.org"
@@ -15,6 +15,8 @@ module Milk
15
15
 
16
16
  # Fallback to match everything
17
17
  regex = /(.*)/
18
+
19
+ puts path
18
20
 
19
21
  # Route the request to the right callback
20
22
  action = case
@@ -66,12 +68,12 @@ module Milk
66
68
  end
67
69
 
68
70
  if (action == :preview || action == :save)
69
- page = Milk::Page.json_unserialize(YAML.load(req.body.read))
71
+ page = Milk::Page.json_unserialize(YAML.load(req.body.read), page_name)
70
72
  end
71
73
 
72
74
  return action, page_name, page
73
75
  end
74
-
76
+
75
77
  # Rack call interface
76
78
  def call(env)
77
79
  req = Rack::Request.new(env)
@@ -85,7 +87,7 @@ module Milk
85
87
  else
86
88
  html_type = "text/html"
87
89
  end
88
- html_type = "text/html"
90
+ # html_type = "text/html"
89
91
 
90
92
  case action
91
93
  when :haxe
@@ -97,7 +99,7 @@ module Milk
97
99
  when :edit
98
100
  [200, {"Content-Type"=>html_type}, [page.edit]]
99
101
  when :save
100
- [200, {"Content-Type"=>html_type}, [page.save(page_name)]]
102
+ [200, {"Content-Type"=>html_type}, [page.save]]
101
103
  when :preview
102
104
  [200, {"Content-Type"=>html_type}, [page.preview]]
103
105
  else
@@ -80,6 +80,23 @@ module Milk
80
80
  end
81
81
  end
82
82
 
83
+ def haml(filename, context=self, extras={})
84
+ if block_given?
85
+ Page.haml(filename, context, extras) { yield }
86
+ else
87
+ Page.haml(filename, context, extras)
88
+ end
89
+ end
90
+
91
+ def partial(filename, vars, extras={})
92
+ obj = self.dup
93
+ vars.each do |key, value|
94
+ obj.instance_variable_set("@#{key}", value)
95
+ end
96
+ haml(filename, obj, extras)
97
+ end
98
+
99
+
83
100
  def edit(prefix)
84
101
  @prefix = prefix
85
102
  haml_file = FIELDS_DIR + "/component.haml"
@@ -1,2 +1,2 @@
1
- %div{:class=>"component com_#{index}"}
1
+ %div{:class=>"component com_#{index}", :title => self.name}
2
2
  = yield
@@ -12,9 +12,8 @@
12
12
  body.busy
13
13
  :cursor busy
14
14
  div.component
15
- border: 2px solid transparent
16
15
  &:hover
17
- border-color: #08f
16
+ :border 10px solid #08f
18
17
  #framework-logo
19
18
  :position absolute
20
19
  :bottom 0
@@ -131,7 +130,7 @@
131
130
  %button#cancel_button.toolitem{:title=>'Cancel changes and go to live page.'}
132
131
  %span{:class=>'ui-icon ui-icon-cancel'}
133
132
  Cancel
134
- #preview{:class => "ui-widget ui-helper-reset ui-widget-content"}
133
+ #preview
135
134
  = preview
136
135
  #divider
137
136
  #framework-logo
@@ -250,8 +249,6 @@
250
249
  evt.stopPropagation();
251
250
  evt.preventDefault();
252
251
  var index = this.className.split("_")[1];
253
- console.log(index);
254
- console.log(sections);
255
252
  sections.accordion('activate', parseInt(index)+1);
256
253
  });
257
254
 
@@ -1,21 +1,44 @@
1
1
  module Milk
2
2
  class Page
3
+
4
+ attr_reader :title
5
+ attr_reader :description
6
+ attr_reader :pagename
7
+
3
8
  def self.find(pagename)
4
- yaml_file = Milk::PAGES_DIR + "/" + pagename.gsub(/\//, '.') + ".yml"
9
+ yaml_file = Milk::PAGES_DIR + "/" + pagename + ".yml"
5
10
  raise PageNotFoundError unless File.readable? yaml_file
6
11
  page = YAML.load_file(yaml_file)
7
12
  page.instance_variable_set('@pagename', pagename)
8
13
  page.load_settings
9
14
  page
10
15
  end
16
+
17
+ def self.haml(filename, context, extras)
18
+ if block_given?
19
+ ::Haml::Engine.new(File.read(filename), :filename => filename).render(context, extras) do
20
+ yield
21
+ end
22
+ else
23
+ ::Haml::Engine.new(File.read(filename), :filename => filename).render(context, extras)
24
+ end
25
+ end
26
+
27
+ def haml(filename, context=self, extras={})
28
+ if block_given?
29
+ Page.haml(filename, context, extras) { yield }
30
+ else
31
+ Page.haml(filename, context, extras)
32
+ end
33
+ end
11
34
 
12
35
  def to_yaml_properties
13
36
  [:@components, :@title, :@keywords, :@description]
14
37
  end
15
38
 
16
- def save(pagename)
39
+ def save
17
40
  save_settings
18
- yaml_file = Milk::PAGES_DIR + "/" + pagename.gsub(/\//, '.') + ".yml"
41
+ yaml_file = Milk::PAGES_DIR + "/" + @pagename + ".yml"
19
42
  data = YAML.dump(self)
20
43
  File.open(yaml_file, "w") do |file|
21
44
  file.write(data)
@@ -23,7 +46,7 @@ module Milk
23
46
  data
24
47
  end
25
48
 
26
- def self.json_unserialize(data)
49
+ def self.json_unserialize(data, pagename=nil)
27
50
  class_name = data.delete('class')
28
51
  obj = class_name.constantize.allocate
29
52
  data.each do |key, value|
@@ -32,6 +55,7 @@ module Milk
32
55
  end
33
56
  obj.instance_variable_set("@#{key}", value)
34
57
  end
58
+ obj.instance_variable_set("@pagename", pagename) if obj.class == Milk::Page
35
59
  obj
36
60
  end
37
61
 
@@ -48,24 +72,23 @@ module Milk
48
72
  end
49
73
 
50
74
  def edit
51
- filename = FIELDS_DIR + "/xhtml.haml"
52
- ::Haml::Engine.new(File.read(filename), :filename => filename).render(self)
75
+ haml(FIELDS_DIR + "/xhtml.haml", self)
53
76
  end
54
77
 
55
78
  def preview
56
- haml_template_file = FIELDS_DIR + "/component_view.haml"
57
- i = 0
58
- (@components.map do |component|
59
- ::Haml::Engine.new(File.read(haml_template_file), :filename => haml_template_file).render(self, {:index=>i}) do
60
- i += 1
61
- component.view
62
- end
63
- end).join("\n")
79
+ haml(Milk::COMPONENTS_DIR + "/page.haml", self) do
80
+ i = 0
81
+ (@components.collect do |component|
82
+ haml(FIELDS_DIR + "/component_view.haml", component, {:index=>i}) do
83
+ i += 1
84
+ component.view
85
+ end
86
+ end).join("\n")
87
+ end
64
88
  end
65
89
 
66
90
  def view
67
- filename = Milk::COMPONENTS_DIR + "/xhtml.haml"
68
- ::Haml::Engine.new(File.read(filename), :filename => filename).render(self) do
91
+ haml(Milk::COMPONENTS_DIR + "/xhtml.haml", self) do
69
92
  preview
70
93
  end
71
94
  end
@@ -1,5 +1,4 @@
1
- ::MILK_ROOT = ::File.absolute_path(::File.dirname(__FILE__))
2
- require '../lib/milk'
1
+ require 'milk'
3
2
 
4
3
  # use Lock
5
4
  if %w{rackup thin}.member?($0.rpartition('/').last)
@@ -1,4 +1,3 @@
1
- ::MILK_ROOT = File.dirname(__FILE__)
2
1
  require 'rake'
3
- load '../lib/milk/tasks.rb'
2
+ load 'milk/tasks.rb'
4
3
 
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Caswell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-18 00:00:00 -05:00
12
+ date: 2009-06-02 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,44 +51,42 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
 
53
53
  files:
54
- - INSTALL
55
- - README
56
- - Rakefile
57
- - test
58
- - pkg
59
54
  - bin
60
55
  - bin/milk
61
- - LICENSE
56
+ - INSTALL
62
57
  - lib
63
- - lib/milk.rb
64
58
  - lib/milk
65
- - lib/milk/tasks.rb
59
+ - lib/milk/application.rb
60
+ - lib/milk/component.rb
66
61
  - lib/milk/field.rb
67
- - lib/milk/haxe.rb
68
62
  - lib/milk/fields
69
- - lib/milk/fields/component_array.rb
70
- - lib/milk/fields/sprite_chooser.haml
71
- - lib/milk/fields/sprite_chooser.rb
72
- - lib/milk/fields/image_chooser.rb
73
- - lib/milk/fields/page_chooser.haml
74
- - lib/milk/fields/markdown_field.rb
75
63
  - lib/milk/fields/component.haml
64
+ - lib/milk/fields/component_array.haml
65
+ - lib/milk/fields/component_array.rb
66
+ - lib/milk/fields/component_view.haml
76
67
  - lib/milk/fields/image_chooser.haml
68
+ - lib/milk/fields/image_chooser.rb
77
69
  - lib/milk/fields/markdown_field.haml
78
- - lib/milk/fields/text_field.rb
79
- - lib/milk/fields/component_view.haml
70
+ - lib/milk/fields/markdown_field.rb
71
+ - lib/milk/fields/page_chooser.haml
80
72
  - lib/milk/fields/page_chooser.rb
81
- - lib/milk/fields/component_array.haml
73
+ - lib/milk/fields/sprite_chooser.haml
74
+ - lib/milk/fields/sprite_chooser.rb
82
75
  - lib/milk/fields/text_field.haml
76
+ - lib/milk/fields/text_field.rb
83
77
  - lib/milk/fields/xhtml.haml
84
- - lib/milk/application.rb
78
+ - lib/milk/haxe.rb
85
79
  - lib/milk/page.rb
80
+ - lib/milk/tasks.rb
86
81
  - lib/milk/templates
87
- - lib/milk/templates/rackup
88
- - lib/milk/templates/restart
89
82
  - lib/milk/templates/bzrignore
83
+ - lib/milk/templates/rackup
90
84
  - lib/milk/templates/rakefile
91
- - lib/milk/component.rb
85
+ - lib/milk/templates/restart
86
+ - lib/milk.rb
87
+ - LICENSE
88
+ - Rakefile
89
+ - README
92
90
  has_rdoc: false
93
91
  homepage: http://milk.rubyforge.org
94
92
  post_install_message: