rhyhann-merb_stathyc_slice 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/LICENSE +21 -0
  2. data/README.markdown +106 -0
  3. data/Rakefile +55 -0
  4. data/TODO +5 -0
  5. data/app/controllers/application.rb +3 -0
  6. data/app/controllers/pages.rb +62 -0
  7. data/app/helpers/application_helper.rb +136 -0
  8. data/app/helpers/pages_helper.rb +49 -0
  9. data/app/models/page.rb +49 -0
  10. data/app/views/layout/static_slice.html.haml +27 -0
  11. data/app/views/pages/_cud.html.haml +11 -0
  12. data/app/views/pages/_sidebar.html.haml +2 -0
  13. data/app/views/pages/delete.html.haml +2 -0
  14. data/app/views/pages/edit.html.haml +6 -0
  15. data/app/views/pages/index.html.haml +5 -0
  16. data/app/views/pages/new.html.haml +6 -0
  17. data/app/views/pages/show.html.haml +5 -0
  18. data/lib/static_slice.rb +85 -0
  19. data/lib/static_slice/merbtasks.rb +103 -0
  20. data/lib/static_slice/slicetasks.rb +18 -0
  21. data/lib/static_slice/spectasks.rb +65 -0
  22. data/public/images/css/banner_mountains.jpg +0 -0
  23. data/public/images/css/bg.png +0 -0
  24. data/public/images/css/bg02-blue-left.png +0 -0
  25. data/public/images/css/bg02-blue-right.png +0 -0
  26. data/public/images/css/bg02-left.png +0 -0
  27. data/public/images/css/bg02-right.png +0 -0
  28. data/public/images/css/bg02-white-left.png +0 -0
  29. data/public/images/css/bg02-white-right.png +0 -0
  30. data/public/images/css/logo.png +0 -0
  31. data/public/images/css/menu.png +0 -0
  32. data/public/images/css/menuleft.png +0 -0
  33. data/public/images/css/menuright.png +0 -0
  34. data/public/stylesheets/master.css +138 -0
  35. data/spec/models/page_spec.rb +7 -0
  36. data/spec/requests/pages_spec.rb +110 -0
  37. data/spec/spec_helper.rb +43 -0
  38. data/spec/static_slice_spec.rb +19 -0
  39. data/stubs/app/controllers/application.rb +2 -0
  40. data/stubs/app/controllers/main.rb +2 -0
  41. metadata +118 -0
@@ -0,0 +1,49 @@
1
+ class Page
2
+ include DataMapper::Resource
3
+ property :id, Serial
4
+ property :name, String
5
+ property :description, Text
6
+ property :content, Text
7
+ validates_is_unique :name
8
+ validates_present :name
9
+ validates_present :description
10
+ validates_present :content
11
+ def self.sexhy
12
+ {
13
+ :properties => {
14
+ :name => {
15
+ :input => :text_field,
16
+ :label => 'Nom',
17
+ :order => 1
18
+ },
19
+ :description => {
20
+ :input => :text_area,
21
+ :label => 'Description',
22
+ :order => 2
23
+ },
24
+ :content => {
25
+ :input => :text_area,
26
+ :label => 'Contenu',
27
+ :order => 3
28
+ },
29
+ },
30
+ :html => {
31
+ :input => {
32
+ :tag => :p,
33
+ :attributes => {
34
+ :class => 'sexhy_p'
35
+ },
36
+ },
37
+ :label => {
38
+ :tag => :label,
39
+ :attributes => {
40
+ :class => 'sexhy_label',
41
+ },
42
+ },
43
+ },
44
+ }
45
+ end
46
+ def self.form_definition
47
+
48
+ end
49
+ end
@@ -0,0 +1,27 @@
1
+ !!! XML
2
+ !!! Strict
3
+ %html{ html_attrs('fr') }
4
+ %head
5
+ %title
6
+ Web Design Victoria BC
7
+ %meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-Type" }/
8
+ = css_include_tag 'master'
9
+ %body
10
+ #menu-top
11
+ %ul
12
+ %li= link_to "Index", url(:pages)
13
+ = partial 'pages/sidebar', :with => Page.all
14
+ #wrapper-header
15
+ #header
16
+ #wrapper-header2
17
+ #wrapper-header3
18
+ %h1= @page.nil? ? "Static Pages" : @page.name
19
+ #wrapper-content
20
+ #wrapper-menu-page
21
+ #menu-page
22
+ = catch_content :for_cud
23
+ #content
24
+ %p= catch_content :for_layout
25
+ #wrapper-footer
26
+ #footer
27
+ %p= link_to "Design by 7designs", "http://studio7designs.com/"
@@ -0,0 +1,11 @@
1
+ - throw_content :for_cud do
2
+ / TODO: Generation Error
3
+ - if @new_thrown.nil?
4
+ %h3= link_to 'New', url(:new_page)
5
+ - @new_thrown = true
6
+ = catch_content :for_cud
7
+ %h3= cud.name
8
+ %ul
9
+ %li= link_to 'Show', url(:page, cud)
10
+ %li= link_to 'Edit', url(:edit_page, cud)
11
+ %li= delete_button cud
@@ -0,0 +1,2 @@
1
+ %li
2
+ %span= link_to sidebar.name, url(:page, sidebar)
@@ -0,0 +1,2 @@
1
+ %h1 Do you really want to delete this ?
2
+ = render :show, :layout => false
@@ -0,0 +1,6 @@
1
+ = error_messages_for :page
2
+ = form_for(@page, :action => url(:page, @page)) do
3
+ %p
4
+ = sexify @page
5
+ = submit "Update"
6
+ = partial 'cud', :with => @page
@@ -0,0 +1,5 @@
1
+ - for page in @pages
2
+ %h3= page.name
3
+ %p= page.description
4
+ %p= page.content
5
+ = partial 'cud', :with => @pages
@@ -0,0 +1,6 @@
1
+ = error_messages_for :page
2
+ = form_for(@page, :action => url(:pages) ) do
3
+ %p
4
+ = sexify @page
5
+ = submit "Create"
6
+ = partial 'cud', :with => @page
@@ -0,0 +1,5 @@
1
+ #something
2
+ %h3= @page.name
3
+ %p= @page.description
4
+ %p= @page.content
5
+ = partial 'cud', :with => @page
@@ -0,0 +1,85 @@
1
+ if defined?(Merb::Plugins)
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ load_dependency 'merb-slices'
6
+ Merb::Plugins.add_rakefiles "static_slice/merbtasks", "static_slice/slicetasks", "static_slice/spectasks"
7
+
8
+ # Register the Slice for the current host application
9
+ Merb::Slices::register(__FILE__)
10
+
11
+ # Slice configuration - set this in a before_app_loads callback.
12
+ # By default a Slice uses its own layout, so you can swicht to
13
+ # the main application layout or no layout at all if needed.
14
+ #
15
+ # Configuration options:
16
+ # :layout - the layout to use; defaults to :static_slice
17
+ # :mirror - which path component types to use on copy operations; defaults to all
18
+ Merb::Slices::config[:static_slice][:layout] ||= :static_slice
19
+
20
+ # All Slice code is expected to be namespaced inside a module
21
+ module StaticSlice
22
+
23
+ # Slice metadata
24
+ self.description = "StathycSlice provides core static pages functionnalities, with CUD operations separated, so you can easily protect your app."
25
+ self.version = "0.1"
26
+ self.author = "(rhyhann, Othmane Benkirane)"
27
+
28
+ # Stub classes loaded hook - runs before LoadClasses BootLoader
29
+ # right after a slice's classes have been loaded internally.
30
+ def self.loaded
31
+ end
32
+
33
+ # Initialization hook - runs before AfterAppLoads BootLoader
34
+ def self.init
35
+ end
36
+
37
+ # Activation hook - runs after AfterAppLoads BootLoader
38
+ def self.activate
39
+ end
40
+
41
+ # Deactivation hook - triggered by Merb::Slices.deactivate(StaticSlice)
42
+ def self.deactivate
43
+ end
44
+
45
+ # Setup routes inside the host application
46
+ #
47
+ # @param scope<Merb::Router::Behaviour>
48
+ # Routes will be added within this scope (namespace). In fact, any
49
+ # router behaviour is a valid namespace, so you can attach
50
+ # routes at any level of your router setup.
51
+ #
52
+ # @note prefix your named routes with :static_slice_
53
+ # to avoid potential conflicts with global named routes.
54
+ def self.setup_router(scope)
55
+ # example of a named route
56
+
57
+ scope.resources :pages
58
+ # http://eo:4000/pages
59
+ scope.match('/index(.:format)').to(:controller => 'pages', :action => 'index').name(:index)
60
+ # the slice is mounted at /static_slice - note that it comes before default_routes
61
+ scope.match('/').to(:controller => 'pages', :action => 'index').name(:home)
62
+ # enable slice-level default routes by default
63
+ scope.default_routes
64
+ end
65
+
66
+ end
67
+
68
+ # Setup the slice layout for StaticSlice
69
+ #
70
+ # Use StaticSlice.push_path and StaticSlice.push_app_path
71
+ # to set paths to static_slice-level and app-level paths. Example:
72
+ #
73
+ # StaticSlice.push_path(:application, StaticSlice.root)
74
+ # StaticSlice.push_app_path(:application, Merb.root / 'slices' / 'static_slice')
75
+ # ...
76
+ #
77
+ # Any component path that hasn't been set will default to StaticSlice.root
78
+ #
79
+ # Or just call setup_default_structure! to setup a basic Merb MVC structure.
80
+ StaticSlice.setup_default_structure!
81
+
82
+ # Add dependencies for other StaticSlice classes below. Example:
83
+ # dependency "static_slice/other"
84
+
85
+ end
@@ -0,0 +1,103 @@
1
+ namespace :slices do
2
+ namespace :static_slice do
3
+
4
+ desc "Install StaticSlice"
5
+ task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
6
+
7
+ desc "Test for any dependencies"
8
+ task :preflight do # see slicetasks.rb
9
+ end
10
+
11
+ desc "Setup directories"
12
+ task :setup_directories do
13
+ puts "Creating directories for host application"
14
+ StaticSlice.mirrored_components.each do |type|
15
+ if File.directory?(StaticSlice.dir_for(type))
16
+ if !File.directory?(dst_path = StaticSlice.app_dir_for(type))
17
+ relative_path = dst_path.relative_path_from(Merb.root)
18
+ puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
19
+ mkdir_p(dst_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "Copy stub files to host application"
26
+ task :stubs do
27
+ puts "Copying stubs for StaticSlice - resolves any collisions"
28
+ copied, preserved = StaticSlice.mirror_stubs!
29
+ puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ copied.each { |f| puts "- copied #{f}" }
31
+ preserved.each { |f| puts "! preserved override as #{f}" }
32
+ end
33
+
34
+ desc "Copy stub files and views to host application"
35
+ task :patch => [ "stubs", "freeze:views" ]
36
+
37
+ desc "Copy public assets to host application"
38
+ task :copy_assets do
39
+ puts "Copying assets for StaticSlice - resolves any collisions"
40
+ copied, preserved = StaticSlice.mirror_public!
41
+ puts "- no files to copy" if copied.empty? && preserved.empty?
42
+ copied.each { |f| puts "- copied #{f}" }
43
+ preserved.each { |f| puts "! preserved override as #{f}" }
44
+ end
45
+
46
+ desc "Migrate the database"
47
+ task :migrate do # see slicetasks.rb
48
+ end
49
+
50
+ desc "Freeze StaticSlice into your app (only static_slice/app)"
51
+ task :freeze => [ "freeze:app" ]
52
+
53
+ namespace :freeze do
54
+
55
+ desc "Freezes StaticSlice by installing the gem into application/gems"
56
+ task :gem do
57
+ ENV["GEM"] ||= "static_slice"
58
+ Rake::Task['slices:install_as_gem'].invoke
59
+ end
60
+
61
+ desc "Freezes StaticSlice by copying all files from static_slice/app to your application"
62
+ task :app do
63
+ puts "Copying all static_slice/app files to your application - resolves any collisions"
64
+ copied, preserved = StaticSlice.mirror_app!
65
+ puts "- no files to copy" if copied.empty? && preserved.empty?
66
+ copied.each { |f| puts "- copied #{f}" }
67
+ preserved.each { |f| puts "! preserved override as #{f}" }
68
+ end
69
+
70
+ desc "Freeze all views into your application for easy modification"
71
+ task :views do
72
+ puts "Copying all view templates to your application - resolves any collisions"
73
+ copied, preserved = StaticSlice.mirror_files_for :view
74
+ puts "- no files to copy" if copied.empty? && preserved.empty?
75
+ copied.each { |f| puts "- copied #{f}" }
76
+ preserved.each { |f| puts "! preserved override as #{f}" }
77
+ end
78
+
79
+ desc "Freeze all models into your application for easy modification"
80
+ task :models do
81
+ puts "Copying all models to your application - resolves any collisions"
82
+ copied, preserved = StaticSlice.mirror_files_for :model
83
+ puts "- no files to copy" if copied.empty? && preserved.empty?
84
+ copied.each { |f| puts "- copied #{f}" }
85
+ preserved.each { |f| puts "! preserved override as #{f}" }
86
+ end
87
+
88
+ desc "Freezes StaticSlice as a gem and copies over static_slice/app"
89
+ task :app_with_gem => [:gem, :app]
90
+
91
+ desc "Freezes StaticSlice by unpacking all files into your application"
92
+ task :unpack do
93
+ puts "Unpacking StaticSlice files to your application - resolves any collisions"
94
+ copied, preserved = StaticSlice.unpack_slice!
95
+ puts "- no files to copy" if copied.empty? && preserved.empty?
96
+ copied.each { |f| puts "- copied #{f}" }
97
+ preserved.each { |f| puts "! preserved override as #{f}" }
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,18 @@
1
+ namespace :slices do
2
+ namespace :static_slice do
3
+
4
+ # add your own static_slice tasks here
5
+
6
+ # implement this to test for structural/code dependencies
7
+ # like certain directories or availability of other files
8
+ desc "Test for any dependencies"
9
+ task :preflight do
10
+ end
11
+
12
+ # implement this to perform any database related setup steps
13
+ desc "Migrate the database"
14
+ task :migrate do
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,65 @@
1
+ namespace :slices do
2
+ namespace :static_slice do
3
+
4
+ desc "Run slice specs within the host application context"
5
+ task :spec => [ "spec:explain", "spec:default" ]
6
+
7
+ namespace :spec do
8
+
9
+ slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
+
11
+ task :explain do
12
+ puts "\nNote: By running StaticSlice specs inside the application context any\n" +
13
+ "overrides could break existing specs. This isn't always a problem,\n" +
14
+ "especially in the case of views. Use these spec tasks to check how\n" +
15
+ "well your application conforms to the original slice implementation."
16
+ end
17
+
18
+ Spec::Rake::SpecTask.new('default') do |t|
19
+ t.spec_opts = ["--format", "specdoc", "--colour"]
20
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
21
+ end
22
+
23
+ desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
24
+ Spec::Rake::SpecTask.new('model') do |t|
25
+ t.spec_opts = ["--format", "specdoc", "--colour"]
26
+ if(ENV['MODEL'])
27
+ t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
28
+ else
29
+ t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
30
+ end
31
+ end
32
+
33
+ desc "Run all controller specs, run a spec for a specific Controller with CONTROLLER=MyController"
34
+ Spec::Rake::SpecTask.new('controller') do |t|
35
+ t.spec_opts = ["--format", "specdoc", "--colour"]
36
+ if(ENV['CONTROLLER'])
37
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/#{ENV['CONTROLLER']}_spec.rb"].sort
38
+ else
39
+ t.spec_files = Dir["#{slice_root}/spec/controllers/**/*_spec.rb"].sort
40
+ end
41
+ end
42
+
43
+ desc "Run all view specs, run specs for a specific controller (and view) with CONTROLLER=MyController (VIEW=MyView)"
44
+ Spec::Rake::SpecTask.new('view') do |t|
45
+ t.spec_opts = ["--format", "specdoc", "--colour"]
46
+ if(ENV['CONTROLLER'] and ENV['VIEW'])
47
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/#{ENV['VIEW']}*_spec.rb"].sort
48
+ elsif(ENV['CONTROLLER'])
49
+ t.spec_files = Dir["#{slice_root}/spec/views/**/#{ENV['CONTROLLER']}/*_spec.rb"].sort
50
+ else
51
+ t.spec_files = Dir["#{slice_root}/spec/views/**/*_spec.rb"].sort
52
+ end
53
+ end
54
+
55
+ desc "Run all specs and output the result in html"
56
+ Spec::Rake::SpecTask.new('html') do |t|
57
+ t.spec_opts = ["--format", "html"]
58
+ t.libs = ['lib', 'server/lib' ]
59
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,138 @@
1
+ /* Css originally by mejobloggs Design by Aran @ stuio7designs.com Please email me if you use this, as I would love to see how it is being used, also you can join my linkshare to help you with your google ranking */
2
+
3
+ body {
4
+ font-family: trebuchet ms, verdana, arial, tahoma;
5
+ font-size: 90%;
6
+ color: #888;
7
+ background-color: white;
8
+ line-height: 180%;
9
+ margin: 0;
10
+ padding: 0;
11
+ text-align: center;
12
+ }
13
+
14
+ /* Set the page width here */
15
+ #menu-top, #header, #wrapper-content, #wrapper-footer {
16
+ width: 85%;
17
+ margin: 0 auto;
18
+ text-align: left;
19
+ }
20
+
21
+ #menu-top {
22
+ background: white url('/images/css/bg02-white-right.png') no-repeat right top;
23
+ overflow: hidden;
24
+ }
25
+
26
+ #menu-top ul {
27
+ background: transparent url('/images/css/bg02-white-left.png') no-repeat left top;
28
+ margin:0;
29
+ padding: 1em 0 0 0;
30
+ list-style: none;
31
+ font-size: 85%;
32
+ float: left;
33
+ padding-left: 20px;
34
+ }
35
+
36
+ #menu-top li {
37
+ display: inline;
38
+ float: left;
39
+ }
40
+
41
+ #menu-top a {
42
+ float: left;
43
+ background:url(/images/css/menuleft.png) no-repeat left top;
44
+ margin:0;
45
+ padding:0 0 0 4px;
46
+ text-decoration:none;
47
+ line-height: 1.5em;
48
+ }
49
+
50
+ #menu-top a span {
51
+ background: transparent url(/images/css/menuright.png) no-repeat right top;
52
+ padding:5px 15px 4px 6px;
53
+ color:#5b8fbe;
54
+ display: block;
55
+ float: left;
56
+ cursor: pointer; /* IE doesnt display the hand when you roll over the link for some reason. This fixes it */
57
+ }
58
+
59
+ #menu-top a:hover { background-position:0% -42px; }
60
+ #menu-top a:hover span { background-position:100% -42px; }
61
+
62
+ #wrapper-header { background: transparent url('/images/css/bg.png') top center repeat-x; }
63
+
64
+ #header { background: #eee url('/images/css/banner_mountains.jpg') no-repeat center top; }
65
+
66
+ #wrapper-header2 { background: transparent url('/images/css/bg02-blue-left.png') top left no-repeat; }
67
+
68
+ #wrapper-header3 { background: transparent url('/images/css/bg02-blue-right.png') top right no-repeat; }
69
+
70
+ #header h1 {
71
+ margin: 0 20px;
72
+ padding: 0;
73
+ height: 192px;
74
+ line-height: 3em;
75
+ color: #ccc;
76
+ font-size: 130%;
77
+ }
78
+
79
+ #wrapper-content { background: white url('/images/css/bg02-white-left.png') no-repeat left top; }
80
+
81
+ * html #wrapper-content { height: 1%; }
82
+
83
+ #content {
84
+ background: transparent url('/images/css/bg02-white-right.png') no-repeat right top;
85
+ padding: 5px 245px 5px 40px;
86
+ }
87
+
88
+ #wrapper-menu-page {
89
+ float: right;
90
+ width:180px;
91
+ margin: 20px 30px 3em 2em;
92
+ background: transparent url('/images/css/menu.png') no-repeat;
93
+ text-align: center;
94
+ line-height: 140%;
95
+ font-family:"Lucida Grande","Lucida Sans Unicode",arial,sans-serif;
96
+ }
97
+
98
+ * html #wrapper-menu-page { margin-right: 15px; }
99
+
100
+ #menu-page { padding-top: 5px; }
101
+
102
+ #menu-page ul {
103
+ margin: 0;
104
+ padding: 0;
105
+ list-style: none;
106
+ font-size: 90%;
107
+ }
108
+
109
+ #menu-page h3 {
110
+ font-size: 75%;
111
+ text-transform: uppercase;
112
+ margin: 1em 0 0.3em 0;
113
+ color: #5b8fbe;
114
+ font-weight: normal;
115
+ letter-spacing: 0.15em;
116
+ }
117
+
118
+ #menu-page a:link, #menu-page a:visited { color: #888; }
119
+ #menu-page a:hover { color: #5b8fbe; }
120
+
121
+ #wrapper-footer {
122
+ margin-top: 1em;
123
+ text-align: center;
124
+ }
125
+
126
+ #footer {
127
+ margin: 0 20px;
128
+ background-color: #e5f0fc;
129
+ border: 1px solid #ccc;
130
+ border-bottom: 0;
131
+ clear: both;
132
+ }
133
+
134
+ h2 { font-size: 110%; }
135
+ h3 { font-size: 100%; }
136
+
137
+ a:link, a:visited { color: #5b8fbe; text-decoration: none; }
138
+ a:hover{ color: #666; text-decoration: none; }