ominous 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 (119) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +97 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/ominous/application.js +15 -0
  5. data/app/assets/javascripts/ominous/warnings.js +33 -0
  6. data/app/assets/stylesheets/ominous/_ominous_colours.scss +4 -0
  7. data/app/assets/stylesheets/ominous/application.scss +13 -0
  8. data/app/assets/stylesheets/ominous/warnings.scss +41 -0
  9. data/app/controllers/ominous/application_controller.rb +16 -0
  10. data/app/controllers/ominous/warnings_controller.rb +15 -0
  11. data/app/helpers/ominous/application_helper.rb +39 -0
  12. data/app/helpers/ominous/warnings_helper.rb +29 -0
  13. data/app/models/ominous/closer.rb +19 -0
  14. data/app/models/ominous/warning.rb +74 -0
  15. data/app/models/ominous/warning_closer.rb +11 -0
  16. data/app/views/layouts/ominous/application.html.erb +14 -0
  17. data/app/views/ominous/warnings/_list.html.erb +20 -0
  18. data/config/locales/en.yml +1 -0
  19. data/config/routes.rb +8 -0
  20. data/db/migrate/20121206144249_create_ominous_warnings.rb +8 -0
  21. data/db/migrate/20121206145743_create_ominous_warning_closers.rb +10 -0
  22. data/db/migrate/20121206153254_create_ominous_closers.rb +11 -0
  23. data/lib/ominous/engine.rb +14 -0
  24. data/lib/ominous/version.rb +3 -0
  25. data/lib/ominous.rb +4 -0
  26. data/lib/tasks/ominous_tasks.rake +4 -0
  27. data/test/dummy/README.rdoc +261 -0
  28. data/test/dummy/Rakefile +7 -0
  29. data/test/dummy/app/assets/javascripts/application.js +16 -0
  30. data/test/dummy/app/assets/javascripts/things.js +2 -0
  31. data/test/dummy/app/assets/stylesheets/application.scss +14 -0
  32. data/test/dummy/app/assets/stylesheets/scaffold.scss +56 -0
  33. data/test/dummy/app/assets/stylesheets/things.scss +4 -0
  34. data/test/dummy/app/controllers/application_controller.rb +4 -0
  35. data/test/dummy/app/controllers/things_controller.rb +54 -0
  36. data/test/dummy/app/helpers/application_helper.rb +2 -0
  37. data/test/dummy/app/helpers/things_helper.rb +2 -0
  38. data/test/dummy/app/models/thing.rb +5 -0
  39. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  40. data/test/dummy/app/views/things/_form.html.erb +27 -0
  41. data/test/dummy/app/views/things/edit.html.erb +6 -0
  42. data/test/dummy/app/views/things/index.html.erb +23 -0
  43. data/test/dummy/app/views/things/new.html.erb +5 -0
  44. data/test/dummy/app/views/things/show.html.erb +10 -0
  45. data/test/dummy/config/application.rb +59 -0
  46. data/test/dummy/config/boot.rb +10 -0
  47. data/test/dummy/config/database.yml +18 -0
  48. data/test/dummy/config/environment.rb +5 -0
  49. data/test/dummy/config/environments/development.rb +37 -0
  50. data/test/dummy/config/environments/production.rb +67 -0
  51. data/test/dummy/config/environments/test.rb +37 -0
  52. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  53. data/test/dummy/config/initializers/inflections.rb +15 -0
  54. data/test/dummy/config/initializers/mime_types.rb +5 -0
  55. data/test/dummy/config/initializers/secret_token.rb +7 -0
  56. data/test/dummy/config/initializers/session_store.rb +8 -0
  57. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/test/dummy/config/locales/en.yml +20 -0
  59. data/test/dummy/config/routes.rb +6 -0
  60. data/test/dummy/config.ru +4 -0
  61. data/test/dummy/db/migrate/20121207090710_create_things.rb +9 -0
  62. data/test/dummy/db/schema.rb +46 -0
  63. data/test/dummy/db/seeds/ominous/closers.yml +11 -0
  64. data/test/dummy/db/seeds/ominous/warnings.yml +1 -0
  65. data/test/dummy/db/seeds.rb +11 -0
  66. data/test/dummy/log/development.log +6329 -0
  67. data/test/dummy/log/test.log +16544 -0
  68. data/test/dummy/public/404.html +26 -0
  69. data/test/dummy/public/422.html +26 -0
  70. data/test/dummy/public/500.html +25 -0
  71. data/test/dummy/public/favicon.ico +0 -0
  72. data/test/dummy/script/rails +6 -0
  73. data/test/dummy/test/fixtures/things.yml +9 -0
  74. data/test/dummy/test/functional/things_controller_test.rb +98 -0
  75. data/test/dummy/test/unit/helpers/things_helper_test.rb +4 -0
  76. data/test/dummy/test/unit/thing_test.rb +7 -0
  77. data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
  78. data/test/dummy/tmp/cache/assets/CB1/FD0/sprockets%2F6e1bd95023705b5529e7ccc754a02867 +0 -0
  79. data/test/dummy/tmp/cache/assets/CC9/A60/sprockets%2F07383698788b2e4738d47ae3ec6a1d87 +0 -0
  80. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  81. data/test/dummy/tmp/cache/assets/CD8/D80/sprockets%2Fc021b5f59c2af065ff29a632752434f2 +0 -0
  82. data/test/dummy/tmp/cache/assets/CDA/7C0/sprockets%2F12b62b18784b4353d97f6a97a41f0ad0 +0 -0
  83. data/test/dummy/tmp/cache/assets/CDC/310/sprockets%2Ffcc31591d15ae084c418fc172660b956 +0 -0
  84. data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
  85. data/test/dummy/tmp/cache/assets/CFF/E00/sprockets%2F352bab412d75fa19d0a07504553b59df +0 -0
  86. data/test/dummy/tmp/cache/assets/D06/CE0/sprockets%2F41d74669fa9b15be92441ba007ab0c68 +0 -0
  87. data/test/dummy/tmp/cache/assets/D2B/540/sprockets%2Fc83f54ae55237ceb746bbb53c00b1142 +0 -0
  88. data/test/dummy/tmp/cache/assets/D2C/6D0/sprockets%2F3d403240cf0f43b784f29abbcb44f206 +0 -0
  89. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  90. data/test/dummy/tmp/cache/assets/D47/090/sprockets%2F3f61bf7b226774e61d49a5c2bf4ba788 +0 -0
  91. data/test/dummy/tmp/cache/assets/D49/8D0/sprockets%2F92613a75279536c4bcf4f3ba6cfde494 +0 -0
  92. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  93. data/test/dummy/tmp/cache/assets/D55/D30/sprockets%2F7736f39574ccd9ee349df6370cacc753 +0 -0
  94. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  95. data/test/dummy/tmp/cache/assets/D63/460/sprockets%2Fb9c8c98e6433f883fef1c54e67727ae9 +0 -0
  96. data/test/dummy/tmp/cache/assets/D6A/BF0/sprockets%2F762d06ba45dbecea1ec4f91d06449184 +0 -0
  97. data/test/dummy/tmp/cache/assets/D6B/810/sprockets%2Fb86f0cb0c0c0e267d26cf93fa606b578 +0 -0
  98. data/test/dummy/tmp/cache/assets/D6D/E30/sprockets%2F22dcb449e5cb7993f426a6f2ba336b2d +0 -0
  99. data/test/dummy/tmp/cache/assets/D70/F20/sprockets%2F1769eda3bb9755fed833c4ba761231dc +0 -0
  100. data/test/dummy/tmp/cache/assets/D77/D00/sprockets%2F4d1e5a8a96bd3c395214fd8ca879bf41 +0 -0
  101. data/test/dummy/tmp/cache/assets/D96/950/sprockets%2F5eee98198ef9d6273cdca638b9865fa8 +0 -0
  102. data/test/dummy/tmp/cache/assets/DA5/F70/sprockets%2F859ce38bab39b76b3dfcd28026aa8f62 +0 -0
  103. data/test/dummy/tmp/cache/assets/DAB/9C0/sprockets%2F8cadb8398e03f9730da11f8e7c9dc73b +0 -0
  104. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  105. data/test/dummy/tmp/cache/assets/DF4/C60/sprockets%2F9a20e4568aca578053dddb4e4aca0def +0 -0
  106. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  107. data/test/fixtures/ominous/closers.yml +10 -0
  108. data/test/fixtures/ominous/warning_closers.yml +15 -0
  109. data/test/fixtures/ominous/warnings.yml +8 -0
  110. data/test/fixtures/things.yml +11 -0
  111. data/test/functional/ominous/warnings_controller_test.rb +22 -0
  112. data/test/integration/navigation_test.rb +10 -0
  113. data/test/ominous_test.rb +7 -0
  114. data/test/test_helper.rb +19 -0
  115. data/test/unit/helpers/ominous/warnings_helper_test.rb +6 -0
  116. data/test/unit/ominous/closer_test.rb +9 -0
  117. data/test/unit/ominous/warning_closer_test.rb +9 -0
  118. data/test/unit/ominous/warning_test.rb +37 -0
  119. metadata +352 -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,97 @@
1
+ = Ominous
2
+
3
+ This engine adds warnings to a rails application.
4
+
5
+ == Installation
6
+
7
+ Add to your gemfile:
8
+
9
+ 'gem ominous' # TODO - gem not created yet
10
+
11
+ Some ominous functionality is provided by JavaScript. To enable this, you
12
+ need to add this to your app/assets/javascripts/application.js
13
+
14
+ //= require ominous/warnings
15
+
16
+ == Migrations
17
+
18
+ Use this command to copy the ominous migrations over to the parent rails app:
19
+
20
+ rake ominous:install:migrations
21
+
22
+ == Warnings
23
+
24
+ Warnings are the core model used by Ominous.
25
+
26
+ warning = Ominous::Warning.create :something_happened
27
+
28
+ Once a warning has been created, it can triggered with:
29
+
30
+ Ominous::Warning.trigger :something_happened
31
+
32
+ This causes a flag to be set in session, indicating that the associated warning
33
+ needs to be displayed.
34
+
35
+ == Displaying Warnings
36
+
37
+ To display a warning add this somewhere in the page:
38
+
39
+ <%= ominous_warnings %>
40
+
41
+ This will insert a div of class 'ominous_warnings', containing the warning messages
42
+ (if any have been triggered).
43
+
44
+ If you wish to use the ominous default styling, add this to your application.scss file:
45
+
46
+ *= require ominous/warnings
47
+
48
+ Alternatively, you can define your own styling.
49
+
50
+ == Closing a warning
51
+
52
+ Closers provide links within a warning, that allow a user to handle the warning.
53
+ How the link behaves depends upon the closure method associated with the closer.
54
+ See app/models/ominous/closer.rb for a list of closure methods and the behaviour
55
+ associated with them.
56
+
57
+ Warnings can have many closers, and closers can be shared across many warnings.
58
+ This is achieved through the WarningCloser class. This class acts_as_list,
59
+ so that it can be used to arrange the closers within a warning. To move
60
+ a closer within a warning, use this pattern:
61
+
62
+ warning.<acts_as_list_method>(closer)
63
+
64
+ For example:
65
+
66
+ warning.move_to_top(closer)
67
+
68
+ == Warning text
69
+
70
+ Warnings contain a title and description. Closers contain a message and a link.
71
+ The text used for each needs to be defined in your locale file.
72
+
73
+ For the something_happened warning used above
74
+ the entry needs to look like this:
75
+
76
+ en:
77
+
78
+ ominous:
79
+ warning:
80
+ something_happened:
81
+ title: Warning
82
+ description: You have triggered a warning.
83
+ closer_one:
84
+ message: This is the first closer
85
+ link: Click here to activate closer_one
86
+ closer_two:
87
+ message: This is the second closer
88
+ link: Click here to activate closer_two
89
+
90
+
91
+ == Managing warnings
92
+
93
+ This engine does not provide a tool for creating warnings and their associated
94
+ closers. It is envisage that warnings and closers will be defined in the
95
+ background app, for example via seeds (see test/dummy). If more flexible
96
+ assignment and management is require, this should be built into the host
97
+ application.
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 = 'Ominous'
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,15 @@
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_tree .
@@ -0,0 +1,33 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+
4
+
5
+ $(function() {
6
+
7
+ $('.ominous_warnings .reveal_hidden').click( function() {
8
+ $('.ominous_warnings .start_visible').hide();
9
+ $('.ominous_warnings .start_hidden').show();
10
+ return false;
11
+ });
12
+
13
+ $('.ominous_warnings .close_and_dismiss_warning').click( function() {
14
+ send_data_to_server($(this).attr('href'));
15
+ $(this).closest('.warning').hide('fade');
16
+ return false;
17
+ });
18
+
19
+
20
+ function send_data_to_server(url) {
21
+ $.ajax({
22
+ type: "PUT",
23
+ url: url,
24
+
25
+ success: function (data) {
26
+ // console.log(data);
27
+ },
28
+ error: function () {
29
+ // console.log('Error updating');
30
+ }
31
+ })
32
+ }
33
+ })
@@ -0,0 +1,4 @@
1
+ $white: #FFFFFF;
2
+ $warning: #FF0000;
3
+
4
+
@@ -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,41 @@
1
+ @import 'ominous_colours';
2
+
3
+ .ominous_warnings {
4
+ .warning {
5
+ position: absolute;
6
+ left:15%;
7
+ top: 100px;
8
+ margin: auto;
9
+ width: 70%;
10
+ z-index: 10000;
11
+ background-color: $white;
12
+ border: $warning solid 3px;
13
+ font-size: 1.2em;
14
+
15
+ .heading {
16
+
17
+ h2 {
18
+ background-color: $warning;
19
+ color: $white;
20
+ margin: 0;
21
+ }
22
+
23
+ }
24
+
25
+ h2, .description, .closers {
26
+ padding: 5px;
27
+ }
28
+
29
+ .start_hidden {
30
+ display: none;
31
+ }
32
+
33
+ .closer {
34
+ margin: 0 0 1em;
35
+ p {
36
+ margin: 0;
37
+ }
38
+ }
39
+
40
+ }
41
+ }
@@ -0,0 +1,16 @@
1
+ module Ominous
2
+ class ApplicationController < ActionController::Base
3
+
4
+ protected
5
+ def check_ominous_warnings
6
+ Warning.requests.each{|request| session_store << request}
7
+ Warning.clear_requests
8
+ end
9
+ helper_method :check_ominous_warnings
10
+
11
+ def session_store
12
+ session[:ominous_warnings] ||= []
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require_dependency "ominous/application_controller"
2
+
3
+ module Ominous
4
+ class WarningsController < ApplicationController
5
+
6
+ def dismiss
7
+ @warning = Warning.find(params[:id])
8
+ session[:ominous_warnings][@warning.name.to_sym] = :hide
9
+ render :text => "ominous warning #{@warning.name} set to hidden"
10
+ end
11
+
12
+
13
+
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ module Ominous
2
+ module ApplicationHelper
3
+ def ominous_warnings
4
+ process_ominous_warnings
5
+ if warnings_to_show?
6
+ content_tag(
7
+ 'div',
8
+ render(
9
+ :partial => 'ominous/warnings/list',
10
+ :locals => {:warnings => warning_to_display}
11
+ ),
12
+ :class => 'ominous_warnings')
13
+ end
14
+ end
15
+
16
+ def process_ominous_warnings
17
+ Warning.requests.each do |request|
18
+ session_store[request.to_sym] = :show unless session_store[request.to_sym]
19
+ end
20
+ Warning.clear_requests
21
+ end
22
+
23
+ def warnings_to_show?
24
+ session_store
25
+ session_store.values.include? :show
26
+ end
27
+
28
+ def session_store
29
+ session[:ominous_warnings] ||= {}
30
+ end
31
+
32
+ def warning_to_display
33
+ warnings = session_store.keys.collect do |name|
34
+ Warning.find_by_name(name) if session_store[name] == :show
35
+ end
36
+ return warnings.compact
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ module Ominous
2
+ module WarningsHelper
3
+ def classes_for(closer)
4
+ classes = ['closer']
5
+ classes << visibility(closer.start_hidden?)
6
+ classes.join(' ')
7
+ end
8
+
9
+ def visibility(truth)
10
+ truth ? 'start_hidden' : 'start_visible'
11
+ end
12
+
13
+ def closer_link_to(warning, closer)
14
+ text = t("ominous.warning.#{warning.name}.#{closer.name}.link")
15
+ link_class = closer.closure_method
16
+ url = closer_url(warning, closer)
17
+ link_to(text, url, :method => :put, :class => link_class)
18
+ end
19
+
20
+ def closer_url(warning, closer)
21
+ if closer.closure_method == 'close_and_dismiss_warning'
22
+ ominous.dismiss_warning_path(warning)
23
+ else
24
+ return closer.url
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ module Ominous
2
+ class Closer < ActiveRecord::Base
3
+ attr_accessible :name, :url, :closure_method, :start_hidden
4
+
5
+ CLOSURE_METHODS = {
6
+ :reveal_hidden => 'Hides the current closers and reveals any hidden closers',
7
+ :close_and_dismiss_warning => 'Closes the warning message and tells server not to display warning again',
8
+ :redirect => 'Link to take user to closer.url without clearing the warning'
9
+ }
10
+
11
+ validates :name, :presence => true
12
+ validates :closure_method, :inclusion => { :in => CLOSURE_METHODS.keys.collect(&:to_s) }
13
+
14
+ def self.closure_methods
15
+ CLOSURE_METHODS
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,74 @@
1
+ module Ominous
2
+ class Warning < ActiveRecord::Base
3
+ attr_accessible :name
4
+
5
+ validates :name, :presence => true
6
+
7
+ has_many(
8
+ :warning_closers,
9
+ :uniq => true,
10
+ :order => :position
11
+ )
12
+
13
+ has_many(
14
+ :closers,
15
+ :through => :warning_closers,
16
+ :order => :position
17
+ )
18
+
19
+ def self.trigger(name)
20
+ unless exists?(:name => name)
21
+ raise "Attempt to trigger warning failed: #{name} not recognised"
22
+ end
23
+ requests << name.to_sym
24
+ end
25
+
26
+ def self.requests
27
+ @requests ||= []
28
+ end
29
+
30
+ def self.clear_requests
31
+ @requests = []
32
+ end
33
+
34
+ private
35
+ def method_missing(symbol, *args, &block)
36
+ if acts_as_list_method?(symbol)
37
+ pass_method_to_warning_closer(symbol, args.first)
38
+ else
39
+ super
40
+ end
41
+ end
42
+
43
+ # Allows acts_as_list methods to be used within the warning.
44
+ # If closers were the act_as_list object, you could do things like this
45
+ #
46
+ # warning.closers.last.move_higher
47
+ #
48
+ # However, as closers are used on multiple warnings and they
49
+ # need to be independently sortable within each warning, it is the
50
+ # through table model WarningCloser that acts_as_list. To change
51
+ # position the change must be made in the context of the warning.
52
+ # pass_method_to_warning_closer in combination with method_missing,
53
+ # allows you to pass to a warning the acts_as_list method together with
54
+ # the closer it needs to effect. The equivalent move_higher call then becomes:
55
+ #
56
+ # warning.move_higher(warning.closers.last)
57
+ #
58
+ # You can also do:
59
+ #
60
+ # warning.move_to_top(closer)
61
+ # warning.last?(closer)
62
+ #
63
+ def pass_method_to_warning_closer(symbol, closer)
64
+ raise "A closer is needed to identify the warning_closer" unless closer.kind_of? Closer
65
+ warning_closer = warning_closers.where(:closer_id => closer.id).first
66
+ warning_closer.send(symbol) if warning_closer
67
+ end
68
+
69
+ def acts_as_list_method?(symbol)
70
+ ActiveRecord::Acts::List::InstanceMethods.instance_methods.include?(symbol.to_sym)
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,11 @@
1
+ require 'acts_as_list'
2
+ module Ominous
3
+ class WarningCloser < ActiveRecord::Base
4
+ attr_accessible :warning_id, :closer_id, :position
5
+
6
+ belongs_to :closer
7
+ belongs_to :warning
8
+
9
+ acts_as_list :scope => :warning
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Ominous</title>
5
+ <%= stylesheet_link_tag "ominous/application", :media => "all" %>
6
+ <%= javascript_include_tag "ominous/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,20 @@
1
+ <% warnings.each do |warning| %>
2
+ <div class="warning">
3
+ <div class="heading">
4
+ <h2><%= t("ominous.warning.#{warning.name}.title") %></h2>
5
+ </div>
6
+ <div class="description">
7
+ <%= t("ominous.warning.#{warning.name}.description") %>
8
+ </div>
9
+ <div class="closers">
10
+ <% warning.closers.each do |closer| %>
11
+ <div class="<%= classes_for(closer) %>">
12
+ <p><%= t("ominous.warning.#{warning.name}.#{closer.name}.message") %></p>
13
+ <p>
14
+ <%= closer_link_to(warning, closer) %>
15
+ </p>
16
+ </div>
17
+ <% end %>
18
+ </div>
19
+ </div>
20
+ <% end %>
@@ -0,0 +1 @@
1
+ en:
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ Ominous::Engine.routes.draw do
2
+
3
+ resources :warnings, :only => [:dismiss] do
4
+ member do
5
+ put :dismiss
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class CreateOminousWarnings < ActiveRecord::Migration
2
+ def change
3
+ create_table :ominous_warnings do |t|
4
+ t.column :name, :string
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ class CreateOminousWarningClosers < ActiveRecord::Migration
2
+ def change
3
+ create_table :ominous_warning_closers do |t|
4
+ t.column :warning_id, :integer
5
+ t.column :closer_id, :integer
6
+ t.column :position, :integer
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class CreateOminousClosers < ActiveRecord::Migration
2
+ def change
3
+ create_table :ominous_closers do |t|
4
+ t.column :name, :string
5
+ t.column :url, :string
6
+ t.column :closure_method, :string, :limit => 30
7
+ t.column :start_hidden, :boolean, :default => false
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Ominous
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Ominous
4
+
5
+ initializer 'ominous.action_controller' do |app|
6
+ ActiveSupport.on_load :action_controller do
7
+ helper Ominous::ApplicationHelper
8
+ helper Ominous::WarningsHelper
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+
@@ -0,0 +1,3 @@
1
+ module Ominous
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ominous.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "ominous/engine"
2
+
3
+ module Ominous
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ominous do
3
+ # # Task goes here
4
+ # end