merbiful-release 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  PLUGIN = "merbiful-release"
7
7
  NAME = "merbiful-release"
8
- GEM_VERSION = "0.1.1"
8
+ GEM_VERSION = "0.1.2"
9
9
  AUTHOR = "Martin Kihlgren"
10
10
  EMAIL = "martin@wemind.se"
11
11
  HOMEPAGE = ""
@@ -15,6 +15,7 @@ require 'pp'
15
15
  require 'digest/sha1'
16
16
 
17
17
  require File.join(File.dirname(__FILE__), 'merbiful-release', 'filters.rb')
18
+ require File.join(File.dirname(__FILE__), 'merbiful-release', 'string.rb')
18
19
  require File.join(File.dirname(__FILE__), 'merbiful-release', 'relative_time.rb')
19
20
  require File.join(File.dirname(__FILE__), 'merbiful-release', 'images.rb')
20
21
  require File.join(File.dirname(__FILE__), 'merbiful-release', 'controller.rb')
@@ -14,20 +14,9 @@ require 'erubis'
14
14
  require 'pp'
15
15
  require 'digest/sha1'
16
16
 
17
- module Merbiful
18
-
19
- FILTERS = []
20
-
21
- def self.filters
22
- FILTERS.inject([[nil, "Verbatim"]]) do |sum, filter|
23
- filter_name = filter.name.gsub(/^Merbiful::/, "")
24
- sum + [[filter_name, filter_name]]
25
- end
26
- end
27
-
28
- end
29
-
17
+ require File.join(File.dirname(__FILE__), 'merbiful-release', 'filters.rb')
30
18
  require File.join(File.dirname(__FILE__), 'merbiful-release', 'relative_time.rb')
19
+ require File.join(File.dirname(__FILE__), 'merbiful-release', 'images.rb')
31
20
  require File.join(File.dirname(__FILE__), 'merbiful-release', 'controller.rb')
32
21
  require File.join(File.dirname(__FILE__), 'merbiful-release', 'body.rb')
33
22
  require File.join(File.dirname(__FILE__), 'merbiful-release', 'admin.rb')
@@ -199,6 +199,10 @@ module Merbiful
199
199
 
200
200
  private
201
201
 
202
+ def confirm(message)
203
+ "return confirm('#{message}');"
204
+ end
205
+
202
206
  def text_area_rows
203
207
  20
204
208
  end
@@ -249,7 +253,7 @@ module Merbiful
249
253
  rval << "</a>"
250
254
  rval << "<li class='up'><a href='#{url(:merbiful_admin, :action => 'move_page_up', :page_id => page.id)}'>&uarr;</a></li>"
251
255
  rval << "<li class='down'><a href='#{url(:merbiful_admin, :action => 'move_page_down', :page_id => page.id)}'>&darr;</a></li>"
252
- rval << "<li class='remove'><a href='#{url(:merbiful_admin, :action => 'destroy_page', :page_id => page.id)}'>-</a></li>" unless page.parent_id.nil?
256
+ rval << "<li class='remove'><a href='#{url(:merbiful_admin, :action => 'destroy_page', :page_id => page.id)}' onclick=\"#{confirm("Are you absolutely certain that you want to destroy the page at #{page.path}? All versions will be irreversibly destroyed.")}\">-</a></li>" unless page.parent_id.nil?
253
257
  rval << "<li class='append'><a href='#{url(:merbiful_admin, :action => 'create_page', :parent_id => page.id)}'>+</a></li>"
254
258
  rval << "</ul>"
255
259
  rval << render_template_without_layout("page_form.html.haml") if params[:page_id].to_s == page.id.to_s
@@ -13,7 +13,7 @@ module Merbiful
13
13
  unless Merb.environment == "development"
14
14
  caches.each do |destination, to_cache|
15
15
  if to_cache
16
- path = Pathname.new(File.join(Merb.root, "public", destination))
16
+ path = destination.cached_path
17
17
  Merb.logger.info("Flushing to #{path.inspect}")
18
18
  path.parent.mkpath
19
19
  path.open("w") do |out|
@@ -25,12 +25,6 @@ module Merbiful
25
25
  return rval
26
26
  end
27
27
 
28
- def clear_cache(target)
29
- return if target == "/"
30
- path = Pathname.new(File.join(Merb.root, "public", target))
31
- path.unlink if path.exist?
32
- end
33
-
34
28
  end
35
29
 
36
30
  end
@@ -66,7 +66,7 @@ module Merbiful
66
66
  belongs_to :css, :class_name => "Merbiful::Css"
67
67
 
68
68
  before :save do
69
- clear_cache(css.path) if css.latest
69
+ css.path.clear_cache! if css.latest
70
70
  end
71
71
 
72
72
  end
@@ -17,9 +17,14 @@ module Merbiful
17
17
  property :updated_at, DateTime
18
18
 
19
19
  has n, :css_nesses, :class_name => "Merbiful::Css::Ness"
20
- has n, :page_versions, :through => :css_nesses, :class_name => "Merbiful::Page::Version"
20
+ has n, :page_versions, :through => :css_nesses, :class_name => "Merbiful::Page::Version", :child_key => [:css_id]
21
21
  has n, :css_versions, :class_name => "Merbiful::Css::Version"
22
22
 
23
+ before :destroy do
24
+ css_nesses.destroy!
25
+ css_versions.destroy!
26
+ end
27
+
23
28
  def latest
24
29
  css_versions.first(:css_id => self.id, :order => [:id.desc])
25
30
  end
@@ -35,9 +40,11 @@ module Merbiful
35
40
  include DataMapper::Validate
36
41
 
37
42
  property :id, Serial
43
+ property :page_version_id, Integer
44
+ property :css_id, Integer
38
45
 
39
- belongs_to :css, :class_name => "Merbiful::Css"
40
- belongs_to :page_version, :class_name => "Merbiful::Page::Version"
46
+ belongs_to :css, :class_name => "Merbiful::Css", :child_key => [:css_id]
47
+ belongs_to :page_version, :class_name => "Merbiful::Page::Version", :child_key => [:page_version_id]
41
48
  end
42
49
 
43
50
  class Version
@@ -10,7 +10,7 @@ module Merbiful
10
10
  end
11
11
 
12
12
  def self.filters
13
- @filters.inject([[nil, "Verbatim"]]) do |sum, filter|
13
+ @filters.inject([[nil, "No filter"]]) do |sum, filter|
14
14
  filter_name = filter.name.gsub(/^Merbiful::/, "")
15
15
  sum + [[filter_name, filter_name]]
16
16
  end
@@ -1,13 +1,21 @@
1
1
 
2
2
  module Merbiful
3
3
 
4
- FILTERS = []
4
+ module Filter
5
5
 
6
- def self.filters
7
- FILTERS.inject([[nil, "Verbatim"]]) do |sum, filter|
8
- filter_name = filter.name.gsub(/^Merbiful::/, "")
9
- sum + [[filter_name, filter_name]]
6
+ @filters = []
7
+
8
+ def self.register_filter(filter)
9
+ @filters << filter
10
10
  end
11
+
12
+ def self.filters
13
+ @filters.inject([[nil, "Verbatim"]]) do |sum, filter|
14
+ filter_name = filter.name.gsub(/^Merbiful::/, "")
15
+ sum + [[filter_name, filter_name]]
16
+ end
17
+ end
18
+
11
19
  end
12
20
 
13
21
  end
@@ -65,7 +65,7 @@ module Merbiful
65
65
  belongs_to :js, :class_name => "Merbiful::Js"
66
66
 
67
67
  before :save do
68
- clear_cache(js.path) if js.latest
68
+ js.path.clear_cache! if js.latest
69
69
  end
70
70
 
71
71
  end
@@ -16,9 +16,14 @@ module Merbiful
16
16
  property :updated_at, DateTime
17
17
 
18
18
  has n, :js_nesses, :class_name => "Merbiful::Js::Ness"
19
- has n, :page_versions, :through => :js_nesses, :class_name => "Merbiful::Page::Version"
19
+ has n, :page_versions, :through => :js_nesses, :class_name => "Merbiful::Page::Version", :child_key => [:js_id]
20
20
  has n, :js_versions, :class_name => "Merbiful::Js::Version"
21
21
 
22
+ before :destroy do
23
+ js_nesses.destroy!
24
+ js_versions.destroy!
25
+ end
26
+
22
27
  def latest
23
28
  js_versions.first(:js_id => self.id, :order => [:id.desc])
24
29
  end
@@ -34,9 +39,11 @@ module Merbiful
34
39
  include DataMapper::Validate
35
40
 
36
41
  property :id, Serial
42
+ property :page_version_id, Integer
43
+ property :js_id, Integer
37
44
 
38
- belongs_to :js, :class_name => "Merbiful::Js"
39
- belongs_to :page_version, :class_name => "Merbiful::Page::Version"
45
+ belongs_to :js, :class_name => "Merbiful::Js", :child_key => [:js_id]
46
+ belongs_to :page_version, :class_name => "Merbiful::Page::Version", :child_key => [:page_version_id]
40
47
  end
41
48
 
42
49
  class Version
@@ -83,7 +83,7 @@ module Merbiful
83
83
  end
84
84
 
85
85
  before :save do
86
- clear_cache(page.path) if page.latest
86
+ page.path.clear_cache! if page.latest
87
87
  end
88
88
 
89
89
  def add_css(css)
@@ -26,6 +26,12 @@ module Merbiful
26
26
 
27
27
  validates_is_unique :path
28
28
 
29
+ before :destroy do
30
+ versions.each do |version|
31
+ version.destroy
32
+ end
33
+ end
34
+
29
35
  before :save do
30
36
  if self.position.nil?
31
37
  last_position = self.class.first(:parent_id => self.parent_id, :id.not => self.id)
@@ -66,17 +72,22 @@ module Merbiful
66
72
  belongs_to :layout, :class_name => "Merbiful::Layout"
67
73
 
68
74
  has n, :css_nesses, :class_name => "Merbiful::Css::Ness"
69
- has n, :csses, :through => :css_nesses, :class_name => "Merbiful::Css", :remote_name => :css
75
+ has n, :csses, :through => :css_nesses, :class_name => "Merbiful::Css", :remote_name => :css, :child_key => [:page_version_id]
70
76
 
71
77
  has n, :js_nesses, :class_name => "Merbiful::Js::Ness"
72
- has n, :jses, :through => :js_nesses, :class_name => "Merbiful::Js", :remote_name => :js
78
+ has n, :jses, :through => :js_nesses, :class_name => "Merbiful::Js", :remote_name => :js, :child_key => [:page_version_id]
79
+
80
+ before :destroy do
81
+ css_nesses.destroy!
82
+ js_nesses.destroy!
83
+ end
73
84
 
74
85
  before :save do
75
86
  clear_cache(page.path) if page.latest
76
87
  end
77
88
 
78
89
  def add_css(css)
79
- Merbiful::Css::Ness.new(:css => css, :page_version => self).save
90
+ Merbiful::Css::Ness.create(:css => css, :page_version => self)
80
91
  end
81
92
 
82
93
  def remove_css(css)
@@ -84,7 +95,7 @@ module Merbiful
84
95
  end
85
96
 
86
97
  def add_js(js)
87
- Merbiful::Js::Ness.new(:js => js, :page_version => self).save
98
+ Merbiful::Js::Ness.create(:js => js, :page_version => self)
88
99
  end
89
100
 
90
101
  def remove_js(js)
@@ -0,0 +1,26 @@
1
+
2
+ String.class_eval do
3
+
4
+ def cached_path
5
+ path = Pathname.new(File.join(Merb.root, "public", self))
6
+ raise "H4xx0r" unless path.to_s.index(Pathname.new(Merb.root).join("public").expand_path.to_s) == 0
7
+ if path.parent.file?
8
+ path.parent.unlink
9
+ elsif path.directory?
10
+ path = path.join("index.html")
11
+ end
12
+ path.parent.mkpath
13
+ path
14
+ end
15
+
16
+ def currently_cached?
17
+ path = cached_path
18
+ path.exist? && path.file?
19
+ end
20
+
21
+ def clear_cache!
22
+ path = cached_path
23
+ path.rmtree if path.exist?
24
+ end
25
+
26
+ end
@@ -0,0 +1,16 @@
1
+
2
+ String.class_eval do
3
+
4
+ def cached_path
5
+ path = Pathname.new(File.join(Merb.root, "public", self))
6
+ raise "H4xx0r" unless path.to_s.index(Pathname.new(Merb.root).join("public").expand_path.to_s) == 0
7
+ if path.parent.file?
8
+ path.parent.unlink
9
+ elsif path.directory?
10
+ path = path.join("index.html")
11
+ end
12
+ path
13
+ end
14
+
15
+
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merbiful-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Kihlgren
@@ -9,7 +9,7 @@ autorequire: merbiful-release
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-13 00:00:00 +02:00
12
+ date: 2008-09-16 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -67,6 +67,8 @@ files:
67
67
  - lib/merbiful-release/page.rb~
68
68
  - lib/merbiful-release/relative_time.rb
69
69
  - lib/merbiful-release/routes.rb
70
+ - lib/merbiful-release/string.rb
71
+ - lib/merbiful-release/string.rb~
70
72
  - lib/merbiful-release.rb
71
73
  - lib/merbiful-release.rb~
72
74
  - templates/admin.css