disclaimer 0.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.
Files changed (122) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +60 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/disclaimer/application.js +16 -0
  5. data/app/assets/javascripts/disclaimer/documents.js +2 -0
  6. data/app/assets/javascripts/disclaimer/segments.js +2 -0
  7. data/app/assets/stylesheets/disclaimer/application.css +13 -0
  8. data/app/assets/stylesheets/disclaimer/documents.css +9 -0
  9. data/app/assets/stylesheets/disclaimer/segments.css +4 -0
  10. data/app/controllers/disclaimer/application_controller.rb +4 -0
  11. data/app/controllers/disclaimer/documents_controller.rb +74 -0
  12. data/app/controllers/disclaimer/segments_controller.rb +45 -0
  13. data/app/helpers/disclaimer/application_helper.rb +4 -0
  14. data/app/helpers/disclaimer/documents_helper.rb +4 -0
  15. data/app/helpers/disclaimer/segments_helper.rb +4 -0
  16. data/app/models/disclaimer/document.rb +57 -0
  17. data/app/models/disclaimer/segment.rb +26 -0
  18. data/app/models/disclaimer/segment_holder.rb +17 -0
  19. data/app/views/disclaimer/documents/delete.html.erb +8 -0
  20. data/app/views/disclaimer/documents/index.html.erb +28 -0
  21. data/app/views/disclaimer/documents/new.html.erb +48 -0
  22. data/app/views/disclaimer/documents/show.html.erb +19 -0
  23. data/app/views/disclaimer/segments/_segment.html.erb +8 -0
  24. data/app/views/disclaimer/segments/delete.html.erb +8 -0
  25. data/app/views/disclaimer/segments/index.html.erb +26 -0
  26. data/app/views/disclaimer/segments/new.html.erb +24 -0
  27. data/app/views/disclaimer/segments/show.html.erb +2 -0
  28. data/app/views/layouts/disclaimer/application.html.erb +15 -0
  29. data/config/routes.rb +18 -0
  30. data/db/migrate/20121023125748_create_disclaimer_documents.rb +12 -0
  31. data/db/migrate/20121024074240_create_segments.rb +10 -0
  32. data/db/migrate/20121024080818_create_disclaimer_segment_holders.rb +11 -0
  33. data/lib/disclaimer/engine.rb +5 -0
  34. data/lib/disclaimer/version.rb +3 -0
  35. data/lib/disclaimer.rb +6 -0
  36. data/lib/rails/actionpack/lib/action_controller/base.rb +28 -0
  37. data/lib/tasks/disclaimer_tasks.rake +4 -0
  38. data/test/disclaimer_test.rb +7 -0
  39. data/test/dummy/README.rdoc +261 -0
  40. data/test/dummy/Rakefile +7 -0
  41. data/test/dummy/app/assets/javascripts/application.js +15 -0
  42. data/test/dummy/app/assets/javascripts/sample.js +2 -0
  43. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  44. data/test/dummy/app/assets/stylesheets/sample.css +4 -0
  45. data/test/dummy/app/controllers/application_controller.rb +3 -0
  46. data/test/dummy/app/controllers/sample_controller.rb +12 -0
  47. data/test/dummy/app/helpers/application_helper.rb +2 -0
  48. data/test/dummy/app/helpers/sample_helper.rb +2 -0
  49. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/test/dummy/app/views/sample/index.html.erb +4 -0
  51. data/test/dummy/config/application.rb +59 -0
  52. data/test/dummy/config/boot.rb +10 -0
  53. data/test/dummy/config/database.yml +25 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +37 -0
  56. data/test/dummy/config/environments/production.rb +67 -0
  57. data/test/dummy/config/environments/test.rb +37 -0
  58. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/test/dummy/config/initializers/inflections.rb +15 -0
  60. data/test/dummy/config/initializers/mime_types.rb +5 -0
  61. data/test/dummy/config/initializers/secret_token.rb +7 -0
  62. data/test/dummy/config/initializers/session_store.rb +8 -0
  63. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/test/dummy/config/locales/en.yml +5 -0
  65. data/test/dummy/config/routes.rb +10 -0
  66. data/test/dummy/config.ru +4 -0
  67. data/test/dummy/db/development.sqlite3 +0 -0
  68. data/test/dummy/db/schema.rb +41 -0
  69. data/test/dummy/db/test.sqlite3 +0 -0
  70. data/test/dummy/log/development.log +13228 -0
  71. data/test/dummy/log/test.log +35207 -0
  72. data/test/dummy/public/404.html +26 -0
  73. data/test/dummy/public/422.html +26 -0
  74. data/test/dummy/public/500.html +25 -0
  75. data/test/dummy/public/favicon.ico +0 -0
  76. data/test/dummy/script/rails +6 -0
  77. data/test/dummy/test/functional/sample_controller_test.rb +29 -0
  78. data/test/dummy/test/unit/helpers/sample_helper_test.rb +4 -0
  79. data/test/dummy/tmp/cache/assets/B9D/BB0/sprockets%2Fc3340956015865527b738281d0798842 +0 -0
  80. data/test/dummy/tmp/cache/assets/C5A/090/sprockets%2F163158930fc7f594992ed570eb262440 +0 -0
  81. data/test/dummy/tmp/cache/assets/C65/6C0/sprockets%2F6411c0191302133114dd7b9452abec58 +0 -0
  82. data/test/dummy/tmp/cache/assets/C83/2C0/sprockets%2F99d131cd7946c82b8a39070e6b434530 +0 -0
  83. data/test/dummy/tmp/cache/assets/CD4/F20/sprockets%2F9705276958dc30aad02ae1f4618a60a4 +0 -0
  84. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  85. data/test/dummy/tmp/cache/assets/CE3/0F0/sprockets%2F1c1d13e6a59e0476d7663354de087ff0 +0 -0
  86. data/test/dummy/tmp/cache/assets/D05/D80/sprockets%2F0f27d3a1d395bf559a2d725033de721c +0 -0
  87. data/test/dummy/tmp/cache/assets/D14/8E0/sprockets%2F1d0962a03dd3d782c8eadf712769a972 +0 -0
  88. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  89. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  90. data/test/dummy/tmp/cache/assets/D51/800/sprockets%2F0b6c1b1792d877f8e8fb3d82d577ca92 +0 -0
  91. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  92. data/test/dummy/tmp/cache/assets/D69/ED0/sprockets%2F5e34b8807c9168eb298bc1eb4d01bc1b +0 -0
  93. data/test/dummy/tmp/cache/assets/D6A/080/sprockets%2Fb083da81ad739ec14c03d78b63c22d9f +0 -0
  94. data/test/dummy/tmp/cache/assets/D73/200/sprockets%2Ff550d44b0e67ff62964de563da84c2ab +0 -0
  95. data/test/dummy/tmp/cache/assets/D9D/D20/sprockets%2F17bfe7df9a25cca0b3e5604f442be847 +0 -0
  96. data/test/dummy/tmp/cache/assets/DA6/F40/sprockets%2F55aedaf8fe75d461c2c82239e7e1d0b9 +0 -0
  97. data/test/dummy/tmp/cache/assets/DB4/B10/sprockets%2F1419cefd434468f9dfea571aa7ee59f7 +0 -0
  98. data/test/dummy/tmp/cache/assets/DC6/910/sprockets%2Faad8dad748c771644d1bbbcf02409fe2 +0 -0
  99. data/test/dummy/tmp/cache/assets/DCD/6D0/sprockets%2Fe8e47b38d458acad468a0b2bdcd12e76 +0 -0
  100. data/test/dummy/tmp/cache/assets/DD1/600/sprockets%2Fd61c971a175fe64d20ceefe3e7f4e2b3 +0 -0
  101. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  102. data/test/dummy/tmp/cache/assets/DDD/C60/sprockets%2F59ec92d2bcdf9ece368f07a4ca6509c7 +0 -0
  103. data/test/dummy/tmp/cache/assets/DE1/2B0/sprockets%2Fdca152daab7ddab59235356c1d2b21db +0 -0
  104. data/test/dummy/tmp/cache/assets/DFB/DF0/sprockets%2Fa1fb1cc09fd766dcc9e2b9d4a9421db4 +0 -0
  105. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  106. data/test/dummy/tmp/cache/assets/E22/0C0/sprockets%2F72c5c1adba8375dda425a7bfb5ba7c4f +0 -0
  107. data/test/dummy/tmp/cache/assets/E27/370/sprockets%2Ff374d3bfba2ca636ce768ab8eecb31b3 +0 -0
  108. data/test/dummy/tmp/cache/assets/E2C/8D0/sprockets%2F234ff42c359a2beddfb9d10ee75aef3d +0 -0
  109. data/test/dummy/tmp/pids/server.pid +1 -0
  110. data/test/fixtures/disclaimer/documents.yml +9 -0
  111. data/test/fixtures/disclaimer/segment_holders.yml +9 -0
  112. data/test/fixtures/disclaimer/segments.yml +13 -0
  113. data/test/functional/disclaimer/documents_controller_test.rb +129 -0
  114. data/test/functional/disclaimer/segments_controller_test.rb +77 -0
  115. data/test/integration/navigation_test.rb +10 -0
  116. data/test/test_helper.rb +35 -0
  117. data/test/unit/disclaimer/document_test.rb +36 -0
  118. data/test/unit/disclaimer/segment_holder_test.rb +9 -0
  119. data/test/unit/disclaimer/segment_test.rb +59 -0
  120. data/test/unit/helpers/disclaimer/documents_helper_test.rb +6 -0
  121. data/test/unit/helpers/disclaimer/segments_helper_test.rb +6 -0
  122. metadata +330 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Rob Nichols
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.rdoc ADDED
@@ -0,0 +1,60 @@
1
+ = Disclaimer
2
+
3
+ A tool for adding disclaimers to applications.
4
+
5
+ == Installation
6
+
7
+ === Gemfile TODO - add config option
8
+
9
+ === Routing
10
+
11
+ Update config/routes.rb by adding:
12
+
13
+ mount Disclaimer::Engine => "/disclaimer"
14
+
15
+ See test/dummy/config/routes.rb
16
+
17
+ == Usage
18
+
19
+ First create a disclaimer document (see below) and give it a name. (The name is in underscore form: like_this).
20
+
21
+ Then in your application controller, define the disclaimer you wish to use with 'disclaimer(:document_name)'.
22
+
23
+ So for example, you have a disclaimer document with the name :our_company_disclaimer and you want to make sure that
24
+ everyone who visits your products controller has accepted this disclaimer. Modify the controller like this:
25
+
26
+ class ProductsController < ApplicationController
27
+
28
+ disclaimer :our_company_disclaimer
29
+
30
+
31
+ .....(rest of controller)....
32
+
33
+ end
34
+
35
+ Then when a user navigates to the products controller, they will be redirected to the disclaimer document at:
36
+
37
+ /disclaimer/documents/our_company_disclaimer
38
+
39
+ If they accept the disclaimer, they will be redirected back to the page they were originally aiming for.
40
+
41
+ The acceptance is stored in session and therefore will be remembered for as long as the browser is open.
42
+
43
+ === Options
44
+
45
+ A before_filter is used to provide this functionality, and you can pass before_filter options through from
46
+ the disclaimer declaration. Therefore, to only display a disclaimer for the index and show actions in a controller
47
+ use:
48
+
49
+ disclaimer :our_company_disclaimer, :only => [:index, :show]
50
+
51
+ == Documents and Segments
52
+
53
+ Documents can be created at /disclaimer/documents, and Segments as /disclaimer/segments. Documents can contain
54
+ many segments, and segments can be shared across many documents (that is, you can share common sections of a disclaimer
55
+ across many documents). This behaviour can be overwritten in the host application.
56
+
57
+ The disclaimer engine does not restrict access to these controllers. Such restriction should be configured in
58
+ the host application. However, everyone needs access to the disclaimer documents#show action so that they can read
59
+ and accept the disclaimer.
60
+
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Disclaimer'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require jquery-ui
16
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,9 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ .ui-icon {
7
+ float: left;
8
+ margin-right: 0.5em;
9
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ module Disclaimer
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,74 @@
1
+ require_dependency "disclaimer/application_controller"
2
+
3
+ module Disclaimer
4
+ class DocumentsController < ApplicationController
5
+ before_filter :get_document, :only => [:show, :delete, :destroy, :edit, :update, :accept]
6
+
7
+ def index
8
+ @documents = Document.all
9
+ end
10
+
11
+ def show
12
+ end
13
+
14
+ def new
15
+ @document = Document.new
16
+ end
17
+
18
+ def create
19
+ new
20
+ update
21
+ end
22
+
23
+ def edit
24
+ render :new
25
+ end
26
+
27
+ def update
28
+ params[:document][:segments] = replace_with_segments(params[:document][:segments])
29
+ @document.update_attributes(params[:document])
30
+ redirect_to document_path(@document)
31
+ end
32
+
33
+ def delete
34
+ end
35
+
36
+ def destroy
37
+ @document.destroy
38
+ redirect_to :controller => 'disclaimer/documents', :action => 'index'
39
+ end
40
+
41
+ def accept
42
+ return_path = disclaimer_return_path
43
+ store_disclaimer_acceptance
44
+ redirect_to return_path || :root
45
+ end
46
+
47
+ private
48
+ def get_document
49
+ @document = Document.find_by_name(params[:id])
50
+ end
51
+
52
+ def replace_with_segments(hash_with_ids_as_keys = nil)
53
+ if hash_with_ids_as_keys
54
+ hash_with_ids_as_keys.keys.collect{|id| Segment.find(id)}
55
+ else
56
+ []
57
+ end
58
+ end
59
+
60
+ def store_disclaimer_acceptance
61
+ session[:disclaimer] ||= {}
62
+ session[:disclaimer][@document.name.to_sym] = ACCEPTED
63
+ end
64
+
65
+ def disclaimer_return_path
66
+ if session[:disclaimer]
67
+ return_path = session[:disclaimer][@document.name.to_sym]
68
+ return return_path if return_path != ACCEPTED
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,45 @@
1
+ require_dependency "disclaimer/application_controller"
2
+
3
+ module Disclaimer
4
+ class SegmentsController < ApplicationController
5
+ before_filter :get_segment, :only => [:show, :delete, :destroy, :edit, :update]
6
+
7
+ def index
8
+ @segments = Segment.all
9
+ end
10
+
11
+ def show
12
+ end
13
+
14
+ def new
15
+ @segment = Segment.new
16
+ end
17
+
18
+ def create
19
+ new
20
+ update
21
+ end
22
+
23
+ def edit
24
+ render :new
25
+ end
26
+
27
+ def update
28
+ @segment.update_attributes(params[:segment])
29
+ redirect_to segment_path(@segment)
30
+ end
31
+
32
+ def delete
33
+ end
34
+
35
+ def destroy
36
+ @segment.destroy
37
+ redirect_to :controller => 'disclaimer/segments', :action => 'index'
38
+ end
39
+
40
+ private
41
+ def get_segment
42
+ @segment = Segment.find_by_name(params[:id])
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ module Disclaimer
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Disclaimer
2
+ module DocumentsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Disclaimer
2
+ module SegmentsHelper
3
+ end
4
+ end
@@ -0,0 +1,57 @@
1
+ module Disclaimer
2
+ class Document < ActiveRecord::Base
3
+ attr_accessible :footer, :header, :title, :name, :segments
4
+
5
+ before_save :underscore_name
6
+
7
+ has_many :segment_holders, :uniq => true
8
+ has_many :segments, :through => :segment_holders, :uniq => true
9
+
10
+ validates :name, :presence => true
11
+
12
+ def segment_holder_for(segment)
13
+ segment_holders.where(:segment_id => segment.id).first
14
+ end
15
+
16
+ def to_param
17
+ name
18
+ end
19
+
20
+ def title
21
+ ((!super || super.empty?) && name.present?) ? name.humanize : super
22
+ end
23
+
24
+ private
25
+ def method_missing(method, *args)
26
+ segment = args.first
27
+ if act_as_list_methods.include?(method.to_sym) and segment.kind_of? Segment
28
+ modify_via_segment_holder_acts_as_list_method(method, segment)
29
+ else
30
+ super(method, *args)
31
+ end
32
+ end
33
+
34
+ def act_as_list_methods
35
+ @act_as_list_methods ||= ActiveRecord::Acts::List::InstanceMethods.instance_methods
36
+ end
37
+
38
+ def modify_via_segment_holder_acts_as_list_method(method, segment)
39
+ segment_holder = segment_holder_for(segment)
40
+ raise segment_not_associated_message(method, segment) unless segment_holder
41
+ segment_holder.send(method)
42
+ end
43
+
44
+ def segment_not_associated_message(method, segment)
45
+ <<EOF
46
+ The segment is not associated with the document, and therefore document.#{method}(segment) is not valid:
47
+ #{inspect}
48
+ #{segment.inspect}
49
+ EOF
50
+ end
51
+
52
+ def underscore_name
53
+ self.name = self.name.downcase.gsub(/\s+/, '_')
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,26 @@
1
+ module Disclaimer
2
+ class Segment < ActiveRecord::Base
3
+ attr_accessible :body, :title, :name
4
+
5
+ before_save :underscore_name
6
+
7
+ has_many :segment_holders
8
+ has_many :documents, :through => :segment_holders
9
+
10
+ validates :name, :presence => true
11
+
12
+ def to_param
13
+ name
14
+ end
15
+
16
+ def title
17
+ ((!super || super.empty?) && name.present?) ? name.humanize : super
18
+ end
19
+
20
+ private
21
+ def underscore_name
22
+ self.name = self.name.downcase.gsub(/\s+/, '_')
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'acts_as_list'
2
+
3
+ module Disclaimer
4
+ class SegmentHolder < ActiveRecord::Base
5
+ attr_accessible :document_id, :position, :segment_id
6
+
7
+ belongs_to :document
8
+ belongs_to :segment
9
+
10
+ acts_as_list :scope => :document
11
+
12
+ # I needed to use default_scope to preserve ordering in through relationships.
13
+ # Using 'acts_as_list :scope => :document' alone does not preserve ordering
14
+ # in the 'has_many :segments, :through => :segment_holders' relationship.
15
+ default_scope :order => :position
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ <h1>Delete Document</h1>
2
+ <h2><%= @document.title %></h2>
3
+ <p>Are you sure you want to delete this document?</p>
4
+
5
+ <%= form_for(@document, :url => document_path(@document), :method => :delete) do |form| %>
6
+ <%= form.submit('Yes') %>
7
+ <%= link_to('Cancel', url_for(:back)) %>
8
+ <% end %>
@@ -0,0 +1,28 @@
1
+ <h1>Documents</h1>
2
+ <p><%= link_to('New Document', new_document_path) %></p>
3
+
4
+ <h1>Disclaimer</h1>
5
+
6
+ <% if @documents.empty? %>
7
+ <p>There are currently no disclaimer documents</p>
8
+ <% else %>
9
+ <table>
10
+ <tr>
11
+ <th>Name</th>
12
+ <th>Title</th>
13
+ <th>Segments</th>
14
+ <th colspan="3">Action</th>
15
+ </tr>
16
+ <% @documents.each do |document| %>
17
+ <tr>
18
+ <td><%= document.name %></td>
19
+ <td><%= document.title %></td>
20
+ <td><%= document.segments.collect{|d| d.name}.join(', ') %>
21
+ <td><%= link_to('Show', document_path(document)) %></td>
22
+ <td><%= link_to('Edit', edit_document_path(document)) %></td>
23
+ <td><%= link_to('Delete', delete_document_path(document)) %></td>
24
+ </tr>
25
+ <% end %>
26
+ </table>
27
+ <% end %>
28
+
@@ -0,0 +1,48 @@
1
+ <h1>Disclaimer document</h1>
2
+
3
+ <%= form_for(@document) do |form| %>
4
+
5
+ <p>
6
+ <%= form.label(:name) %><br/>
7
+ <%= form.text_field(:name) %>
8
+ </p>
9
+
10
+ <p>
11
+ <%= form.label(:title) %><br/>
12
+ <%= form.text_field(:title) %>
13
+ </p>
14
+
15
+ <p>
16
+ <%= form.label(:header) %><br/>
17
+ <%= form.text_area(:header, :rows => 4) %>
18
+ </p>
19
+
20
+ <p>Segments</p>
21
+
22
+ <ul>
23
+ <% Disclaimer::Segment.all.each do |segment| %>
24
+ <li>
25
+
26
+ <%= check_box_tag(
27
+ :segment_ids,
28
+ nil,
29
+ @document.segments.include?(segment),
30
+ :name => "document[segments][#{segment.id}]"
31
+ )
32
+ %>
33
+
34
+ <%= segment.name %>
35
+ </li>
36
+ <% end %>
37
+ </ul>
38
+ <p>
39
+ <%= form.label(:footer) %><br/>
40
+ <%= form.text_area(:footer, :rows => 4) %>
41
+ </p>
42
+
43
+ <p>
44
+ <%= form.submit %>
45
+ </p>
46
+
47
+ <% end %>
48
+
@@ -0,0 +1,19 @@
1
+ <header>
2
+ <h1><%= @document.title %></h1>
3
+ <%= @document.header %>
4
+ </header>
5
+ <%= javascript_tag('$(function() {$( "#articles" ).accordion({heightStyle: "content"});});') %>
6
+ <div id="articles">
7
+ <% @document.segments.each do |segment| %>
8
+
9
+ <h3><%= segment.title %></h3>
10
+ <div><%= segment.body %></div>
11
+
12
+ <% end %>
13
+ </div>
14
+ <footer>
15
+ <%= @document.footer %>
16
+ <%= form_for(@document, :url => accept_document_path(@document), :method => 'post') do |form| %>
17
+ <%= form.submit('Accept') %>
18
+ <% end %>
19
+ </footer>
@@ -0,0 +1,8 @@
1
+ <section class="segment">
2
+ <header>
3
+ <h2><%= segment.title %></h2>
4
+ </header>
5
+ <div class="content">
6
+ <%= segment.body %>
7
+ </div>
8
+ </section>
@@ -0,0 +1,8 @@
1
+ <h1>Delete Segment</h1>
2
+ <h2><%= @segment.title %></h2>
3
+ <p>Are you sure you want to delete this segment?</p>
4
+
5
+ <%= form_for(@segment, :url => segment_path(@segment), :method => :delete) do |form| %>
6
+ <%= form.submit('Yes') %>
7
+ <%= link_to('Cancel', url_for(:back)) %>
8
+ <% end %>
@@ -0,0 +1,26 @@
1
+ <h1>Segments</h1>
2
+ <p><%= link_to('New Segment', new_segment_path) %></p>
3
+
4
+ <% if @segments.empty? %>
5
+ <p>There are currently no disclaimer segments</p>
6
+ <% else %>
7
+
8
+ <table>
9
+ <tr>
10
+ <th>Name</th>
11
+ <th>Title</th>
12
+ <th>Documents</th>
13
+ <th colspan="3">Action</th>
14
+ </tr>
15
+ <% @segments.each do |segment| %>
16
+ <tr>
17
+ <td><%= segment.name %></td>
18
+ <td><%= segment.title %></td>
19
+ <td><%= segment.documents.collect{|d| d.name}.join(', ') %>
20
+ <td><%= link_to('Show', segment_path(segment)) %></td>
21
+ <td><%= link_to('Edit', edit_segment_path(segment)) %></td>
22
+ <td><%= link_to('Delete', delete_segment_path(segment)) %></td>
23
+ </tr>
24
+ <% end %>
25
+ </table>
26
+ <% end %>
@@ -0,0 +1,24 @@
1
+ <h1>Disclaimer segment</h1>
2
+
3
+ <%= form_for(@segment) do |form| %>
4
+
5
+ <p>
6
+ <%= form.label(:name) %><br/>
7
+ <%= form.text_field(:name) %>
8
+ </p>
9
+
10
+ <p>
11
+ <%= form.label(:title) %><br/>
12
+ <%= form.text_field(:title) %>
13
+ </p>
14
+
15
+ <p>
16
+ <%= form.label(:body) %><br/>
17
+ <%= form.text_area(:body, :rows => 6) %>
18
+ </p>
19
+
20
+ <p>
21
+ <%= form.submit %>
22
+ </p>
23
+
24
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <h1><%= @segment.name %></h1>
2
+ <%= render @segment %>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Disclaimer</title>
5
+ <%= stylesheet_link_tag "disclaimer/application", :media => "all" %>
6
+ <%= stylesheet_link_tag "http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" %>
7
+ <%= javascript_include_tag "disclaimer/application" %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,18 @@
1
+ Disclaimer::Engine.routes.draw do
2
+
3
+ root :to => "documents#index"
4
+
5
+ resources :documents do
6
+ member do
7
+ get :delete
8
+ post :accept
9
+ end
10
+ end
11
+
12
+ resources :segments do
13
+ member do
14
+ get :delete
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,12 @@
1
+ class CreateDisclaimerDocuments < ActiveRecord::Migration
2
+ def change
3
+ create_table :disclaimer_documents do |t|
4
+ t.string :title
5
+ t.string :name
6
+ t.text :header
7
+ t.text :footer
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSegments < ActiveRecord::Migration
2
+ def change
3
+ create_table :disclaimer_segments do |t|
4
+ t.string :name
5
+ t.string :title
6
+ t.text :body
7
+ t.timestamps
8
+ end
9
+ end
10
+ end