merb-words 0.1
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/LICENSE +20 -0
- data/README +59 -0
- data/Rakefile +68 -0
- data/app/controllers/application.rb +5 -0
- data/app/controllers/categories.rb +52 -0
- data/app/controllers/pages.rb +109 -0
- data/app/controllers/passwords.rb +89 -0
- data/app/helpers/application_helper.rb +55 -0
- data/app/helpers/global_helpers.rb +7 -0
- data/app/models/category.rb +10 -0
- data/app/models/order.rb +9 -0
- data/app/models/page.rb +14 -0
- data/app/models/password.rb +25 -0
- data/app/views/categories/_form.html.erb +3 -0
- data/app/views/categories/create.html.erb +8 -0
- data/app/views/categories/delete.html.erb +8 -0
- data/app/views/categories/update.html.erb +8 -0
- data/app/views/layout/application.xml.erb +8 -0
- data/app/views/pages/_category.html.erb +41 -0
- data/app/views/pages/_form.html.erb +29 -0
- data/app/views/pages/_order.html.erb +17 -0
- data/app/views/pages/_page.html.erb +26 -0
- data/app/views/pages/_preview.html.erb +14 -0
- data/app/views/pages/_search.html.erb +21 -0
- data/app/views/pages/create.html.erb +8 -0
- data/app/views/pages/delete.html.erb +6 -0
- data/app/views/pages/feed.xml.erb +7 -0
- data/app/views/pages/index.html.erb +34 -0
- data/app/views/pages/read.html.erb +19 -0
- data/app/views/pages/update.html.erb +8 -0
- data/app/views/passwords/_form.html.erb +12 -0
- data/app/views/passwords/create.html.erb +8 -0
- data/app/views/passwords/delete.html.erb +6 -0
- data/app/views/passwords/read.html.erb +10 -0
- data/app/views/passwords/update.html.erb +9 -0
- data/lib/merb-words/merbtasks.rb +103 -0
- data/lib/merb-words/slicetasks.rb +18 -0
- data/lib/merb-words/spectasks.rb +65 -0
- data/lib/merb-words.rb +107 -0
- metadata +120 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Jamie Hoover
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Prerequisite:
|
2
|
+
|
3
|
+
http://github.com/uipoet/merb-ui/tree/master
|
4
|
+
|
5
|
+
------------------------------------------------------------------------------
|
6
|
+
|
7
|
+
Installation:
|
8
|
+
|
9
|
+
1.) Install merb-words gem.
|
10
|
+
git clone git://github.com/uipoet/merb-words.git
|
11
|
+
cd merb-words
|
12
|
+
sudo rake install
|
13
|
+
|
14
|
+
2.) Navigate to your merb application.
|
15
|
+
cd ~/your_merb_app/
|
16
|
+
|
17
|
+
3.) Add to your dependencies file.
|
18
|
+
vim config/dependencies.rb
|
19
|
+
a
|
20
|
+
|
21
|
+
dependency 'merb-words'
|
22
|
+
|
23
|
+
esc : wq
|
24
|
+
|
25
|
+
4.) Add options to your init file in the before_app_loads callback.
|
26
|
+
vim config/init.rb
|
27
|
+
a
|
28
|
+
|
29
|
+
Merb::BootLoader.before_app_loads do
|
30
|
+
Merb::Slices::config[:merb_words][:title] = 'Words' #Title of the index page and/or tab.
|
31
|
+
end
|
32
|
+
|
33
|
+
esc : wq
|
34
|
+
|
35
|
+
5.) Add to your router file.
|
36
|
+
vim config/router.rb
|
37
|
+
a
|
38
|
+
|
39
|
+
slice(:merb_words)
|
40
|
+
|
41
|
+
esc : wq
|
42
|
+
|
43
|
+
6.) Start your merb application and browse.
|
44
|
+
http://your_domain/photos
|
45
|
+
|
46
|
+
------------------------------------------------------------------------------
|
47
|
+
|
48
|
+
Advanced:
|
49
|
+
|
50
|
+
# List all available tasks:
|
51
|
+
rake -T slices:merb_words
|
52
|
+
|
53
|
+
# Put your application-level overrides in:
|
54
|
+
host-app/slices/merb-words/
|
55
|
+
|
56
|
+
# Templates are located in this order:
|
57
|
+
1. host-app/slices/merb-words/app/views/*
|
58
|
+
2. gems/merb-words/app/views/*
|
59
|
+
3. host-app/app/views/*
|
data/Rakefile
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
|
4
|
+
require 'merb-core'
|
5
|
+
require 'merb-core/tasks/merb'
|
6
|
+
|
7
|
+
GEM_NAME = "merb-words"
|
8
|
+
AUTHOR = "uipoet"
|
9
|
+
EMAIL = "dont.tase@me.com"
|
10
|
+
HOMEPAGE = "http://uipoet.com/"
|
11
|
+
SUMMARY = "Word management for Merb."
|
12
|
+
GEM_VERSION = "0.1"
|
13
|
+
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.rubyforge_project = "mui"
|
16
|
+
s.name = GEM_NAME
|
17
|
+
s.version = GEM_VERSION
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ["README", "LICENSE"]
|
21
|
+
s.summary = SUMMARY
|
22
|
+
s.description = s.summary
|
23
|
+
s.author = AUTHOR
|
24
|
+
s.email = EMAIL
|
25
|
+
s.homepage = HOMEPAGE
|
26
|
+
s.add_dependency('merb', '~> 1.0.0')
|
27
|
+
s.add_dependency('merb-ui', '>= 0.1')
|
28
|
+
s.require_path = 'lib'
|
29
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{lib,app,public}/**/*")
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
33
|
+
pkg.gem_spec = spec
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Install the gem"
|
37
|
+
task :install do
|
38
|
+
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Uninstall the gem"
|
42
|
+
task :uninstall do
|
43
|
+
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Release the gem to rubyforge"
|
47
|
+
task :release do
|
48
|
+
require 'rubyforge'
|
49
|
+
sh %{sudo rake package}
|
50
|
+
begin
|
51
|
+
sh %{rubyforge login}
|
52
|
+
sh %{rubyforge add_release #{AUTHOR} #{GEM_NAME} #{GEM_VERSION} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem}
|
53
|
+
rescue Exception => e
|
54
|
+
puts "Release failed: #{e.message}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "Create a gemspec file"
|
59
|
+
task :gemspec do
|
60
|
+
File.open("#{GEM_NAME}.gemspec", "w") do |file|
|
61
|
+
file.puts spec.to_ruby
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
require 'spec/rake/spectask'
|
66
|
+
require 'merb-core/test/tasks/spectasks'
|
67
|
+
desc 'Default: run spec examples'
|
68
|
+
task :default => 'spec'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class MerbWords::Categories < MerbWords::Application
|
2
|
+
|
3
|
+
before(:mui_window_referer, :only => [:create, :update, :delete])
|
4
|
+
|
5
|
+
def create
|
6
|
+
display(@category = Category.new, :layout => false)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_post
|
10
|
+
category = Category.new(params[:category])
|
11
|
+
if category.save
|
12
|
+
session[:mui_message] = {:title => 'Category created', :tone => 'positive'}
|
13
|
+
else
|
14
|
+
session[:mui_message] = {:title => 'Unable to create category', :body => mui_list(category.errors), :tone => 'negative'}
|
15
|
+
session[:mui_window] = slice_url(:category_create)
|
16
|
+
end
|
17
|
+
mui_window_redirect
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
display(@category = Category.get!(params[:category_id]), :layout => false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_put
|
25
|
+
category = Category.get!(params[:category_id])
|
26
|
+
if category.update_attributes(params[:category])
|
27
|
+
session[:mui_message] = {:title => 'Category updated', :tone => 'positive'}
|
28
|
+
else
|
29
|
+
session[:mui_message] = {:title => 'Unable to update category', :body => mui_list(category.errors), :tone => 'negative'}
|
30
|
+
session[:mui_window] = slice_url(:category_update)
|
31
|
+
end
|
32
|
+
mui_window_redirect
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete
|
36
|
+
display(@category = Category.get!(params[:category_id]), :layout => false)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete_delete
|
40
|
+
category = Category.get!(params[:category_id])
|
41
|
+
category.pages.clear
|
42
|
+
category.save
|
43
|
+
if category.destroy
|
44
|
+
session[:mui_message] = {:title => 'Category deleted', :tone => 'positive'}
|
45
|
+
else
|
46
|
+
session[:mui_message] = {:title => 'Unable to delete category', :body => mui_list(category.errors), :tone => 'negative'}
|
47
|
+
session[:mui_window] = slice_url(:category_delete)
|
48
|
+
end
|
49
|
+
mui_window_redirect
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
class MerbWords::Pages < MerbWords::Application
|
4
|
+
|
5
|
+
before(:mui_window_referer, :only => [:create, :update, :delete])
|
6
|
+
before(:merb_words_password_redirect, :exclude => [:index, :feed, :read], :unless => :merb_words_password?)
|
7
|
+
before(:merb_words_orders, :only => [:index])
|
8
|
+
|
9
|
+
def index
|
10
|
+
if Page.first
|
11
|
+
filters = {}
|
12
|
+
filters[:publish] = true unless merb_words_password?
|
13
|
+
@order_property = params[:order_property] || MerbWords[:order] || 'created_at'
|
14
|
+
if @order_property == 'title'
|
15
|
+
filters[:order] = [@order_property.intern.asc]
|
16
|
+
else
|
17
|
+
filters[:order] = [@order_property.intern.desc]
|
18
|
+
end
|
19
|
+
if search = params[:search] and !search.blank?
|
20
|
+
search = CGI.escape(search).to_a
|
21
|
+
if searches = session[:mui_searches]
|
22
|
+
session[:mui_searches] = searches | search
|
23
|
+
else
|
24
|
+
session[:mui_searches] = search
|
25
|
+
end
|
26
|
+
pages_title = Page.all(:title.like => "%#{search}%")
|
27
|
+
pages_body = Page.all(:body.like => "%#{search}%")
|
28
|
+
@pages = pages_title | pages_body
|
29
|
+
elsif @category_id = params[:category_id]
|
30
|
+
@pages = Category.get!(@category_id).pages(filters)
|
31
|
+
else
|
32
|
+
@pages = Page.all(filters)
|
33
|
+
end
|
34
|
+
@categories = Category.all(:order => [:title.asc])
|
35
|
+
@orders = Order.all
|
36
|
+
display @pages
|
37
|
+
else
|
38
|
+
session[:mui_message] = {:title => 'Create the first page'} if merb_words_password?
|
39
|
+
session[:mui_window] = slice_url(:create)
|
40
|
+
render
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def feed
|
45
|
+
only_provides :xml
|
46
|
+
display @pages = Page.all(:publish => true) if Page.first
|
47
|
+
end
|
48
|
+
|
49
|
+
def create
|
50
|
+
display(@page = Page.new, :layout => false)
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_post
|
54
|
+
params[:page][:categories].collect!{|c| Category[c]} if params[:page][:categories]
|
55
|
+
page = Page.new(params[:page])
|
56
|
+
if page.save
|
57
|
+
session[:mui_message] = {:title => 'Page created', :tone => 'positive'}
|
58
|
+
else
|
59
|
+
session[:mui_message] = {:title => 'Unable to create page', :body => mui_list(page.errors), :tone => 'negative'}
|
60
|
+
session[:mui_window] = slice_url(:create)
|
61
|
+
end
|
62
|
+
mui_window_redirect
|
63
|
+
end
|
64
|
+
|
65
|
+
def read
|
66
|
+
display @page = Page.get!(params[:page_id])
|
67
|
+
end
|
68
|
+
|
69
|
+
def update
|
70
|
+
display(@page = Page.get!(params[:page_id]), :layout => false)
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_put
|
74
|
+
page = Page.get!(params[:page_id])
|
75
|
+
page.categories.clear
|
76
|
+
page.save
|
77
|
+
params[:page][:categories].collect!{|c| Category[c]} if params[:page][:categories]
|
78
|
+
if page.update_attributes(params[:page])
|
79
|
+
session[:mui_message] = {:title => 'Page updated', :tone => 'positive'}
|
80
|
+
else
|
81
|
+
session[:mui_message] = {:title => 'Unable to update page', :body => mui_list(page.errors), :tone => 'negative'}
|
82
|
+
session[:mui_window] = slice_url(:create)
|
83
|
+
end
|
84
|
+
mui_window_redirect
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete
|
88
|
+
display(@page = Page.get!(params[:page_id]), :layout => false)
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete_delete
|
92
|
+
page = Page.get!(params[:page_id])
|
93
|
+
page.categories.clear
|
94
|
+
page.save
|
95
|
+
if page.destroy
|
96
|
+
session[:mui_message] = {:title => 'Page deleted', :tone => 'positive'}
|
97
|
+
else
|
98
|
+
session[:mui_message] = {:title => 'Unable to delete page', :body => mui_list(page.errors), :tone => 'negative'}
|
99
|
+
session[:mui_window] = slice_url(:delete)
|
100
|
+
end
|
101
|
+
redirect(slice_url(:index))
|
102
|
+
end
|
103
|
+
|
104
|
+
def search_delete
|
105
|
+
session[:mui_searches] = session[:mui_searches] - params[:search].to_a
|
106
|
+
redirect(slice_url(:index))
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
class MerbWords::Passwords < MerbWords::Application
|
2
|
+
|
3
|
+
before(:mui_window_referer, :only => [:exit, :create, :read, :update, :delete])
|
4
|
+
before(:merb_words_password_redirect, :exclude => [:exit, :create, :read], :unless => :merb_words_password?)
|
5
|
+
|
6
|
+
def exit
|
7
|
+
session.delete(:mui_password_id)
|
8
|
+
session[:mui_message] = {:title => 'Exited', :tone => 'positive'}
|
9
|
+
mui_window_redirect
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
display(@password = Password.new, :layout => false)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_post
|
17
|
+
password = Password.new(params[:password])
|
18
|
+
if password.save
|
19
|
+
session[:mui_password_id] = password.id
|
20
|
+
session[:mui_message] = {:title => 'Password created', :tone => 'positive'}
|
21
|
+
mui_window_redirect
|
22
|
+
else
|
23
|
+
session[:mui_message] = {:title => 'Unable to create password', :body => mui_list(password.errors), :tone => 'negative'}
|
24
|
+
session[:mui_window] = slice_url(:password_create)
|
25
|
+
mui_window_redirect
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def read
|
30
|
+
if Password.first
|
31
|
+
display(@password = Password.new, :layout => false)
|
32
|
+
else
|
33
|
+
redirect slice_url(:password_create)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_post
|
38
|
+
encrypted = encrypt(params[:password])
|
39
|
+
if password_match = Password.first(:encrypted => encrypted)
|
40
|
+
session[:mui_password_id] = password_match.id
|
41
|
+
session[:mui_message] = {:title => 'Password correct', :tone => 'positive'}
|
42
|
+
else
|
43
|
+
session[:mui_message] = {:title => 'Password incorrect', :tone => 'negative'}
|
44
|
+
session[:mui_window] = slice_url(:password_read)
|
45
|
+
end
|
46
|
+
mui_window_redirect
|
47
|
+
end
|
48
|
+
|
49
|
+
def update
|
50
|
+
display(@password = Password.new, :layout => false)
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_post
|
54
|
+
password = Password.get!(session[:mui_password_id])
|
55
|
+
if password.update_attributes(params[:password])
|
56
|
+
session[:mui_message] = {:title => 'Password updated', :tone => 'positive'}
|
57
|
+
else
|
58
|
+
session[:mui_message] = {:title => 'Unable to update password', :body => mui_list(password.errors), :tone => 'negative'}
|
59
|
+
session[:mui_window] = slice_url(:password_update)
|
60
|
+
end
|
61
|
+
mui_window_redirect
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete
|
65
|
+
render :layout => false
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_delete
|
69
|
+
password = Password.get!(session[:mui_password_id])
|
70
|
+
if password.destroy
|
71
|
+
session.delete(:mui_password_id)
|
72
|
+
session[:mui_message] = {:title => 'Password deleted', :tone => 'positive'}
|
73
|
+
mui_window_redirect
|
74
|
+
else
|
75
|
+
session[:mui_message] = {:title => 'Unable to delete password', :body => mui_list(password.errors), :tone => 'negative'}
|
76
|
+
session[:mui_window] = slice_url(:password_delete)
|
77
|
+
mui_window_redirect
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
|
83
|
+
require "digest/sha1"
|
84
|
+
|
85
|
+
def encrypt(password)
|
86
|
+
Digest::SHA1.hexdigest("--#{password[:password]}--")
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Merb::MerbWords::ApplicationHelper
|
2
|
+
|
3
|
+
def merb_words_categories(options = {})
|
4
|
+
attributes = {}
|
5
|
+
attributes[:class] = 'mui_menu'
|
6
|
+
attributes[:collection] = Category.all(:order => [:title.asc])
|
7
|
+
attributes[:label] = 'Categories'
|
8
|
+
attributes[:multiple] = 'multiple'
|
9
|
+
attributes[:selected] = options[:categories].all.map {|c| c.id}
|
10
|
+
attributes[:text_method] = :title
|
11
|
+
attributes[:value_method] = :id
|
12
|
+
select(:categories, attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
def merb_words_orders
|
16
|
+
unless Order.first
|
17
|
+
Order.create!(:property => 'created_at', :title => 'Date Created')
|
18
|
+
Order.create!(:property => 'updated_at', :title => 'Date Updated')
|
19
|
+
Order.create!(:property => 'title', :title => 'Title')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def merb_words_password?
|
24
|
+
session[:mui_password_id] ? true : false
|
25
|
+
end
|
26
|
+
|
27
|
+
def merb_words_password_redirect
|
28
|
+
if Password.first
|
29
|
+
redirect slice_url(:password_read)
|
30
|
+
else
|
31
|
+
redirect slice_url(:password_create)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def merb_words_password_status
|
36
|
+
if merb_words_password?
|
37
|
+
update = mui_button(:title => 'Update', :url => slice_url(:password_update), :window => 'open')
|
38
|
+
exit = mui_button(:title => 'Exit', :url => slice_url(:password_exit))
|
39
|
+
mui_block(:type => 'status'){%{Password: #{update} #{exit}}}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def merb_words_paragraph(body)
|
44
|
+
body.gsub(/\r\n|\r|\n/, '<br/>')
|
45
|
+
end
|
46
|
+
|
47
|
+
def merb_words_truncate(options = {})
|
48
|
+
characters = options[:characters] || 256
|
49
|
+
title = options[:title] || ' ...continued'
|
50
|
+
body = options[:body].gsub(/<\/?[^>]*>/, '')
|
51
|
+
body = body[0, characters] + tag(:span, title, :class => 'mui_truncate') if body.size > characters
|
52
|
+
merb_words_paragraph(body)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/app/models/order.rb
ADDED
data/app/models/page.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class Page
|
2
|
+
|
3
|
+
include DataMapper::Resource
|
4
|
+
|
5
|
+
property :id, Serial
|
6
|
+
property :title, String, :nullable => false
|
7
|
+
property :body, Text, :nullable => false
|
8
|
+
property :publish, Boolean, :default => false
|
9
|
+
property :created_at, Date
|
10
|
+
property :updated_at, Date
|
11
|
+
|
12
|
+
has n, :categories, :through => Resource
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Password
|
2
|
+
|
3
|
+
include DataMapper::Resource
|
4
|
+
include DataMapper::Validate
|
5
|
+
|
6
|
+
attr_accessor :password, :password_confirmation
|
7
|
+
|
8
|
+
property :id, Integer, :key => true, :serial => true
|
9
|
+
property :encrypted, String
|
10
|
+
|
11
|
+
validates_present(:password, :password_confirmation)
|
12
|
+
validates_length(:password, :within => 4..20)
|
13
|
+
validates_is_confirmed(:password, :groups => :create)
|
14
|
+
|
15
|
+
before :save, :encrypt
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
require "digest/sha1"
|
20
|
+
|
21
|
+
def encrypt
|
22
|
+
attribute_set(:encrypted, Digest::SHA1.hexdigest("--#{password}--"))
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%= mui_window(:title => 'Create Category') do %>
|
2
|
+
<%= mui_form(:category, :action => slice_url(:category_create)) do %>
|
3
|
+
<%= partial(:form) %>
|
4
|
+
<%= mui_block do %>
|
5
|
+
<%= mui_button(:title => 'Create', :submit => true, :tone => 'positive')%>
|
6
|
+
<% end =%>
|
7
|
+
<% end =%>
|
8
|
+
<% end =%>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%= mui_window(:title => 'Delete Category') do %>
|
2
|
+
<%= mui_block do %>Are you sure that you want to delete <%= @category.title %>?<% end =%>
|
3
|
+
<%= mui_block do %>
|
4
|
+
<%= mui_form(:category, :action => slice_url(:category_delete, :category_id => @category.id)) do %>
|
5
|
+
<%= mui_button(:title => 'Delete', :submit => true, :tone => 'negative') %>
|
6
|
+
<% end =%>
|
7
|
+
<% end =%>
|
8
|
+
<% end =%>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%= mui_window(:title => 'Update Category') do %>
|
2
|
+
<%= mui_form(:category, :action => slice_url(:category_update, :category_id => @category.id)) do %>
|
3
|
+
<%= partial(:form) %>
|
4
|
+
<%= mui_block do %>
|
5
|
+
<%= mui_button(:title => 'Update', :submit => true, :tone => 'positive')%>
|
6
|
+
<% end =%>
|
7
|
+
<% end =%>
|
8
|
+
<% end =%>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<%
|
2
|
+
attributes = {}
|
3
|
+
attributes[:order_property] = params[:order_property]
|
4
|
+
%>
|
5
|
+
<%= mui_divider %>
|
6
|
+
<%= mui_grid(:columns => 2) do %>
|
7
|
+
<%= mui_cell(:width => '100%') do %>
|
8
|
+
<%= mui_block(:title => 'Categories', :title_size => '1em') %>
|
9
|
+
<% end =%>
|
10
|
+
<% if merb_words_password? %>
|
11
|
+
<%= mui_cell(:align => 'right', :valign => 'bottom') do %>
|
12
|
+
<%= mui_button(:title => 'Create', :url => slice_url(:category_create), :window => 'open') %>
|
13
|
+
<% end =%>
|
14
|
+
<% end %>
|
15
|
+
<% end =%>
|
16
|
+
<% if category_id %>
|
17
|
+
<%= mui_link(:title => 'All', :title_size => '0.85em', :url => slice_url(:index, attributes)) %>
|
18
|
+
<% else %>
|
19
|
+
<span style="font-size:0.85em;">All</span>
|
20
|
+
<% end %>
|
21
|
+
<% if categories %>
|
22
|
+
<% categories.each do |category| %>
|
23
|
+
<%= mui_grid(:columns => 2, :width => '100%') do %>
|
24
|
+
<%= mui_cell do %>
|
25
|
+
<% if category_id.to_i == category.id %>
|
26
|
+
<span style="font-size:0.85em;"><%= category.title %></span>
|
27
|
+
<% else %>
|
28
|
+
<% attributes[:category_id] = category.id %>
|
29
|
+
<%= mui_link(:title => category.title, :title_size => '0.85em', :url => slice_url(:index, attributes)) %>
|
30
|
+
<% end %>
|
31
|
+
<% end =%>
|
32
|
+
<% if merb_words_password? %>
|
33
|
+
<%= mui_cell(:align => 'right', :wrap => false) do %>
|
34
|
+
|
35
|
+
<%= mui_button(:title => 'Update', :url => slice_url(:category_update, :category_id => category.id), :window => 'open') %>
|
36
|
+
<%= mui_button(:title => '×', :tone => 'negative', :url => slice_url(:category_delete, :category_id => category.id), :window => 'open') %>
|
37
|
+
<% end =%>
|
38
|
+
<% end %>
|
39
|
+
<% end =%>
|
40
|
+
<% end %>
|
41
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%= mui_grid(:columns => 2) do %>
|
2
|
+
<%= mui_cell do %>
|
3
|
+
<%= mui_block do %>
|
4
|
+
<%= mui_text(:title, :focus => true, :title => 'Title', :width => '23em') %>
|
5
|
+
<% end =%>
|
6
|
+
<% end =%>
|
7
|
+
<%= mui_cell do %>
|
8
|
+
<%= mui_block do %>
|
9
|
+
<%= mui_date(:created_at, :title => 'Date') %>
|
10
|
+
<% end =%>
|
11
|
+
<% end =%>
|
12
|
+
<% end =%>
|
13
|
+
<%= mui_grid(:columns => 2) do %>
|
14
|
+
<%= mui_cell do %>
|
15
|
+
<%= mui_block do %>
|
16
|
+
<%= mui_hyper_text(:body, :title => 'Body') %>
|
17
|
+
<% end =%>
|
18
|
+
<% end =%>
|
19
|
+
<% if Category.first %>
|
20
|
+
<%= mui_cell do %>
|
21
|
+
<%= mui_block do %>
|
22
|
+
<%= merb_words_categories(:categories => @page.categories) %>
|
23
|
+
<% end =%>
|
24
|
+
<% end =%>
|
25
|
+
<% end %>
|
26
|
+
<% end =%>
|
27
|
+
<%= mui_block do %>
|
28
|
+
<%= mui_check(:publish, :title => 'Publish') %>
|
29
|
+
<% end =%>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= mui_divider %>
|
2
|
+
<%= mui_block(:title => 'Sort by', :title_size => '1em') %>
|
3
|
+
<% orders.each do |order| %>
|
4
|
+
<div>
|
5
|
+
<% if order_property == order.property %>
|
6
|
+
<span style="font-size:0.85em;"><%= order.title %></span>
|
7
|
+
<% else %>
|
8
|
+
<%
|
9
|
+
attributes = {}
|
10
|
+
attributes[:category_id] = params[:category_id]
|
11
|
+
attributes[:order_property] = order.property
|
12
|
+
attributes[:search] = params[:search]
|
13
|
+
%>
|
14
|
+
<%= mui_link(:title => order.title, :title_size => '0.85em', :url => slice_url(:index, attributes)) %>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|