manifest-rails 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README.rdoc +3 -0
  3. data/app/assets/javascripts/manifest/main.js +17 -0
  4. data/app/assets/stylesheets/manifest/_forms.css.scss +42 -21
  5. data/app/assets/stylesheets/manifest/_tables.css.scss +24 -20
  6. data/app/assets/stylesheets/manifest/main.css.scss +72 -0
  7. data/app/assets/stylesheets/manifest/sessions.css.scss +9 -0
  8. data/app/controllers/manifest/content_blocks_controller.rb +14 -11
  9. data/app/controllers/manifest/manifest_controller.rb +3 -8
  10. data/app/controllers/manifest/pages_controller.rb +2 -5
  11. data/app/controllers/manifest/sessions_controller.rb +1 -1
  12. data/app/controllers/pages_controller.rb +1 -8
  13. data/app/form_builders/manifest/labelled_form_builder.rb +23 -0
  14. data/app/models/content_block.rb +6 -2
  15. data/app/models/page.rb +18 -13
  16. data/app/views/layouts/manifest/manifest.html.erb +19 -18
  17. data/app/views/layouts/manifest/sessions.html.erb +10 -7
  18. data/app/views/manifest/content_blocks/_form.html.erb +24 -26
  19. data/app/views/manifest/content_blocks/edit.html.erb +1 -9
  20. data/app/views/manifest/content_blocks/index.html.erb +14 -14
  21. data/app/views/manifest/content_blocks/new.html.erb +1 -1
  22. data/app/views/manifest/pages/_form.html.erb +9 -10
  23. data/app/views/manifest/pages/edit.html.erb +1 -9
  24. data/app/views/manifest/pages/index.html.erb +5 -3
  25. data/app/views/manifest/pages/new.html.erb +1 -1
  26. data/app/views/manifest/pages/show.html.erb +29 -6
  27. data/config/initializers/manifest.rb +1 -1
  28. data/config/routes.rb +1 -1
  29. data/db/migrate/20120303200114_create_pages.rb +10 -0
  30. data/db/migrate/20120304152605_create_content_blocks.rb +13 -0
  31. data/db/migrate/20120304155055_add_index_to_pages.rb +5 -0
  32. data/db/migrate/20120304155130_add_index_to_content_blocks.rb +5 -0
  33. data/db/migrate/20120305164036_create_editors.rb +11 -0
  34. data/lib/active_record/base/data_type_for_manifest.rb +11 -0
  35. data/lib/generators/manifest/data_type/data_type_generator.rb +13 -2
  36. data/lib/generators/manifest/data_type/templates/_form.html.erb +19 -0
  37. data/lib/generators/manifest/data_type/templates/controller.rb +41 -4
  38. data/lib/generators/manifest/data_type/templates/edit.html.erb +3 -0
  39. data/lib/generators/manifest/data_type/templates/index.html.erb +4 -0
  40. data/lib/generators/manifest/data_type/templates/model.rb +1 -1
  41. data/lib/generators/manifest/data_type/templates/new.html.erb +3 -0
  42. data/lib/generators/manifest/install/USAGE +1 -3
  43. data/lib/generators/manifest/install/install_generator.rb +13 -4
  44. data/lib/generators/manifest/install/templates/create_content_blocks.rb +1 -1
  45. data/lib/generators/manifest/install/templates/create_pages.rb +1 -1
  46. data/lib/manifest.rb +4 -9
  47. data/lib/manifest/engine.rb +0 -3
  48. data/lib/manifest/version.rb +1 -1
  49. metadata +54 -115
  50. data/README.md +0 -37
  51. data/app/assets/images/manifest/grid.png +0 -0
  52. data/app/assets/images/manifest/sketch.png +0 -0
  53. data/app/assets/javascripts/manifest/manifest.js +0 -7
  54. data/app/assets/stylesheets/manifest/_mixins.css.scss +0 -41
  55. data/app/assets/stylesheets/manifest/manifest.css.scss +0 -137
  56. data/app/controllers/manifest/editors_controller.rb +0 -3
  57. data/app/models/user.rb +0 -8
  58. data/lib/active_record/base/acts_as_manifest.rb +0 -8
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2012 Jonathan Clem
1
+ Copyright 2012 YOURNAME
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Manifest
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,17 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require tinymce-jquery
4
+
5
+ $(function() {
6
+ $('.tinymce').tinymce({});
7
+
8
+ $('#content_block_allow_html').change(function() {
9
+ if ($(this).is(':checked')) {
10
+ $('#content_block_content').tinymce({});
11
+ } else {
12
+ $('#content_block_content_container').remove();
13
+ $('#content_block_content').css('display', 'inline-block');
14
+ $('#content_block_content').attr('aria-hidden', 'false');
15
+ }
16
+ })
17
+ })
@@ -1,34 +1,55 @@
1
- input[type='text'], input[type='password'], textarea {
2
- padding: 10px 10px;
3
- @include border-radius(4px);
4
- border: 1px solid #aaa;
5
- background: #f8f8f8;
6
- @include box-shadow(0 1px 1px rgba(0, 0, 0, 0.2) inset);
1
+ label {
2
+ display: block;
3
+ margin-bottom: $base / 4;
7
4
  }
8
5
 
9
- label {
10
- margin-bottom: 10px;
11
- display: block;
6
+ input[type='text'],
7
+ input[type='password'],
8
+ textarea {
9
+ width: $base * 14;
12
10
  font-size: inherit;
11
+ border: 1px solid #ccc;
12
+ height: $base;
13
+ padding: $base / 4;
14
+ @include box-shadow(0 1px 1px rgba(0,0,0,0.1) inset, 0 1px 0 white);
13
15
  }
14
16
 
15
- textarea { line-height: 1.428571429; }
16
-
17
- input[type='submit'] {
18
- @include pretty_button;
19
- font-size: 1em;
17
+ textarea {
18
+ height: $base * 10;
20
19
  }
21
20
 
22
21
  .field {
23
- margin-bottom: 20px;
24
- }
22
+ margin-bottom: $base;
23
+
24
+ &.inline-label {
25
+ label {
26
+ display: inline;
27
+ margin-right: $base / 2;
25
28
 
26
- .inline-label {
27
- label {
28
- margin-right: 20px;
29
- display: inline;
29
+ &:after { content: ':'; }
30
+ }
30
31
  }
31
32
  }
32
33
 
33
- .actions { margin-top: 20px; }
34
+ .form-actions {
35
+ margin-top: $base;
36
+ }
37
+
38
+ .form-errors {
39
+ width: $base * 16;
40
+ margin-bottom: $base;
41
+ padding: $base;
42
+ padding-left: $base * 2;
43
+ background: #fcc;
44
+ border: 1px solid #faa;
45
+ @include box-shadow(0 1px 1px rgba(0,0,0,0.1));
34
46
 
47
+ h3 { font: 150% 'Oswald'; }
48
+ p { font-style: italic; }
49
+ li { position: relative; }
50
+ li:before {
51
+ content: '\279b';
52
+ position: absolute;
53
+ left: -24px;
54
+ }
55
+ }
@@ -1,26 +1,30 @@
1
- table.resource_table {
2
- width: 100%;
3
-
4
- thead {
5
- background: #346;
6
- @include background(linear-gradient(#346, #346 - 25));
7
- color: $copy-on-dark;
8
- }
1
+ thead {
2
+ border: 1px solid darken(#36c, 13.5);
3
+ border-bottom: none;
4
+ }
5
+
6
+ th, td {
7
+ padding: $base / 4 $base / 2;
8
+ }
9
9
 
10
- th, td {
11
- padding: 10px 20px;
12
- }
10
+ th {
11
+ background: #36c;
12
+ @include background(linear-gradient(#36c, darken(#36c, 6.75)));
13
+ @include box-shadow(0 -1px 0 darken(#36c, 27) inset);
14
+ color: #fff;
15
+ }
13
16
 
14
- tbody tr:nth-child(even) {
15
- background: #ccc;
16
- }
17
+ tr:first-child td { @include box-shadow(0 1px 0 #f8f8f8 inset); }
17
18
 
18
- tbody tr:hover {
19
- background: $accent + 25;
20
- cursor: pointer;
21
- color: $copy-on-dark;
19
+ tr:nth-child(odd) {
20
+ background: #e8e8e8;
21
+ }
22
22
 
23
- a { color: $copy-on-dark; }
24
- }
23
+ tr:nth-child(even) {
24
+ background: #fff;
25
25
  }
26
26
 
27
+ tbody {
28
+ border: 1px solid #ccc;
29
+ border-top: none;
30
+ }
@@ -0,0 +1,72 @@
1
+ @import 'compass/reset';
2
+ @import 'compass/css3';
3
+
4
+ $base: 22.856px;
5
+ $accent: #36c;
6
+
7
+ body {
8
+ background: #f8f8f8;
9
+ font: 100%/1.4285 'PT Sans';
10
+ }
11
+
12
+ h1, h2 {
13
+ margin-bottom: $base;
14
+ font: 200% 'Oswald';
15
+ text-transform: uppercase;
16
+ }
17
+
18
+ h1 {
19
+ padding-bottom: $base;
20
+ border-bottom: 1px solid #999;
21
+ font: 200% 'Oswald';
22
+ text-align: center;
23
+ text-transform: uppercase;
24
+
25
+ /* &:after { content: ':'; } */
26
+ }
27
+
28
+ p {
29
+ margin-bottom: 16px;
30
+ &:last-child { margin-bottom: 0; }
31
+ }
32
+
33
+ a { color: $accent; }
34
+
35
+ strong, label { font-weight: bold; }
36
+
37
+ .app-nav {
38
+ width: $base * 8;
39
+ position: fixed;
40
+ top: 0; bottom: 0;
41
+ padding: $base * 2 $base;
42
+ background: #fcfcfc;
43
+ border-right: 1px solid #ccc;
44
+ @include box-shadow(1px 0 1px rgba(0, 0, 0, 0.1));
45
+ }
46
+
47
+ .app-nav nav {
48
+ padding-bottom: $base;
49
+ border-bottom: 1px solid #999;
50
+
51
+ a {
52
+ display: block;
53
+ text-decoration: none;
54
+ }
55
+
56
+ a:before {
57
+ content: '\279b';
58
+ margin-right: 0.5em;
59
+ }
60
+ }
61
+
62
+ .app-content {
63
+ margin-left: $base * 10;
64
+ padding: $base * 2 $base;
65
+ }
66
+
67
+ .model-actions {
68
+ margin-top: $base;
69
+ }
70
+
71
+ @import 'forms';
72
+ @import 'tables';
@@ -0,0 +1,9 @@
1
+ @import 'compass/reset';
2
+
3
+ $base: 22.856px;
4
+ $accent: #36c;
5
+
6
+ body {
7
+ background: #f8f8f8;
8
+ font: 100%/1.4285 'PT Sans';
9
+ }
@@ -1,22 +1,18 @@
1
1
  class Manifest::ContentBlocksController < Manifest::ManifestController
2
- before_filter :authorize
3
2
  before_filter :authorize_admin, except: [:index, :edit, :update]
4
3
 
5
- layout 'manifest/manifest'
6
-
7
4
  def index
8
5
  @content_blocks = ContentBlock.all
9
6
  end
10
7
 
11
8
  def new
12
- @content_block = ContentBlock.new
9
+ @content_block = ContentBlock.new(content_block_params)
13
10
  end
14
11
 
15
12
  def create
16
- @content_block = ContentBlock.new(params[:content_block])
13
+ @content_block = ContentBlock.new(content_block_params)
17
14
 
18
15
  if @content_block.save
19
- expire_all_pages
20
16
  redirect_to manifest_content_blocks_path
21
17
  else
22
18
  render 'new'
@@ -30,8 +26,7 @@ class Manifest::ContentBlocksController < Manifest::ManifestController
30
26
  def update
31
27
  @content_block = ContentBlock.find(params[:id])
32
28
 
33
- if @content_block.update_attributes(params[:content_block])
34
- expire_all_pages
29
+ if @content_block.update_attributes(content_block_params)
35
30
  redirect_to manifest_content_blocks_path
36
31
  else
37
32
  render 'edit'
@@ -40,10 +35,18 @@ class Manifest::ContentBlocksController < Manifest::ManifestController
40
35
 
41
36
  def destroy
42
37
  @content_block = ContentBlock.find(params[:id])
43
- @content_block.delete
44
-
45
- expire_all_pages
38
+ @content_block.destroy
46
39
 
47
40
  redirect_to manifest_content_blocks_path
48
41
  end
42
+
43
+ private
44
+
45
+ def content_block_params
46
+ if current_editor.admin?
47
+ params[:content_block]
48
+ else
49
+ params[:content_block].slice(:content)
50
+ end
51
+ end
49
52
  end
@@ -1,4 +1,7 @@
1
1
  class Manifest::ManifestController < ApplicationController
2
+ before_filter :authorize
3
+
4
+ layout 'manifest/manifest'
2
5
 
3
6
  private
4
7
 
@@ -15,12 +18,4 @@ class Manifest::ManifestController < ApplicationController
15
18
  def authorize_admin
16
19
  redirect_to manifest_path, alert: 'Admins only' unless current_editor.admin?
17
20
  end
18
-
19
- def expire_all_pages
20
- expire_page '/index.html'
21
-
22
- Page.all.each do |p|
23
- expire_page "/#{p.slug}.html"
24
- end
25
- end
26
21
  end
@@ -1,9 +1,6 @@
1
1
  class Manifest::PagesController < Manifest::ManifestController
2
- before_filter :authorize
3
2
  before_filter :authorize_admin, except: [:index, :show]
4
3
 
5
- layout 'manifest/manifest'
6
-
7
4
  def index
8
5
  @pages = Page.all
9
6
  end
@@ -20,7 +17,7 @@ class Manifest::PagesController < Manifest::ManifestController
20
17
  @page = Page.new(params[:page])
21
18
 
22
19
  if @page.save
23
- redirect_to manifest_pages_path
20
+ redirect_to manifest_page_path(@page)
24
21
  else
25
22
  render 'new'
26
23
  end
@@ -42,7 +39,7 @@ class Manifest::PagesController < Manifest::ManifestController
42
39
 
43
40
  def destroy
44
41
  @page = Page.find(params[:id])
45
- @page.delete
42
+ @page.destroy
46
43
 
47
44
  redirect_to manifest_pages_path
48
45
  end
@@ -1,4 +1,4 @@
1
- class Manifest::SessionsController < Manifest::ManifestController
1
+ class Manifest::SessionsController < ApplicationController
2
2
  layout 'manifest/sessions'
3
3
 
4
4
  def new
@@ -1,14 +1,7 @@
1
1
  class PagesController < ApplicationController
2
2
  layout 'public'
3
3
 
4
- caches_page :show
5
-
6
4
  def show
7
- if @page = Page.find_by_slug(params[:slug])
8
- @content_blocks = @page.content_blocks
9
- render @page.slug
10
- else
11
- raise ActiveRecord::RecordNotFound
12
- end
5
+ render @page.slug if @page = Page.find(params[:id])
13
6
  end
14
7
  end
@@ -0,0 +1,23 @@
1
+ class Manifest::LabelledFormBuilder < ActionView::Helpers::FormBuilder
2
+ %w[text_field check_box collection_select check_box text_area date_select datetime_select time_select].each do |method_name|
3
+ define_method(method_name) do |name, *args|
4
+ classes = %w[field]
5
+
6
+ if %w[collection_select check_box].include? method_name
7
+ classes << 'inline-label'
8
+ end
9
+
10
+ @template.content_tag :div, class: classes.join(' ') do
11
+ label(name) + super(name, *args)
12
+ end
13
+ end
14
+ end
15
+
16
+ %w[submit].each do |method_name|
17
+ define_method(method_name) do
18
+ @template.content_tag :div, class: 'form-actions' do
19
+ super()
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,13 +4,17 @@ class ContentBlock < ActiveRecord::Base
4
4
 
5
5
  validates :title, :slug, uniqueness: true
6
6
  validates :title, presence: true
7
- validates :page_id, presence: true, on: :update
7
+ validates :slug, presence: true, on: :update
8
8
 
9
9
  belongs_to :page
10
10
 
11
11
  default_scope includes(:page).order('pages.title')
12
12
 
13
13
  def render
14
- self.content.html_safe
14
+ if allow_html
15
+ content.html_safe
16
+ else
17
+ content
18
+ end
15
19
  end
16
20
  end
data/app/models/page.rb CHANGED
@@ -2,10 +2,9 @@ class Page < ActiveRecord::Base
2
2
  extend FriendlyId
3
3
  friendly_id :title, use: :slugged
4
4
 
5
- before_save :set_template_path
6
- after_create :create_template_file
7
- after_update :move_template_file
8
- after_destroy :remove_template_file
5
+ after_create :create_template
6
+ after_update :rename_template
7
+ after_destroy :remove_template
9
8
 
10
9
  validates :title, :slug, uniqueness: true
11
10
  validates :title, presence: true
@@ -13,22 +12,28 @@ class Page < ActiveRecord::Base
13
12
 
14
13
  has_many :content_blocks
15
14
 
16
- private
15
+ default_scope order('title')
17
16
 
18
- def set_template_path
19
- @old_template_path = attribute_was(:template_path)
20
- self.template_path = "#{Rails.root}/app/views/pages/#{self.slug}.html.erb"
17
+ def template_path
18
+ template_path_from_slug(slug)
21
19
  end
22
20
 
23
- def create_template_file
21
+ private
22
+
23
+ def create_template
24
24
  %x(touch #{self.template_path})
25
25
  end
26
26
 
27
- def move_template_file
28
- %x(mv #{@old_template_path} #{self.template_path})
27
+ def rename_template
28
+ old_template_path = template_path_from_slug(slug_was)
29
+ %x(mv #{old_template_path} #{template_path})
30
+ end
31
+
32
+ def remove_template
33
+ %x(rm #{template_path})
29
34
  end
30
35
 
31
- def remove_template_file
32
- %x(rm #{self.template_path})
36
+ def template_path_from_slug(slug)
37
+ "#{Rails.root}/app/views/pages/#{slug}.html.erb"
33
38
  end
34
39
  end