silvermoon 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.
- data/.gitignore +8 -0
- data/.rvmrc +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +159 -0
- data/Guardfile +21 -0
- data/MIT-LICENSE +20 -0
- data/README.md +83 -0
- data/Rakefile +27 -0
- data/lib/generators/silvermoon/install/install_generator.rb +16 -0
- data/lib/generators/silvermoon/install/templates/silvermoon.yml +17 -0
- data/lib/silvermoon.rb +54 -0
- data/lib/silvermoon/action_controller_extension.rb +22 -0
- data/lib/silvermoon/notifier.rb +18 -0
- data/lib/silvermoon/notifier/base.rb +19 -0
- data/lib/silvermoon/notifier/facebook.rb +35 -0
- data/lib/silvermoon/notifier/twitter.rb +27 -0
- data/lib/silvermoon/railtie.rb +11 -0
- data/lib/silvermoon/version.rb +3 -0
- data/silvermoon.gemspec +21 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/notifications_controller.rb +86 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/notifications_helper.rb +2 -0
- data/spec/dummy/app/models/notification.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/notifications/_form.html.erb +29 -0
- data/spec/dummy/app/views/notifications/edit.html.erb +6 -0
- data/spec/dummy/app/views/notifications/index.html.erb +27 -0
- data/spec/dummy/app/views/notifications/new.html.erb +5 -0
- data/spec/dummy/app/views/notifications/show.html.erb +20 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/config/silvermoon.yml +12 -0
- data/spec/dummy/db/migrate/20110906125229_create_notifications.rb +15 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +191 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/public/stylesheets/scaffold.css +56 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/silvermoon/action_controller_extension_spec.rb +45 -0
- data/spec/silvermoon/notifier/base_spec.rb +18 -0
- data/spec/silvermoon/notifier_spec.rb +20 -0
- data/spec/silvermoon_spec.rb +45 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/config_helpers.rb +13 -0
- data/spec/support/stubs.rb +15 -0
- metadata +186 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
(function() {
|
2
|
+
// Technique from Juriy Zaytsev
|
3
|
+
// http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
|
4
|
+
function isEventSupported(eventName) {
|
5
|
+
var el = document.createElement('div');
|
6
|
+
eventName = 'on' + eventName;
|
7
|
+
var isSupported = (eventName in el);
|
8
|
+
if (!isSupported) {
|
9
|
+
el.setAttribute(eventName, 'return;');
|
10
|
+
isSupported = typeof el[eventName] == 'function';
|
11
|
+
}
|
12
|
+
el = null;
|
13
|
+
return isSupported;
|
14
|
+
}
|
15
|
+
|
16
|
+
function isForm(element) {
|
17
|
+
return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
|
18
|
+
}
|
19
|
+
|
20
|
+
function isInput(element) {
|
21
|
+
if (Object.isElement(element)) {
|
22
|
+
var name = element.nodeName.toUpperCase()
|
23
|
+
return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
|
24
|
+
}
|
25
|
+
else return false
|
26
|
+
}
|
27
|
+
|
28
|
+
var submitBubbles = isEventSupported('submit'),
|
29
|
+
changeBubbles = isEventSupported('change')
|
30
|
+
|
31
|
+
if (!submitBubbles || !changeBubbles) {
|
32
|
+
// augment the Event.Handler class to observe custom events when needed
|
33
|
+
Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
|
34
|
+
function(init, element, eventName, selector, callback) {
|
35
|
+
init(element, eventName, selector, callback)
|
36
|
+
// is the handler being attached to an element that doesn't support this event?
|
37
|
+
if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
|
38
|
+
(!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
|
39
|
+
// "submit" => "emulated:submit"
|
40
|
+
this.eventName = 'emulated:' + this.eventName
|
41
|
+
}
|
42
|
+
}
|
43
|
+
)
|
44
|
+
}
|
45
|
+
|
46
|
+
if (!submitBubbles) {
|
47
|
+
// discover forms on the page by observing focus events which always bubble
|
48
|
+
document.on('focusin', 'form', function(focusEvent, form) {
|
49
|
+
// special handler for the real "submit" event (one-time operation)
|
50
|
+
if (!form.retrieve('emulated:submit')) {
|
51
|
+
form.on('submit', function(submitEvent) {
|
52
|
+
var emulated = form.fire('emulated:submit', submitEvent, true)
|
53
|
+
// if custom event received preventDefault, cancel the real one too
|
54
|
+
if (emulated.returnValue === false) submitEvent.preventDefault()
|
55
|
+
})
|
56
|
+
form.store('emulated:submit', true)
|
57
|
+
}
|
58
|
+
})
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!changeBubbles) {
|
62
|
+
// discover form inputs on the page
|
63
|
+
document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
|
64
|
+
// special handler for real "change" events
|
65
|
+
if (!input.retrieve('emulated:change')) {
|
66
|
+
input.on('change', function(changeEvent) {
|
67
|
+
input.fire('emulated:change', changeEvent, true)
|
68
|
+
})
|
69
|
+
input.store('emulated:change', true)
|
70
|
+
}
|
71
|
+
})
|
72
|
+
}
|
73
|
+
|
74
|
+
function handleRemote(element) {
|
75
|
+
var method, url, params;
|
76
|
+
|
77
|
+
var event = element.fire("ajax:before");
|
78
|
+
if (event.stopped) return false;
|
79
|
+
|
80
|
+
if (element.tagName.toLowerCase() === 'form') {
|
81
|
+
method = element.readAttribute('method') || 'post';
|
82
|
+
url = element.readAttribute('action');
|
83
|
+
params = element.serialize();
|
84
|
+
} else {
|
85
|
+
method = element.readAttribute('data-method') || 'get';
|
86
|
+
url = element.readAttribute('href');
|
87
|
+
params = {};
|
88
|
+
}
|
89
|
+
|
90
|
+
new Ajax.Request(url, {
|
91
|
+
method: method,
|
92
|
+
parameters: params,
|
93
|
+
evalScripts: true,
|
94
|
+
|
95
|
+
onComplete: function(request) { element.fire("ajax:complete", request); },
|
96
|
+
onSuccess: function(request) { element.fire("ajax:success", request); },
|
97
|
+
onFailure: function(request) { element.fire("ajax:failure", request); }
|
98
|
+
});
|
99
|
+
|
100
|
+
element.fire("ajax:after");
|
101
|
+
}
|
102
|
+
|
103
|
+
function handleMethod(element) {
|
104
|
+
var method = element.readAttribute('data-method'),
|
105
|
+
url = element.readAttribute('href'),
|
106
|
+
csrf_param = $$('meta[name=csrf-param]')[0],
|
107
|
+
csrf_token = $$('meta[name=csrf-token]')[0];
|
108
|
+
|
109
|
+
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
110
|
+
element.parentNode.insert(form);
|
111
|
+
|
112
|
+
if (method !== 'post') {
|
113
|
+
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
|
114
|
+
form.insert(field);
|
115
|
+
}
|
116
|
+
|
117
|
+
if (csrf_param) {
|
118
|
+
var param = csrf_param.readAttribute('content'),
|
119
|
+
token = csrf_token.readAttribute('content'),
|
120
|
+
field = new Element('input', { type: 'hidden', name: param, value: token });
|
121
|
+
form.insert(field);
|
122
|
+
}
|
123
|
+
|
124
|
+
form.submit();
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
document.on("click", "*[data-confirm]", function(event, element) {
|
129
|
+
var message = element.readAttribute('data-confirm');
|
130
|
+
if (!confirm(message)) event.stop();
|
131
|
+
});
|
132
|
+
|
133
|
+
document.on("click", "a[data-remote]", function(event, element) {
|
134
|
+
if (event.stopped) return;
|
135
|
+
handleRemote(element);
|
136
|
+
event.stop();
|
137
|
+
});
|
138
|
+
|
139
|
+
document.on("click", "a[data-method]", function(event, element) {
|
140
|
+
if (event.stopped) return;
|
141
|
+
handleMethod(element);
|
142
|
+
event.stop();
|
143
|
+
});
|
144
|
+
|
145
|
+
document.on("submit", function(event) {
|
146
|
+
var element = event.findElement(),
|
147
|
+
message = element.readAttribute('data-confirm');
|
148
|
+
if (message && !confirm(message)) {
|
149
|
+
event.stop();
|
150
|
+
return false;
|
151
|
+
}
|
152
|
+
|
153
|
+
var inputs = element.select("input[type=submit][data-disable-with]");
|
154
|
+
inputs.each(function(input) {
|
155
|
+
input.disabled = true;
|
156
|
+
input.writeAttribute('data-original-value', input.value);
|
157
|
+
input.value = input.readAttribute('data-disable-with');
|
158
|
+
});
|
159
|
+
|
160
|
+
var element = event.findElement("form[data-remote]");
|
161
|
+
if (element) {
|
162
|
+
handleRemote(element);
|
163
|
+
event.stop();
|
164
|
+
}
|
165
|
+
});
|
166
|
+
|
167
|
+
document.on("ajax:after", "form", function(event, element) {
|
168
|
+
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
|
169
|
+
inputs.each(function(input) {
|
170
|
+
input.value = input.readAttribute('data-original-value');
|
171
|
+
input.removeAttribute('data-original-value');
|
172
|
+
input.disabled = false;
|
173
|
+
});
|
174
|
+
});
|
175
|
+
|
176
|
+
Ajax.Responders.register({
|
177
|
+
onCreate: function(request) {
|
178
|
+
var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
|
179
|
+
|
180
|
+
if (csrf_meta_tag) {
|
181
|
+
var header = 'X-CSRF-Token',
|
182
|
+
token = csrf_meta_tag.readAttribute('content');
|
183
|
+
|
184
|
+
if (!request.options.requestHeaders) {
|
185
|
+
request.options.requestHeaders = {};
|
186
|
+
}
|
187
|
+
request.options.requestHeaders[header] = token;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
});
|
191
|
+
})();
|
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Silvermoon::ActionControllerExtension do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
ActionController::Base.send :include, subject
|
7
|
+
@controller = ActionController::Base.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "adds notifiers to controller notifiers" do
|
11
|
+
ActionController::Base.notifies :facebook, :twitter
|
12
|
+
@controller.controller_notifiers.should == [:facebook, :twitter]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should notify with controller specified notifiers" do
|
16
|
+
ActionController::Base.notifies :facebook
|
17
|
+
|
18
|
+
with_config_file(STUB_CONFIG) do
|
19
|
+
Silvermoon.should_receive(:notify).with('title', 'content', 'url', {}, [:facebook])
|
20
|
+
end
|
21
|
+
|
22
|
+
@controller.notify 'title', 'content', 'url'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should notify with all specified notifiers if no notifiers are defined" do
|
26
|
+
with_config_file(STUB_CONFIG) do
|
27
|
+
ActionController::Base.notifies nil
|
28
|
+
|
29
|
+
Silvermoon.should_receive(:notify).with('title', 'content', 'url', {}, [])
|
30
|
+
|
31
|
+
@controller.notify 'title', 'content', 'url'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should override controller specified notifiers if passed on notify" do
|
36
|
+
ActionController::Base.notifies :facebook
|
37
|
+
|
38
|
+
with_config_file(STUB_CONFIG) do
|
39
|
+
Silvermoon.should_receive(:notify).with('title', 'content', 'url', {}, :twitter)
|
40
|
+
|
41
|
+
@controller.notify 'title', 'content', 'url', {}, :twitter
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Silvermoon::Notifier::Base do
|
4
|
+
|
5
|
+
it { should respond_to(:identifier) }
|
6
|
+
|
7
|
+
it "should raise NotImplementedError on notify method" do
|
8
|
+
lambda { Silvermoon::Notifier::Base.new.notify('title', 'content', 'url') }.should raise_error(NotImplementedError)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should read the configuration for his class" do
|
12
|
+
with_config_file(STUB_CONFIG) do
|
13
|
+
notifier = Silvermoon::Notifier::Twitter.new
|
14
|
+
notifier.identifier = :twitter
|
15
|
+
notifier.config.should == STUB_CONFIG[:twitter]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Silvermoon::Notifier do
|
4
|
+
it "should be valid" do
|
5
|
+
Silvermoon::Notifier.should be_a(Module)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should define the base class" do
|
9
|
+
Silvermoon::Notifier.const_defined?('Base').should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it { should respond_to(:config) }
|
13
|
+
|
14
|
+
it "should read the config file from config/silvermoon.yml" do
|
15
|
+
hash = STUB_CONFIG
|
16
|
+
with_config_file(hash) do
|
17
|
+
Silvermoon::Notifier.config.should == hash
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Silvermoon do
|
4
|
+
it "should be valid" do
|
5
|
+
Silvermoon.should be_a(Module)
|
6
|
+
end
|
7
|
+
|
8
|
+
it { should respond_to(:notify) }
|
9
|
+
|
10
|
+
it "should notify the loaded notifiers" do
|
11
|
+
title = 'title'; content = 'content'; url = 'url'
|
12
|
+
|
13
|
+
Silvermoon.loaded_notifiers.each do |notifier|
|
14
|
+
notifier.should_receive(:notify).with(title, content, url, {})
|
15
|
+
end
|
16
|
+
|
17
|
+
ret = Silvermoon.notify(title, content, url)
|
18
|
+
ret.should be_a(Hash)
|
19
|
+
ret.keys.should == [ :facebook, :twitter ]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should add notifiers as symbols" do
|
23
|
+
Silvermoon.clear_notifiers!
|
24
|
+
Silvermoon.add_notifier(:twitter)
|
25
|
+
Silvermoon.loaded_notifiers[:twitter].should be_a(Silvermoon::Notifier::Twitter)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should load a notifier by it's symbol" do
|
29
|
+
Silvermoon.load_notifier(:twitter).should be_a(Silvermoon::Notifier::Twitter)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should clear its loaded notifiers" do
|
33
|
+
Silvermoon.add_notifier(:twitter)
|
34
|
+
Silvermoon.clear_notifiers!
|
35
|
+
Silvermoon.loaded_notifiers.should == {}
|
36
|
+
end
|
37
|
+
|
38
|
+
# it "should have a setup method that accepts a block for configuration" do
|
39
|
+
# Silvermoon.should_receive(:add_notifier).with(:twitter)
|
40
|
+
#
|
41
|
+
# Silvermoon.setup do
|
42
|
+
# add_notifier :twitter
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Configure Rails Envinronment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
require "rspec/rails"
|
7
|
+
|
8
|
+
ActionMailer::Base.delivery_method = :test
|
9
|
+
ActionMailer::Base.perform_deliveries = true
|
10
|
+
ActionMailer::Base.default_url_options[:host] = "test.com"
|
11
|
+
|
12
|
+
Rails.backtrace_cleaner.remove_silencers!
|
13
|
+
|
14
|
+
# Configure capybara for integration testing
|
15
|
+
require "capybara/rails"
|
16
|
+
Capybara.default_driver = :rack_test
|
17
|
+
Capybara.default_selector = :css
|
18
|
+
|
19
|
+
# Run any available migration
|
20
|
+
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
|
21
|
+
|
22
|
+
# Load support files
|
23
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
# Remove this line if you don't want RSpec's should and should_not
|
27
|
+
# methods or matchers
|
28
|
+
require 'rspec/expectations'
|
29
|
+
config.include RSpec::Matchers
|
30
|
+
config.include ConfigHelpers
|
31
|
+
|
32
|
+
# == Mock Framework
|
33
|
+
config.mock_with :rspec
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails'
|
2
|
+
module ConfigHelpers
|
3
|
+
def with_config_file(hash, &block)
|
4
|
+
#Silvermoon::Notifier.stub!(:config_file_path).and_return('spec/dummy/config/silvermoon.yml')
|
5
|
+
hash = { :test => hash }
|
6
|
+
File.open("#{Rails.root}/config/silvermoon.yml", 'w') do |f|
|
7
|
+
f.write hash.to_yaml
|
8
|
+
end
|
9
|
+
|
10
|
+
Silvermoon::Notifier.reload_config!
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
end
|