merbiful-release 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +44 -0
- data/lib/merbiful-release/admin.rb +281 -0
- data/lib/merbiful-release/admin.rb~ +12 -0
- data/lib/merbiful-release/body.rb +36 -0
- data/lib/merbiful-release/body.rb~ +15 -0
- data/lib/merbiful-release/controller.rb +55 -0
- data/lib/merbiful-release/controller.rb~ +12 -0
- data/lib/merbiful-release/css.rb +70 -0
- data/lib/merbiful-release/css.rb~ +62 -0
- data/lib/merbiful-release/erubis.rb +13 -0
- data/lib/merbiful-release/erubis.rb~ +11 -0
- data/lib/merbiful-release/eruby.rb~ +11 -0
- data/lib/merbiful-release/filters.rb +22 -0
- data/lib/merbiful-release/haml.rb +23 -0
- data/lib/merbiful-release/haml.rb~ +11 -0
- data/lib/merbiful-release/images.rb +28 -0
- data/lib/merbiful-release/js.rb +69 -0
- data/lib/merbiful-release/js.rb~ +62 -0
- data/lib/merbiful-release/layout.rb +49 -0
- data/lib/merbiful-release/layout.rb~ +21 -0
- data/lib/merbiful-release/merbiful.rb~ +8 -0
- data/lib/merbiful-release/page.rb +98 -0
- data/lib/merbiful-release/page.rb~ +57 -0
- data/lib/merbiful-release/relative_time.rb +116 -0
- data/lib/merbiful-release/relative_time.rb~ +78 -0
- data/lib/merbiful-release/routes.rb +42 -0
- data/lib/merbiful-release/routes.rb~ +4 -0
- data/lib/merbiful-release/version.rb~ +45 -0
- data/lib/merbiful-release.rb +29 -0
- data/lib/merbiful-release.rb~ +2 -0
- data/templates/admin.css +17 -0
- data/templates/admin.css~ +3 -0
- data/templates/admin_layout.html.haml +11 -0
- data/templates/admin_layout.html.haml~ +9 -0
- data/templates/admin_layout.html.rhtml~ +10 -0
- data/templates/css.html.haml +29 -0
- data/templates/css.html.haml.orig +28 -0
- data/templates/css.html.haml~ +29 -0
- data/templates/images.html.haml +17 -0
- data/templates/index.html.haml +2 -0
- data/templates/index.html.haml~ +2 -0
- data/templates/js.html.haml +26 -0
- data/templates/js.html.haml~ +29 -0
- data/templates/layouts.html.haml +23 -0
- data/templates/layouts.html.haml~ +0 -0
- data/templates/page_form.html.haml +41 -0
- data/templates/page_form.html.haml~ +1 -0
- data/templates/pages.html.haml~ +3 -0
- metadata +120 -0
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'spec'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
PLUGIN = "merbiful-release"
|
8
|
+
NAME = "merbiful-release"
|
9
|
+
GEM_VERSION = "0.0.1"
|
10
|
+
AUTHOR = "Martin Kihlgren"
|
11
|
+
EMAIL = "martin@wemind.se"
|
12
|
+
HOMEPAGE = ""
|
13
|
+
SUMMARY = "Merb plugin that provides a simple CMS"
|
14
|
+
|
15
|
+
spec = Gem::Specification.new do |s|
|
16
|
+
s.name = NAME
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.summary = SUMMARY
|
21
|
+
s.description = s.summary
|
22
|
+
s.author = AUTHOR
|
23
|
+
s.email = EMAIL
|
24
|
+
s.homepage = HOMEPAGE
|
25
|
+
s.add_dependency('merb-core', '>= 0.9.5')
|
26
|
+
s.add_dependency('dm-core', '>= 0.9.5')
|
27
|
+
s.require_path = 'lib'
|
28
|
+
s.autorequire = PLUGIN
|
29
|
+
s.files = %w(Rakefile) + Dir.glob("{lib,specs,templates}/**/*")
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
33
|
+
pkg.gem_spec = spec
|
34
|
+
end
|
35
|
+
|
36
|
+
task :install => [:package] do
|
37
|
+
sh %{sudo gem install pkg/#{NAME}-#{GEM_VERSION} --no-update-sources --no-update-sources}
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Run specifications"
|
41
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
42
|
+
t.spec_opts = ["--format", "specdoc", "--colour"]
|
43
|
+
t.spec_files = Pathname.glob(Pathname.new(__FILE__).parent.join("spec").join("**").join("*_spec.rb"))
|
44
|
+
end
|
@@ -0,0 +1,281 @@
|
|
1
|
+
|
2
|
+
module Merbiful
|
3
|
+
|
4
|
+
class Admin < Merb::Controller
|
5
|
+
|
6
|
+
include RelativeTimeHelpers
|
7
|
+
|
8
|
+
def index
|
9
|
+
render_template_with_layout("index.html.haml")
|
10
|
+
end
|
11
|
+
|
12
|
+
def layouts
|
13
|
+
@form_layout = Layout.get(params[:layout_id])
|
14
|
+
if request.post?
|
15
|
+
@form_layout.update_attributes(params[:layout])
|
16
|
+
if @form_layout.valid?
|
17
|
+
@form_layout.save
|
18
|
+
@form_version = Layout::Version.new(params[:version].merge(:layout => @form_layout))
|
19
|
+
if @form_version.valid?
|
20
|
+
@form_version.save
|
21
|
+
redirect url(:merbiful_admin, :action => "layouts", :layout_id => @form_layout.id)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
@form_version = @form_layout.latest if @form_layout
|
26
|
+
end
|
27
|
+
render_template_with_layout("layouts.html.haml")
|
28
|
+
end
|
29
|
+
|
30
|
+
def js
|
31
|
+
@form_js = Js.get(params[:js_id])
|
32
|
+
if request.post?
|
33
|
+
params[:js][:cached] = !!params[:js][:cached]
|
34
|
+
@form_js.update_attributes(params[:js])
|
35
|
+
if @form_js.valid?
|
36
|
+
@form_js.save
|
37
|
+
@form_version = Js::Version.new(params[:version].merge(:js => @form_js))
|
38
|
+
if @form_version.valid?
|
39
|
+
@form_version.save
|
40
|
+
redirect url(:merbiful_admin, :action => "js", :js_id => @form_js.id)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
else
|
44
|
+
@form_version = @form_layout.latest if @form_layout
|
45
|
+
end
|
46
|
+
render_template_with_layout("js.html.haml")
|
47
|
+
end
|
48
|
+
|
49
|
+
def images
|
50
|
+
if request.post?
|
51
|
+
end
|
52
|
+
render_template_with_layout("images.html.haml")
|
53
|
+
end
|
54
|
+
|
55
|
+
def css
|
56
|
+
@form_css = Css.get(params[:css_id])
|
57
|
+
if request.post?
|
58
|
+
params[:css][:cached] = !!params[:css][:cached]
|
59
|
+
@form_css.update_attributes(params[:css])
|
60
|
+
if @form_css.valid?
|
61
|
+
@form_css.save
|
62
|
+
@form_version = Css::Version.new(params[:version].merge(:css => @form_css))
|
63
|
+
if @form_version.valid?
|
64
|
+
@form_version.save
|
65
|
+
redirect url(:merbiful_admin, :action => "css", :css_id => @form_css.id)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
else
|
69
|
+
@form_version = @form_layout.latest if @form_layout
|
70
|
+
end
|
71
|
+
render_template_with_layout("css.html.haml")
|
72
|
+
end
|
73
|
+
|
74
|
+
def pages
|
75
|
+
if Page.count == 0
|
76
|
+
new_root = Page.create(:path => "/")
|
77
|
+
new_root_version = Page::Version.create(:page => new_root, :body => "Here be Dagon")
|
78
|
+
end
|
79
|
+
@form_page = Page.get(params[:page_id])
|
80
|
+
if request.post?
|
81
|
+
params[:page][:cached] = !!params[:page][:cached]
|
82
|
+
@form_page.update_attributes(params[:page])
|
83
|
+
if @form_page.valid?
|
84
|
+
@form_page.save
|
85
|
+
version_csses = params[:version].delete(:css)
|
86
|
+
version_jses = params[:version].delete(:js)
|
87
|
+
@form_version = Page::Version.new(params[:version].merge(:page => @form_page))
|
88
|
+
version_csses.each do |css|
|
89
|
+
@form_version.add_css(Css.get(css))
|
90
|
+
end if version_csses
|
91
|
+
version_jses.each do |js|
|
92
|
+
@form_version.add_js(Js.get(js))
|
93
|
+
end if version_jses
|
94
|
+
if @form_version.valid?
|
95
|
+
@form_version.save
|
96
|
+
redirect url(:merbiful_admin, :action => "pages", :page_id => @form_page.id)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
else
|
100
|
+
@form_version = @form_page.latest if @form_page
|
101
|
+
end
|
102
|
+
render_with_layout(Page.all(:parent_id => nil).collect do |page|
|
103
|
+
"<ul class='root'>\n#{render_page(page)}\n</ul>"
|
104
|
+
end.join("\n"))
|
105
|
+
end
|
106
|
+
|
107
|
+
def render_css
|
108
|
+
read_template("admin.css")
|
109
|
+
end
|
110
|
+
|
111
|
+
def destroy_page
|
112
|
+
page = Page.get(params[:page_id])
|
113
|
+
page.versions.each do |version|
|
114
|
+
version.css_nesses.destroy!
|
115
|
+
version.js_nesses.destroy!
|
116
|
+
version.destroy
|
117
|
+
end
|
118
|
+
page.destroy
|
119
|
+
redirect url(:merbiful_admin, :action => "pages")
|
120
|
+
end
|
121
|
+
|
122
|
+
def upload_image
|
123
|
+
path = Pathname.new(File.join(Merb.root, "public", "images", File.basename(params[:image][:filename])))
|
124
|
+
Pathname.new(params[:image][:tempfile].path).rename(path)
|
125
|
+
redirect url(:merbiful_admin, :action => "images")
|
126
|
+
end
|
127
|
+
|
128
|
+
def delete_image
|
129
|
+
path = Pathname.new(File.join(Merb.root, "public", params[:path])).expand_path
|
130
|
+
raise "H4xx0r" unless path.to_s.index(Pathname.new(Merb.root).expand_path.to_s) == 0
|
131
|
+
path.unlink
|
132
|
+
redirect url(:merbiful_admin, :action => "images")
|
133
|
+
end
|
134
|
+
|
135
|
+
def destroy_layout
|
136
|
+
layout = Layout.get(params[:layout_id])
|
137
|
+
layout.page_versions.each do |page_version|
|
138
|
+
page_version.layout = nil
|
139
|
+
page_version.save
|
140
|
+
end
|
141
|
+
layout.layout_versions.destroy!
|
142
|
+
layout.destroy
|
143
|
+
redirect url(:merbiful_admin, :action => "layouts")
|
144
|
+
end
|
145
|
+
|
146
|
+
def destroy_css
|
147
|
+
css = Css.get(params[:css_id])
|
148
|
+
css.css_nesses.destroy!
|
149
|
+
css.css_versions.destroy!
|
150
|
+
css.destroy
|
151
|
+
redirect url(:merbiful_admin, :action => "css")
|
152
|
+
end
|
153
|
+
|
154
|
+
def destroy_js
|
155
|
+
js = Js.get(params[:js_id])
|
156
|
+
js.js_nesses.destroy!
|
157
|
+
js.js_versions.destroy!
|
158
|
+
js.destroy
|
159
|
+
redirect url(:merbiful_admin, :action => "js")
|
160
|
+
end
|
161
|
+
|
162
|
+
def create_page
|
163
|
+
parent = Page.get(params[:parent_id])
|
164
|
+
new_page = Page.create(:parent => parent, :path => next_path(parent.path))
|
165
|
+
new_page_version = Page::Version.create(:page => new_page)
|
166
|
+
redirect url(:merbiful_admin, :action => "pages", :page_id => new_page.id)
|
167
|
+
end
|
168
|
+
|
169
|
+
def create_css
|
170
|
+
new_css = Css.create(:name => next_name(Css))
|
171
|
+
new_css_version = Css::Version.create(:css => new_css)
|
172
|
+
redirect url(:merbiful_admin, :action => 'css')
|
173
|
+
end
|
174
|
+
|
175
|
+
def create_js
|
176
|
+
new_js = Js.create(:name => next_name(Js))
|
177
|
+
new_js_version = Js::Version.create(:js => new_js)
|
178
|
+
redirect url(:merbiful_admin, :action => 'js')
|
179
|
+
end
|
180
|
+
|
181
|
+
def create_layout
|
182
|
+
new_layout = Layout.create(:name => next_name(Layout))
|
183
|
+
new_layout_version = Layout::Version.create(:layout => new_layout)
|
184
|
+
redirect url(:merbiful_admin, :action => 'layouts')
|
185
|
+
end
|
186
|
+
|
187
|
+
def move_page_up
|
188
|
+
page = Page.get(params[:page_id])
|
189
|
+
page.position -= 1
|
190
|
+
page.save
|
191
|
+
redirect url(:merbiful_admin, :action => "pages")
|
192
|
+
end
|
193
|
+
|
194
|
+
def move_page_down
|
195
|
+
page = Page.get(params[:page_id])
|
196
|
+
page.position += 1
|
197
|
+
page.save
|
198
|
+
redirect url(:merbiful_admin, :action => "pages")
|
199
|
+
end
|
200
|
+
|
201
|
+
private
|
202
|
+
|
203
|
+
def text_area_rows
|
204
|
+
20
|
205
|
+
end
|
206
|
+
|
207
|
+
def next_path(parent_path)
|
208
|
+
index = 0
|
209
|
+
while Page.first(:path => File.join(parent_path, index.to_s))
|
210
|
+
index += 1
|
211
|
+
end
|
212
|
+
return File.join(parent_path, index.to_s)
|
213
|
+
end
|
214
|
+
|
215
|
+
def next_name(klass)
|
216
|
+
index = 0
|
217
|
+
while klass.first(:name => index.to_s)
|
218
|
+
index += 1
|
219
|
+
end
|
220
|
+
return index.to_s
|
221
|
+
end
|
222
|
+
|
223
|
+
def errors(obj, meth)
|
224
|
+
return ""
|
225
|
+
if obj.errors.on(meth)
|
226
|
+
obj.errors.on(meth).join(", ")
|
227
|
+
else
|
228
|
+
""
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def render_children(page, ind = "")
|
233
|
+
rval = []
|
234
|
+
rval << "<ul class='children'>"
|
235
|
+
page.children(:order => [:position, :id]).each do |child|
|
236
|
+
rval << render_page(child, ind + " ")
|
237
|
+
end
|
238
|
+
rval << "</ul>"
|
239
|
+
return rval.collect do |line| ind + line end.join("\n")
|
240
|
+
end
|
241
|
+
|
242
|
+
def render_page(page, ind = "")
|
243
|
+
rval = []
|
244
|
+
rval << "<li class='page'>"
|
245
|
+
rval << "<ul class='page_info info'>"
|
246
|
+
rval << "<a href='#{url(:merbiful_admin, :action => 'pages', :page_id => page.id)}'>"
|
247
|
+
rval << "<li class='page_path'>#{page.path}</li>"
|
248
|
+
rval << "<li class='page_title'>#{page.title || "untitled"}</li>"
|
249
|
+
rval << "<li class='page_version'>ver##{page.latest.id} (#{time_ago_in_words(page.latest.created_at)} ago)</li>"
|
250
|
+
rval << "</a>"
|
251
|
+
rval << "<li class='up'><a href='#{url(:merbiful_admin, :action => 'move_page_up', :page_id => page.id)}'>↑</a></li>"
|
252
|
+
rval << "<li class='down'><a href='#{url(:merbiful_admin, :action => 'move_page_down', :page_id => page.id)}'>↓</a></li>"
|
253
|
+
rval << "<li class='remove'><a href='#{url(:merbiful_admin, :action => 'destroy_page', :page_id => page.id)}'>-</a></li>" unless page.parent_id.nil?
|
254
|
+
rval << "<li class='append'><a href='#{url(:merbiful_admin, :action => 'create_page', :parent_id => page.id)}'>+</a></li>"
|
255
|
+
rval << "</ul>"
|
256
|
+
rval << render_template_without_layout("page_form.html.haml") if params[:page_id].to_s == page.id.to_s
|
257
|
+
rval << render_children(page, ind) unless page.children.empty?
|
258
|
+
rval << "</li>"
|
259
|
+
return rval.collect do |line| ind + line end.join("\n")
|
260
|
+
end
|
261
|
+
|
262
|
+
def read_template(template)
|
263
|
+
Pathname.new(__FILE__).parent.parent.parent.join("templates").join(template).read
|
264
|
+
end
|
265
|
+
|
266
|
+
def render_with_layout(text)
|
267
|
+
throw_content :for_layout, text
|
268
|
+
::Haml::Engine.new(read_template("admin_layout.html.haml")).render(self)
|
269
|
+
end
|
270
|
+
|
271
|
+
def render_template_with_layout(template)
|
272
|
+
render_with_layout(::Haml::Engine.new(read_template(template)).render(self))
|
273
|
+
end
|
274
|
+
|
275
|
+
def render_template_without_layout(template)
|
276
|
+
::Haml::Engine.new(read_template(template)).render(self)
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
module Merbiful
|
3
|
+
|
4
|
+
module Body
|
5
|
+
|
6
|
+
def render(controller, caches = {})
|
7
|
+
rval = if self.filter.blank?
|
8
|
+
self.body
|
9
|
+
else
|
10
|
+
filter_class = Merbiful.const_get(self.filter.to_sym)
|
11
|
+
filter_class.new.render(self.body, controller)
|
12
|
+
end
|
13
|
+
unless Merb.environment == "development"
|
14
|
+
caches.each do |destination, to_cache|
|
15
|
+
if to_cache
|
16
|
+
path = Pathname.new(File.join(Merb.root, "public", destination))
|
17
|
+
Merb.logger.info("Flushing to #{path.inspect}")
|
18
|
+
path.parent.mkpath
|
19
|
+
path.open("w") do |out|
|
20
|
+
out.write(rval)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return rval
|
26
|
+
end
|
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
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
module Merbiful
|
3
|
+
|
4
|
+
class Controller < Merb::Controller
|
5
|
+
|
6
|
+
class MissingPageError < RuntimeError
|
7
|
+
end
|
8
|
+
|
9
|
+
class MissingLayoutError < RuntimeError
|
10
|
+
end
|
11
|
+
|
12
|
+
class MissingCssError < RuntimeError
|
13
|
+
end
|
14
|
+
|
15
|
+
class MissingJsError < RuntimeError
|
16
|
+
end
|
17
|
+
|
18
|
+
def css(id)
|
19
|
+
css_version = Css::Version.get(id)
|
20
|
+
raise MissingCssError.new(id) unless css_version
|
21
|
+
css_version.render(self, css_version.css.path => css_version.css.cached)
|
22
|
+
end
|
23
|
+
|
24
|
+
def js(id)
|
25
|
+
js_version = Js::Version.get(id)
|
26
|
+
raise MissingJsError.new(id) unless js_version
|
27
|
+
js_version.render(self, js_version.js.path => js_version.js.cached)
|
28
|
+
end
|
29
|
+
|
30
|
+
def display(what)
|
31
|
+
@page = Page.first(:path => what)
|
32
|
+
raise NotFound.new(what.inspect) unless @page
|
33
|
+
unless @page.jses.empty?
|
34
|
+
throw_content(:for_js, @page.jses.inject([]) do |sum, frozen_js|
|
35
|
+
js = Js.get(frozen_js.id)
|
36
|
+
sum << "<script src='#{js.path}' type='text/javascript'></script>"
|
37
|
+
end.join("\n"))
|
38
|
+
end
|
39
|
+
unless @page.csses.empty?
|
40
|
+
throw_content(:for_css, @page.csses.inject([]) do |sum, frozen_css|
|
41
|
+
css = Css.get(frozen_css.id)
|
42
|
+
sum << "<link href='#{css.path}' #{css.media.blank? ? "" : "media='#{css.media}' "}rel='Stylesheet' type='text/css' />"
|
43
|
+
end.join("\n"))
|
44
|
+
end
|
45
|
+
if @page.layout
|
46
|
+
throw_content :for_layout, @page.render(self)
|
47
|
+
@page.layout.render(self, @page.path => @page.cached)
|
48
|
+
else
|
49
|
+
@page.render(self, @page.path => @page.cached)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
module Merbiful
|
3
|
+
|
4
|
+
class Css
|
5
|
+
|
6
|
+
include DataMapper::Resource
|
7
|
+
include DataMapper::Validate
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
property :id, Serial
|
11
|
+
|
12
|
+
property :name, DataMapper::Types::Text, :nullable => false
|
13
|
+
property :media, DataMapper::Types::Text
|
14
|
+
property :cached, Boolean, :default => true, :nullable => false
|
15
|
+
|
16
|
+
property :created_at, DateTime
|
17
|
+
property :updated_at, DateTime
|
18
|
+
|
19
|
+
has n, :css_nesses, :class_name => "Merbiful::Css::Ness"
|
20
|
+
has n, :page_versions, :through => :css_nesses, :class_name => "Merbiful::Page::Version"
|
21
|
+
has n, :css_versions, :class_name => "Merbiful::Css::Version"
|
22
|
+
|
23
|
+
def latest
|
24
|
+
css_versions.first(:css_id => self.id, :order => [:id.desc])
|
25
|
+
end
|
26
|
+
|
27
|
+
def_delegators :latest, :render, :body, :filter
|
28
|
+
|
29
|
+
def path
|
30
|
+
"/stylesheets/#{latest.id}"
|
31
|
+
end
|
32
|
+
|
33
|
+
class Ness
|
34
|
+
include DataMapper::Resource
|
35
|
+
include DataMapper::Validate
|
36
|
+
|
37
|
+
property :id, Serial
|
38
|
+
|
39
|
+
belongs_to :css, :class_name => "Merbiful::Css"
|
40
|
+
belongs_to :page_version, :class_name => "Merbiful::Page::Version"
|
41
|
+
end
|
42
|
+
|
43
|
+
class Version
|
44
|
+
|
45
|
+
include DataMapper::Resource
|
46
|
+
include DataMapper::Validate
|
47
|
+
include Merbiful::Body
|
48
|
+
|
49
|
+
property :id, Serial
|
50
|
+
|
51
|
+
property :css_id, Integer, :index => true, :nullable => false
|
52
|
+
|
53
|
+
property :body, DataMapper::Types::Text
|
54
|
+
property :filter, DataMapper::Types::Text
|
55
|
+
|
56
|
+
property :created_at, DateTime
|
57
|
+
property :updated_at, DateTime
|
58
|
+
|
59
|
+
belongs_to :css, :class_name => "Merbiful::Css"
|
60
|
+
|
61
|
+
before :save do
|
62
|
+
clear_cache(css.path) if css.latest
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
module Merbiful
|
3
|
+
|
4
|
+
class Css
|
5
|
+
|
6
|
+
include DataMapper::Resource
|
7
|
+
include DataMapper::Validate
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
property :id, Serial
|
11
|
+
|
12
|
+
property :name, DataMapper::Types::Text, :nullable => false
|
13
|
+
property :media, DataMapper::Types::Text
|
14
|
+
property :cached, Boolean, :default => true, :nullable => false
|
15
|
+
|
16
|
+
property :created_at, DateTime
|
17
|
+
property :updated_at, DateTime
|
18
|
+
|
19
|
+
has n, :css_nesses, :class_name => "Merbiful::Css::Ness"
|
20
|
+
has n, :page_versions, :through => :css_nesses, :class_name => "Merbiful::Page::Version"
|
21
|
+
has n, :css_versions, :class_name => "Merbiful::Css::Version"
|
22
|
+
|
23
|
+
def latest
|
24
|
+
css_versions.first(:order => [:id.desc])
|
25
|
+
end
|
26
|
+
|
27
|
+
def_delegators :latest, :render
|
28
|
+
|
29
|
+
class Ness
|
30
|
+
include DataMapper::Resource
|
31
|
+
include DataMapper::Validate
|
32
|
+
|
33
|
+
property :id, Serial
|
34
|
+
|
35
|
+
belongs_to :css, :class_name => "Merbiful::Css"
|
36
|
+
belongs_to :page_version, :class_name => "Merbiful::Page::Version"
|
37
|
+
end
|
38
|
+
|
39
|
+
class Version
|
40
|
+
|
41
|
+
include DataMapper::Resource
|
42
|
+
include DataMapper::Validate
|
43
|
+
include Merbiful::Body
|
44
|
+
|
45
|
+
property :id, Serial
|
46
|
+
|
47
|
+
property :css_id, Integer, :index => true, :nullable => false
|
48
|
+
|
49
|
+
property :body, DataMapper::Types::Text
|
50
|
+
property :filter, DataMapper::Types::Text
|
51
|
+
|
52
|
+
property :created_at, DateTime
|
53
|
+
property :updated_at, DateTime
|
54
|
+
|
55
|
+
belongs_to :css, :class_name => "Merbiful::Css"
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
module Merbiful
|
3
|
+
|
4
|
+
module Filter
|
5
|
+
|
6
|
+
@filters = []
|
7
|
+
|
8
|
+
def self.register_filter(filter)
|
9
|
+
@filters << filter
|
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
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module Merbiful
|
3
|
+
|
4
|
+
class Haml
|
5
|
+
|
6
|
+
def render(text, scope)
|
7
|
+
::Haml::Engine.new(text).render(scope)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class Sass
|
13
|
+
|
14
|
+
def render(text, scope)
|
15
|
+
::Sass::Engine.new(text).render
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
Filter.register_filter(Haml)
|
21
|
+
Filter.register_filter(Sass)
|
22
|
+
|
23
|
+
end
|