Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't hack me

  • Loading branch information...
commit ba238f88edabf3dda59a40bd5146464e2174cb87 1 parent 069430f
@nakajima authored
View
3  app/helpers/application_helper.rb
@@ -1,3 +1,6 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
+ def title(name)
+ content_for(:title) { h(name) }
+ end
end
View
12 app/models/bookmarklet.rb
@@ -1,17 +1,17 @@
class Bookmarklet < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :code
- validate :spam_check, :if => :spam?
+ validate :spam_check
- attr_accessor :body # This is for spam detection
+ default_scope :conditions => { :spam => false }
- def spam?
- @body || SpamChecker.new(code).spam?
- end
+ attr_accessor :body # This is for spam detection
private
def spam_check
- errors.add(:spam, "detection failed.")
+ if self.spam = @body || SpamChecker.new(code).spam?
+ errors.add(:spam, "detection failed.")
+ end
end
end
View
2  app/views/bookmarklets/edit.html.erb
@@ -1,3 +1,5 @@
+<% title "Editing #{@bookmarklet.name}" %>
+
<h1>Editing bookmarklet</h1>
<% form_for(@bookmarklet) do |f| %>
View
4 app/views/bookmarklets/index.html.erb
@@ -1,9 +1,11 @@
+<% title "All of ’em" %>
+
<h1 id="main-title">Bookmarklet Factory</h1>
<%= link_to 'Click Here to Create One.', new_bookmarklet_path, :id => 'new-link' %>
<div id="the-list">
Or View Existing:
<%- @bookmarklets.each do |bookmarklet| -%>
- <%= link_to bookmarklet.name, bookmarklet %>
+ <%= link_to h(bookmarklet.name), bookmarklet %>
<%- end -%>
</div>
View
4 app/views/bookmarklets/login.html.erb
@@ -1,5 +1,7 @@
+<% title "Login Please" %>
+
<% form_tag authorize_bookmarklet_path(@bookmarklet), :method => :post do %>
- Enter the password for <%= @bookmarklet.name %>:<br>
+ Enter the password for <%= h(@bookmarklet.name) %>:<br>
<%= text_field_tag :password %>
<%= submit_tag 'Authorize' %>
<% end %>
View
2  app/views/bookmarklets/new.html.erb
@@ -1,3 +1,5 @@
+<% title "Add a bookmarklet" %>
+
<h1>New bookmarklet</h1>
<% form_for(@bookmarklet) do |f| %>
View
6 app/views/bookmarklets/show.html.erb
@@ -1,3 +1,5 @@
+<% title @bookmarklet.name %>
+
Drag this to your Bookmarks Bar:
<strong>
<a href="javascript:var%20d=document,z=d.createElement('scr'+'ipt'),b=d.body;try{if(!b)throw(0);z.setAttribute('src','<%= request.protocol + request.host + url_for(@bookmarklet) + '.js' %>');b.appendChild(z);}catch(e){alert('Please%20wait%20until%20the%20page%20has%20loaded.');}void(0)"><%= @bookmarklet.name %></a>
@@ -5,12 +7,12 @@ Drag this to your Bookmarks Bar:
<br>
-<blockquote><%= @bookmarklet.description %></blockquote>
+<blockquote><%= h(@bookmarklet.description) %></blockquote>
<%= link_to_function 'View Source', '$("source").toggle()' %>
<div id="source" style="display:none">
- <pre><%= CGI.escapeHTML(@bookmarklet.code) %></pre>
+ <pre><%= h(@bookmarklet.code) %></pre>
</div>
<br>
View
2  app/views/layouts/bookmarklets.html.erb
@@ -4,7 +4,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
- <title>Bookmarklets: <%= controller.action_name %></title>
+ <title>Bookmarklets: <%= yield :title %></title>
<%= stylesheet_link_tag 'styles' %>
<%= javascript_include_tag 'prototype' %>
</head>
View
9 db/migrate/20100522134227_add_spam_to_bookmarklets.rb
@@ -0,0 +1,9 @@
+class AddSpamToBookmarklets < ActiveRecord::Migration
+ def self.up
+ add_column :bookmarklets, :spam, :boolean, :default => false
+ end
+
+ def self.down
+ remove_column :bookmarklets, :spam
+ end
+end
View
3  db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20091114003903) do
+ActiveRecord::Schema.define(:version => 20100522134227) do
create_table "bookmarklets", :force => true do |t|
t.string "name"
@@ -19,6 +19,7 @@
t.datetime "updated_at"
t.text "description"
t.string "password"
+ t.boolean "spam", :default => false
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.