fesplugas (owner)

Revisions

gist: 86613 Download_button fork
public
Description:
Typus application example.
Public Clone URL: git://gist.github.com/86613.git
Embed All Files: show embed
typus_demo.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
##
# $ rails example.com -m http://tr.im/typus_example
##
 
# Install Typus and friends.
 
plugin 'typus', :git => 'git://github.com/fesplugas/typus.git'
plugin 'acts_as_list', :git => 'git://github.com/rails/acts_as_list.git'
plugin 'acts_as_tree', :git => 'git://github.com/rails/acts_as_tree.git'
plugin 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git'
 
# Gems
 
gem "formtastic", :source => "http://gemcutter.org/"
 
# Run generators.
 
generate("scaffold",
         "Asset asset_file_name:string asset_content_type:string asset_file_size:integer asset_updated_at:datetime",
         "--skip-timestamps")
generate("scaffold",
        "Category name:string parent_id:integer",
        "--skip-timestamps")
generate("scaffold",
         "Page title:string body:text published:boolean position:integer",
         "--skip-timestamps")
generate("scaffold",
         "Post title:string body:text published:boolean category_id:integer",
         "--skip-timestamps")
 
# Define models.
 
file 'app/models/asset.rb', <<-CODE
class Asset < ActiveRecord::Base
 
has_attached_file :asset, :styles => { :typus_preview => "692x461>", :typus_thumbnail => "100x100>" }
validates_attachment_presence :asset
 
end
CODE
 
file 'app/models/category.rb', <<-CODE
class Category < ActiveRecord::Base
 
validates_presence_of :name
has_many :posts
 
end
CODE
 
file 'app/models/page.rb', <<-CODE
class Page < ActiveRecord::Base
 
acts_as_list
 
validates_presence_of :title
 
end
CODE
 
file 'app/models/post.rb', <<-CODE
class Post < ActiveRecord::Base
validates_presence_of :title
belongs_to :category
 
def typus_name
title
end
 
end
CODE
 
# Run the migrations and set the routes.
 
rake 'db:migrate'
run "rm public/index.html"
route "map.root :controller => 'posts'"
 
# Run the Typus generator and migrate.
 
generate 'typus'
rake 'db:migrate'
 
# This file is used as a hack to avoid the detection of children and
# parent relationships.
 
file 'app/models/category.rb', <<-CODE
class Category < ActiveRecord::Base
 
acts_as_tree :order => 'name'
 
validates_presence_of :name
has_many :posts
 
end
CODE