Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Don't hack me

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

0 comments on commit ba238f8

Please sign in to comment.
Something went wrong with that request. Please try again.