Skip to content
This repository
Browse code

adding episode 272

  • Loading branch information...
commit 1e477d1f2e65c984364eb97a72717976e01c6672 1 parent efa0609
Ryan Bates authored

Showing 120 changed files with 20,192 additions and 0 deletions. Show diff stats Hide diff stats

  1. +8 0 episode-272/README
  2. +4 0 episode-272/blog-after/.gitignore
  3. +9 0 episode-272/blog-after/Gemfile
  4. +85 0 episode-272/blog-after/Gemfile.lock
  5. +7 0 episode-272/blog-after/README
  6. +7 0 episode-272/blog-after/Rakefile
  7. +3 0  episode-272/blog-after/app/controllers/application_controller.rb
  8. +41 0 episode-272/blog-after/app/controllers/articles_controller.rb
  9. +14 0 episode-272/blog-after/app/helpers/application_helper.rb
  10. +2 0  episode-272/blog-after/app/helpers/articles_helper.rb
  11. +23 0 episode-272/blog-after/app/helpers/error_messages_helper.rb
  12. +22 0 episode-272/blog-after/app/helpers/layout_helper.rb
  13. +3 0  episode-272/blog-after/app/models/article.rb
  14. +12 0 episode-272/blog-after/app/views/articles/_form.html.erb
  15. +8 0 episode-272/blog-after/app/views/articles/edit.html.erb
  16. +8 0 episode-272/blog-after/app/views/articles/index.html.erb
  17. +5 0 episode-272/blog-after/app/views/articles/new.html.erb
  18. +9 0 episode-272/blog-after/app/views/articles/show.html.erb
  19. +19 0 episode-272/blog-after/app/views/layouts/application.html.erb
  20. +4 0 episode-272/blog-after/config.ru
  21. +42 0 episode-272/blog-after/config/application.rb
  22. +6 0 episode-272/blog-after/config/boot.rb
  23. +22 0 episode-272/blog-after/config/database.yml
  24. +5 0 episode-272/blog-after/config/environment.rb
  25. +25 0 episode-272/blog-after/config/environments/development.rb
  26. +49 0 episode-272/blog-after/config/environments/production.rb
  27. +35 0 episode-272/blog-after/config/environments/test.rb
  28. +7 0 episode-272/blog-after/config/initializers/backtrace_silencers.rb
  29. +10 0 episode-272/blog-after/config/initializers/inflections.rb
  30. +5 0 episode-272/blog-after/config/initializers/mime_types.rb
  31. +7 0 episode-272/blog-after/config/initializers/secret_token.rb
  32. +8 0 episode-272/blog-after/config/initializers/session_store.rb
  33. +5 0 episode-272/blog-after/config/locales/en.yml
  34. +4 0 episode-272/blog-after/config/routes.rb
  35. +13 0 episode-272/blog-after/db/migrate/20110627034728_create_articles.rb
  36. +22 0 episode-272/blog-after/db/schema.rb
  37. +7 0 episode-272/blog-after/db/seeds.rb
  38. +2 0  episode-272/blog-after/doc/README_FOR_APP
  39. 0  episode-272/blog-after/lib/tasks/.gitkeep
  40. +26 0 episode-272/blog-after/public/404.html
  41. +26 0 episode-272/blog-after/public/422.html
  42. +26 0 episode-272/blog-after/public/500.html
  43. 0  episode-272/blog-after/public/favicon.ico
  44. BIN  episode-272/blog-after/public/images/rails.png
  45. +2 0  episode-272/blog-after/public/javascripts/application.js
  46. +965 0 episode-272/blog-after/public/javascripts/controls.js
  47. +974 0 episode-272/blog-after/public/javascripts/dragdrop.js
  48. +1,123 0 episode-272/blog-after/public/javascripts/effects.js
  49. +6,001 0 episode-272/blog-after/public/javascripts/prototype.js
  50. +191 0 episode-272/blog-after/public/javascripts/rails.js
  51. +5 0 episode-272/blog-after/public/robots.txt
  52. 0  episode-272/blog-after/public/stylesheets/.gitkeep
  53. +82 0 episode-272/blog-after/public/stylesheets/application.css
  54. +61 0 episode-272/blog-after/public/stylesheets/pygments.css
  55. +6 0 episode-272/blog-after/script/rails
  56. +7 0 episode-272/blog-after/test/fixtures/articles.yml
  57. +54 0 episode-272/blog-after/test/functional/articles_controller_test.rb
  58. +9 0 episode-272/blog-after/test/performance/browsing_test.rb
  59. +13 0 episode-272/blog-after/test/test_helper.rb
  60. +7 0 episode-272/blog-after/test/unit/article_test.rb
  61. 0  episode-272/blog-after/vendor/plugins/.gitkeep
  62. +4 0 episode-272/blog-before/.gitignore
  63. +5 0 episode-272/blog-before/Gemfile
  64. +79 0 episode-272/blog-before/Gemfile.lock
  65. +7 0 episode-272/blog-before/README
  66. +7 0 episode-272/blog-before/Rakefile
  67. +3 0  episode-272/blog-before/app/controllers/application_controller.rb
  68. +41 0 episode-272/blog-before/app/controllers/articles_controller.rb
  69. +2 0  episode-272/blog-before/app/helpers/application_helper.rb
  70. +2 0  episode-272/blog-before/app/helpers/articles_helper.rb
  71. +23 0 episode-272/blog-before/app/helpers/error_messages_helper.rb
  72. +22 0 episode-272/blog-before/app/helpers/layout_helper.rb
  73. +3 0  episode-272/blog-before/app/models/article.rb
  74. +12 0 episode-272/blog-before/app/views/articles/_form.html.erb
  75. +8 0 episode-272/blog-before/app/views/articles/edit.html.erb
  76. +8 0 episode-272/blog-before/app/views/articles/index.html.erb
  77. +5 0 episode-272/blog-before/app/views/articles/new.html.erb
  78. +9 0 episode-272/blog-before/app/views/articles/show.html.erb
  79. +19 0 episode-272/blog-before/app/views/layouts/application.html.erb
  80. +4 0 episode-272/blog-before/config.ru
  81. +42 0 episode-272/blog-before/config/application.rb
  82. +6 0 episode-272/blog-before/config/boot.rb
  83. +22 0 episode-272/blog-before/config/database.yml
  84. +5 0 episode-272/blog-before/config/environment.rb
  85. +25 0 episode-272/blog-before/config/environments/development.rb
  86. +49 0 episode-272/blog-before/config/environments/production.rb
  87. +35 0 episode-272/blog-before/config/environments/test.rb
  88. +7 0 episode-272/blog-before/config/initializers/backtrace_silencers.rb
  89. +10 0 episode-272/blog-before/config/initializers/inflections.rb
  90. +5 0 episode-272/blog-before/config/initializers/mime_types.rb
  91. +7 0 episode-272/blog-before/config/initializers/secret_token.rb
  92. +8 0 episode-272/blog-before/config/initializers/session_store.rb
  93. +5 0 episode-272/blog-before/config/locales/en.yml
  94. +4 0 episode-272/blog-before/config/routes.rb
  95. +13 0 episode-272/blog-before/db/migrate/20110627034728_create_articles.rb
  96. +22 0 episode-272/blog-before/db/schema.rb
  97. +7 0 episode-272/blog-before/db/seeds.rb
  98. +2 0  episode-272/blog-before/doc/README_FOR_APP
  99. 0  episode-272/blog-before/lib/tasks/.gitkeep
  100. +26 0 episode-272/blog-before/public/404.html
  101. +26 0 episode-272/blog-before/public/422.html
  102. +26 0 episode-272/blog-before/public/500.html
  103. 0  episode-272/blog-before/public/favicon.ico
  104. BIN  episode-272/blog-before/public/images/rails.png
  105. +2 0  episode-272/blog-before/public/javascripts/application.js
  106. +965 0 episode-272/blog-before/public/javascripts/controls.js
  107. +974 0 episode-272/blog-before/public/javascripts/dragdrop.js
  108. +1,123 0 episode-272/blog-before/public/javascripts/effects.js
  109. +6,001 0 episode-272/blog-before/public/javascripts/prototype.js
  110. +191 0 episode-272/blog-before/public/javascripts/rails.js
  111. +5 0 episode-272/blog-before/public/robots.txt
  112. 0  episode-272/blog-before/public/stylesheets/.gitkeep
  113. +75 0 episode-272/blog-before/public/stylesheets/application.css
  114. +6 0 episode-272/blog-before/script/rails
  115. +7 0 episode-272/blog-before/test/fixtures/articles.yml
  116. +54 0 episode-272/blog-before/test/functional/articles_controller_test.rb
  117. +9 0 episode-272/blog-before/test/performance/browsing_test.rb
  118. +13 0 episode-272/blog-before/test/test_helper.rb
  119. +7 0 episode-272/blog-before/test/unit/article_test.rb
  120. 0  episode-272/blog-before/vendor/plugins/.gitkeep
8 episode-272/README
... ... @@ -0,0 +1,8 @@
  1 +RailsCasts Episode #272: Markdown with Redcarpet
  2 +
  3 +http://railscasts.com/episodes/272-markdown-with-redcarpet
  4 +
  5 +Commands used in episode
  6 +
  7 + bundle
  8 + sudo easy_install pygments
4 episode-272/blog-after/.gitignore
... ... @@ -0,0 +1,4 @@
  1 +.bundle
  2 +db/*.sqlite3
  3 +log/*.log
  4 +tmp/
9 episode-272/blog-after/Gemfile
... ... @@ -0,0 +1,9 @@
  1 +source 'http://rubygems.org'
  2 +
  3 +gem 'rails', '3.0.9'
  4 +gem 'sqlite3'
  5 +gem 'nifty-generators'
  6 +
  7 +gem 'redcarpet'
  8 +gem 'albino'
  9 +gem 'nokogiri'
85 episode-272/blog-after/Gemfile.lock
... ... @@ -0,0 +1,85 @@
  1 +GEM
  2 + remote: http://rubygems.org/
  3 + specs:
  4 + abstract (1.0.0)
  5 + actionmailer (3.0.9)
  6 + actionpack (= 3.0.9)
  7 + mail (~> 2.2.19)
  8 + actionpack (3.0.9)
  9 + activemodel (= 3.0.9)
  10 + activesupport (= 3.0.9)
  11 + builder (~> 2.1.2)
  12 + erubis (~> 2.6.6)
  13 + i18n (~> 0.5.0)
  14 + rack (~> 1.2.1)
  15 + rack-mount (~> 0.6.14)
  16 + rack-test (~> 0.5.7)
  17 + tzinfo (~> 0.3.23)
  18 + activemodel (3.0.9)
  19 + activesupport (= 3.0.9)
  20 + builder (~> 2.1.2)
  21 + i18n (~> 0.5.0)
  22 + activerecord (3.0.9)
  23 + activemodel (= 3.0.9)
  24 + activesupport (= 3.0.9)
  25 + arel (~> 2.0.10)
  26 + tzinfo (~> 0.3.23)
  27 + activeresource (3.0.9)
  28 + activemodel (= 3.0.9)
  29 + activesupport (= 3.0.9)
  30 + activesupport (3.0.9)
  31 + albino (1.3.3)
  32 + posix-spawn (>= 0.3.6)
  33 + arel (2.0.10)
  34 + builder (2.1.2)
  35 + erubis (2.6.6)
  36 + abstract (>= 1.0.0)
  37 + i18n (0.5.0)
  38 + mail (2.2.19)
  39 + activesupport (>= 2.3.6)
  40 + i18n (>= 0.4.0)
  41 + mime-types (~> 1.16)
  42 + treetop (~> 1.4.8)
  43 + mime-types (1.16)
  44 + nifty-generators (0.4.6)
  45 + nokogiri (1.4.6)
  46 + polyglot (0.3.1)
  47 + posix-spawn (0.3.6)
  48 + rack (1.2.3)
  49 + rack-mount (0.6.14)
  50 + rack (>= 1.0.0)
  51 + rack-test (0.5.7)
  52 + rack (>= 1.0)
  53 + rails (3.0.9)
  54 + actionmailer (= 3.0.9)
  55 + actionpack (= 3.0.9)
  56 + activerecord (= 3.0.9)
  57 + activeresource (= 3.0.9)
  58 + activesupport (= 3.0.9)
  59 + bundler (~> 1.0)
  60 + railties (= 3.0.9)
  61 + railties (3.0.9)
  62 + actionpack (= 3.0.9)
  63 + activesupport (= 3.0.9)
  64 + rake (>= 0.8.7)
  65 + rdoc (~> 3.4)
  66 + thor (~> 0.14.4)
  67 + rake (0.9.2)
  68 + rdoc (3.6.1)
  69 + redcarpet (1.17.2)
  70 + sqlite3 (1.3.3)
  71 + thor (0.14.6)
  72 + treetop (1.4.9)
  73 + polyglot (>= 0.3.1)
  74 + tzinfo (0.3.28)
  75 +
  76 +PLATFORMS
  77 + ruby
  78 +
  79 +DEPENDENCIES
  80 + albino
  81 + nifty-generators
  82 + nokogiri
  83 + rails (= 3.0.9)
  84 + redcarpet
  85 + sqlite3
7 episode-272/blog-after/README
... ... @@ -0,0 +1,7 @@
  1 += RailsCasts Example Application
  2 +
  3 +Run these commands to try it out.
  4 +
  5 + bundle
  6 + rake db:migrate
  7 + rails s
7 episode-272/blog-after/Rakefile
... ... @@ -0,0 +1,7 @@
  1 +# Add your own tasks in files placed in lib/tasks ending in .rake,
  2 +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
  3 +
  4 +require File.expand_path('../config/application', __FILE__)
  5 +require 'rake'
  6 +
  7 +Blog::Application.load_tasks
3  episode-272/blog-after/app/controllers/application_controller.rb
... ... @@ -0,0 +1,3 @@
  1 +class ApplicationController < ActionController::Base
  2 + protect_from_forgery
  3 +end
41 episode-272/blog-after/app/controllers/articles_controller.rb
... ... @@ -0,0 +1,41 @@
  1 +class ArticlesController < ApplicationController
  2 + def index
  3 + @articles = Article.all
  4 + end
  5 +
  6 + def show
  7 + @article = Article.find(params[:id])
  8 + end
  9 +
  10 + def new
  11 + @article = Article.new
  12 + end
  13 +
  14 + def create
  15 + @article = Article.new(params[:article])
  16 + if @article.save
  17 + redirect_to @article, :notice => "Successfully created article."
  18 + else
  19 + render :action => 'new'
  20 + end
  21 + end
  22 +
  23 + def edit
  24 + @article = Article.find(params[:id])
  25 + end
  26 +
  27 + def update
  28 + @article = Article.find(params[:id])
  29 + if @article.update_attributes(params[:article])
  30 + redirect_to @article, :notice => "Successfully updated article."
  31 + else
  32 + render :action => 'edit'
  33 + end
  34 + end
  35 +
  36 + def destroy
  37 + @article = Article.find(params[:id])
  38 + @article.destroy
  39 + redirect_to articles_url, :notice => "Successfully destroyed article."
  40 + end
  41 +end
14 episode-272/blog-after/app/helpers/application_helper.rb
... ... @@ -0,0 +1,14 @@
  1 +module ApplicationHelper
  2 + def markdown(text)
  3 + options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode]
  4 + syntax_highlighter(Redcarpet.new(text, *options).to_html).html_safe
  5 + end
  6 +
  7 + def syntax_highlighter(html)
  8 + doc = Nokogiri::HTML(html)
  9 + doc.search("//pre[@lang]").each do |pre|
  10 + pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
  11 + end
  12 + doc.to_s
  13 + end
  14 +end
2  episode-272/blog-after/app/helpers/articles_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module ArticlesHelper
  2 +end
23 episode-272/blog-after/app/helpers/error_messages_helper.rb
... ... @@ -0,0 +1,23 @@
  1 +module ErrorMessagesHelper
  2 + # Render error messages for the given objects. The :message and :header_message options are allowed.
  3 + def error_messages_for(*objects)
  4 + options = objects.extract_options!
  5 + options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
  6 + options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
  7 + messages = objects.compact.map { |o| o.errors.full_messages }.flatten
  8 + unless messages.empty?
  9 + content_tag(:div, :class => "error_messages") do
  10 + list_items = messages.map { |msg| content_tag(:li, msg) }
  11 + content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
  12 + end
  13 + end
  14 + end
  15 +
  16 + module FormBuilderAdditions
  17 + def error_messages(options = {})
  18 + @template.error_messages_for(@object, options)
  19 + end
  20 + end
  21 +end
  22 +
  23 +ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
22 episode-272/blog-after/app/helpers/layout_helper.rb
... ... @@ -0,0 +1,22 @@
  1 +# These helper methods can be called in your template to set variables to be used in the layout
  2 +# This module should be included in all views globally,
  3 +# to do so you may need to add this line to your ApplicationController
  4 +# helper :layout
  5 +module LayoutHelper
  6 + def title(page_title, show_title = true)
  7 + content_for(:title) { h(page_title.to_s) }
  8 + @show_title = show_title
  9 + end
  10 +
  11 + def show_title?
  12 + @show_title
  13 + end
  14 +
  15 + def stylesheet(*args)
  16 + content_for(:head) { stylesheet_link_tag(*args) }
  17 + end
  18 +
  19 + def javascript(*args)
  20 + content_for(:head) { javascript_include_tag(*args) }
  21 + end
  22 +end
3  episode-272/blog-after/app/models/article.rb
... ... @@ -0,0 +1,3 @@
  1 +class Article < ActiveRecord::Base
  2 + attr_accessible :name, :content
  3 +end
12 episode-272/blog-after/app/views/articles/_form.html.erb
... ... @@ -0,0 +1,12 @@
  1 +<%= form_for @article do |f| %>
  2 + <%= f.error_messages %>
  3 + <p>
  4 + <%= f.label :name %><br />
  5 + <%= f.text_field :name %>
  6 + </p>
  7 + <p>
  8 + <%= f.label :content %><br />
  9 + <%= f.text_area :content %>
  10 + </p>
  11 + <p><%= f.submit %></p>
  12 +<% end %>
8 episode-272/blog-after/app/views/articles/edit.html.erb
... ... @@ -0,0 +1,8 @@
  1 +<% title "Edit Article" %>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<p>
  6 + <%= link_to "Show", @article %> |
  7 + <%= link_to "View All", articles_path %>
  8 +</p>
8 episode-272/blog-after/app/views/articles/index.html.erb
... ... @@ -0,0 +1,8 @@
  1 +<% title "Articles" %>
  2 +
  3 +<% for article in @articles %>
  4 + <h2><%= link_to article.name, article %></h2>
  5 + <p><%= article.content %></p>
  6 +<% end %>
  7 +
  8 +<p><%= link_to "New Article", new_article_path %></p>
5 episode-272/blog-after/app/views/articles/new.html.erb
... ... @@ -0,0 +1,5 @@
  1 +<% title "New Article" %>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<p><%= link_to "Back to List", articles_path %></p>
9 episode-272/blog-after/app/views/articles/show.html.erb
... ... @@ -0,0 +1,9 @@
  1 +<% title @article.name %>
  2 +
  3 +<%= markdown(@article.content) %>
  4 +
  5 +<p>
  6 + <%= link_to "Edit", edit_article_path(@article) %> |
  7 + <%= link_to "Destroy", @article, :confirm => 'Are you sure?', :method => :delete %> |
  8 + <%= link_to "View All", articles_path %>
  9 +</p>
19 episode-272/blog-after/app/views/layouts/application.html.erb
... ... @@ -0,0 +1,19 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 + <head>
  4 + <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
  5 + <%= stylesheet_link_tag "application", "pygments" %>
  6 + <%= javascript_include_tag :defaults %>
  7 + <%= csrf_meta_tag %>
  8 + <%= yield(:head) %>
  9 + </head>
  10 + <body>
  11 + <div id="container">
  12 + <% flash.each do |name, msg| %>
  13 + <%= content_tag :div, msg, :id => "flash_#{name}" %>
  14 + <% end %>
  15 + <%= content_tag :h1, yield(:title) if show_title? %>
  16 + <%= yield %>
  17 + </div>
  18 + </body>
  19 +</html>
4 episode-272/blog-after/config.ru
... ... @@ -0,0 +1,4 @@
  1 +# This file is used by Rack-based servers to start the application.
  2 +
  3 +require ::File.expand_path('../config/environment', __FILE__)
  4 +run Blog::Application
42 episode-272/blog-after/config/application.rb
... ... @@ -0,0 +1,42 @@
  1 +require File.expand_path('../boot', __FILE__)
  2 +
  3 +require 'rails/all'
  4 +
  5 +# If you have a Gemfile, require the gems listed there, including any gems
  6 +# you've limited to :test, :development, or :production.
  7 +Bundler.require(:default, Rails.env) if defined?(Bundler)
  8 +
  9 +module Blog
  10 + class Application < Rails::Application
  11 + # Settings in config/environments/* take precedence over those specified here.
  12 + # Application configuration should go into files in config/initializers
  13 + # -- all .rb files in that directory are automatically loaded.
  14 +
  15 + # Custom directories with classes and modules you want to be autoloadable.
  16 + # config.autoload_paths += %W(#{config.root}/extras)
  17 +
  18 + # Only load the plugins named here, in the order given (default is alphabetical).
  19 + # :all can be used as a placeholder for all plugins not explicitly named.
  20 + # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
  21 +
  22 + # Activate observers that should always be running.
  23 + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
  24 +
  25 + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
  26 + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
  27 + # config.time_zone = 'Central Time (US & Canada)'
  28 +
  29 + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
  30 + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
  31 + # config.i18n.default_locale = :de
  32 +
  33 + # JavaScript files you want as :defaults (application.js is always included).
  34 + # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
  35 +
  36 + # Configure the default encoding used in templates for Ruby 1.9.
  37 + config.encoding = "utf-8"
  38 +
  39 + # Configure sensitive parameters which will be filtered from the log file.
  40 + config.filter_parameters += [:password]
  41 + end
  42 +end
6 episode-272/blog-after/config/boot.rb
... ... @@ -0,0 +1,6 @@
  1 +require 'rubygems'
  2 +
  3 +# Set up gems listed in the Gemfile.
  4 +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
  5 +
  6 +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
22 episode-272/blog-after/config/database.yml
... ... @@ -0,0 +1,22 @@
  1 +# SQLite version 3.x
  2 +# gem install sqlite3
  3 +development:
  4 + adapter: sqlite3
  5 + database: db/development.sqlite3
  6 + pool: 5
  7 + timeout: 5000
  8 +
  9 +# Warning: The database defined as "test" will be erased and
  10 +# re-generated from your development database when you run "rake".
  11 +# Do not set this db to the same as development or production.
  12 +test:
  13 + adapter: sqlite3
  14 + database: db/test.sqlite3
  15 + pool: 5
  16 + timeout: 5000
  17 +
  18 +production:
  19 + adapter: sqlite3
  20 + database: db/production.sqlite3
  21 + pool: 5
  22 + timeout: 5000
5 episode-272/blog-after/config/environment.rb
... ... @@ -0,0 +1,5 @@
  1 +# Load the rails application
  2 +require File.expand_path('../application', __FILE__)
  3 +
  4 +# Initialize the rails application
  5 +Blog::Application.initialize!
25 episode-272/blog-after/config/environments/development.rb
... ... @@ -0,0 +1,25 @@
  1 +Blog::Application.configure do
  2 + # Settings specified here will take precedence over those in config/application.rb
  3 +
  4 + # In the development environment your application's code is reloaded on
  5 + # every request. This slows down response time but is perfect for development
  6 + # since you don't have to restart the webserver when you make code changes.
  7 + config.cache_classes = false
  8 +
  9 + # Log error messages when you accidentally call methods on nil.
  10 + config.whiny_nils = true
  11 +
  12 + # Show full error reports and disable caching
  13 + config.consider_all_requests_local = true
  14 + config.action_controller.perform_caching = false
  15 +
  16 + # Don't care if the mailer can't send
  17 + config.action_mailer.raise_delivery_errors = false
  18 +
  19 + # Print deprecation notices to the Rails logger
  20 + config.active_support.deprecation = :log
  21 +
  22 + # Only use best-standards-support built into browsers
  23 + config.action_dispatch.best_standards_support = :builtin
  24 +end
  25 +
49 episode-272/blog-after/config/environments/production.rb
... ... @@ -0,0 +1,49 @@
  1 +Blog::Application.configure do
  2 + # Settings specified here will take precedence over those in config/application.rb
  3 +
  4 + # The production environment is meant for finished, "live" apps.
  5 + # Code is not reloaded between requests
  6 + config.cache_classes = true
  7 +
  8 + # Full error reports are disabled and caching is turned on
  9 + config.consider_all_requests_local = false
  10 + config.action_controller.perform_caching = true
  11 +
  12 + # Specifies the header that your server uses for sending files
  13 + config.action_dispatch.x_sendfile_header = "X-Sendfile"
  14 +
  15 + # For nginx:
  16 + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
  17 +
  18 + # If you have no front-end server that supports something like X-Sendfile,
  19 + # just comment this out and Rails will serve the files
  20 +
  21 + # See everything in the log (default is :info)
  22 + # config.log_level = :debug
  23 +
  24 + # Use a different logger for distributed setups
  25 + # config.logger = SyslogLogger.new
  26 +
  27 + # Use a different cache store in production
  28 + # config.cache_store = :mem_cache_store
  29 +
  30 + # Disable Rails's static asset server
  31 + # In production, Apache or nginx will already do this
  32 + config.serve_static_assets = false
  33 +
  34 + # Enable serving of images, stylesheets, and javascripts from an asset server
  35 + # config.action_controller.asset_host = "http://assets.example.com"
  36 +
  37 + # Disable delivery errors, bad email addresses will be ignored
  38 + # config.action_mailer.raise_delivery_errors = false
  39 +
  40 + # Enable threaded mode
  41 + # config.threadsafe!
  42 +
  43 + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  44 + # the I18n.default_locale when a translation can not be found)
  45 + config.i18n.fallbacks = true
  46 +
  47 + # Send deprecation notices to registered listeners
  48 + config.active_support.deprecation = :notify
  49 +end
35 episode-272/blog-after/config/environments/test.rb
... ... @@ -0,0 +1,35 @@
  1 +Blog::Application.configure do
  2 + # Settings specified here will take precedence over those in config/application.rb
  3 +
  4 + # The test environment is used exclusively to run your application's
  5 + # test suite. You never need to work with it otherwise. Remember that
  6 + # your test database is "scratch space" for the test suite and is wiped
  7 + # and recreated between test runs. Don't rely on the data there!
  8 + config.cache_classes = true
  9 +
  10 + # Log error messages when you accidentally call methods on nil.
  11 + config.whiny_nils = true
  12 +
  13 + # Show full error reports and disable caching
  14 + config.consider_all_requests_local = true
  15 + config.action_controller.perform_caching = false
  16 +
  17 + # Raise exceptions instead of rendering exception templates
  18 + config.action_dispatch.show_exceptions = false
  19 +
  20 + # Disable request forgery protection in test environment
  21 + config.action_controller.allow_forgery_protection = false
  22 +
  23 + # Tell Action Mailer not to deliver emails to the real world.
  24 + # The :test delivery method accumulates sent emails in the
  25 + # ActionMailer::Base.deliveries array.
  26 + config.action_mailer.delivery_method = :test
  27 +
  28 + # Use SQL instead of Active Record's schema dumper when creating the test database.
  29 + # This is necessary if your schema can't be completely dumped by the schema dumper,
  30 + # like if you have constraints or database-specific column types
  31 + # config.active_record.schema_format = :sql
  32 +
  33 + # Print deprecation notices to the stderr
  34 + config.active_support.deprecation = :stderr
  35 +end
7 episode-272/blog-after/config/initializers/backtrace_silencers.rb
... ... @@ -0,0 +1,7 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
  4 +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
  5 +
  6 +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
  7 +# Rails.backtrace_cleaner.remove_silencers!
10 episode-272/blog-after/config/initializers/inflections.rb
... ... @@ -0,0 +1,10 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Add new inflection rules using the following format
  4 +# (all these examples are active by default):
  5 +# ActiveSupport::Inflector.inflections do |inflect|
  6 +# inflect.plural /^(ox)$/i, '\1en'
  7 +# inflect.singular /^(ox)en/i, '\1'
  8 +# inflect.irregular 'person', 'people'
  9 +# inflect.uncountable %w( fish sheep )
  10 +# end
5 episode-272/blog-after/config/initializers/mime_types.rb
... ... @@ -0,0 +1,5 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Add new mime types for use in respond_to blocks:
  4 +# Mime::Type.register "text/richtext", :rtf
  5 +# Mime::Type.register_alias "text/html", :iphone
7 episode-272/blog-after/config/initializers/secret_token.rb
... ... @@ -0,0 +1,7 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Your secret key for verifying the integrity of signed cookies.
  4 +# If you change this key, all old signed cookies will become invalid!
  5 +# Make sure the secret is at least 30 characters and all random,
  6 +# no regular words or you'll be exposed to dictionary attacks.
  7 +Blog::Application.config.secret_token = '5ff82c9a11fbace1e0a76db3510c16ec6999326eb9802124b026c5bfdf8f2ecd8e3a0b19cabafc5df66e342b6126bf2722de34aabb73061ba8adaa155f58c401'
8 episode-272/blog-after/config/initializers/session_store.rb
... ... @@ -0,0 +1,8 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +Blog::Application.config.session_store :cookie_store, :key => '_blog_session'
  4 +
  5 +# Use the database for sessions instead of the cookie-based default,
  6 +# which shouldn't be used to store highly confidential information
  7 +# (create the session table with "rails generate session_migration")
  8 +# Blog::Application.config.session_store :active_record_store
5 episode-272/blog-after/config/locales/en.yml
... ... @@ -0,0 +1,5 @@
  1 +# Sample localization file for English. Add more files in this directory for other locales.
  2 +# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
  3 +
  4 +en:
  5 + hello: "Hello world"
4 episode-272/blog-after/config/routes.rb
... ... @@ -0,0 +1,4 @@
  1 +Blog::Application.routes.draw do
  2 + resources :articles
  3 + root :to => "articles#index"
  4 +end
13 episode-272/blog-after/db/migrate/20110627034728_create_articles.rb
... ... @@ -0,0 +1,13 @@
  1 +class CreateArticles < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :articles do |t|
  4 + t.string :name
  5 + t.text :content
  6 + t.timestamps
  7 + end
  8 + end
  9 +
  10 + def self.down
  11 + drop_table :articles
  12 + end
  13 +end
22 episode-272/blog-after/db/schema.rb
... ... @@ -0,0 +1,22 @@
  1 +# This file is auto-generated from the current state of the database. Instead
  2 +# of editing this file, please use the migrations feature of Active Record to
  3 +# incrementally modify your database, and then regenerate this schema definition.
  4 +#
  5 +# Note that this schema.rb definition is the authoritative source for your
  6 +# database schema. If you need to create the application database on another
  7 +# system, you should be using db:schema:load, not running all the migrations
  8 +# from scratch. The latter is a flawed and unsustainable approach (the more migrations
  9 +# you'll amass, the slower it'll run and the greater likelihood for issues).
  10 +#
  11 +# It's strongly recommended to check this file into your version control system.
  12 +
  13 +ActiveRecord::Schema.define(:version => 20110627034728) do
  14 +
  15 + create_table "articles", :force => true do |t|
  16 + t.string "name"
  17 + t.text "content"
  18 + t.datetime "created_at"
  19 + t.datetime "updated_at"
  20 + end
  21 +
  22 +end
7 episode-272/blog-after/db/seeds.rb
... ... @@ -0,0 +1,7 @@
  1 +# This file should contain all the record creation needed to seed the database with its default values.
  2 +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
  3 +#
  4 +# Examples:
  5 +#
  6 +# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
  7 +# Mayor.create(:name => 'Daley', :city => cities.first)
2  episode-272/blog-after/doc/README_FOR_APP
... ... @@ -0,0 +1,2 @@
  1 +Use this README file to introduce your application and point to useful places in the API for learning more.
  2 +Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
0  episode-272/blog-after/lib/tasks/.gitkeep
No changes.
26 episode-272/blog-after/public/404.html
... ... @@ -0,0 +1,26 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <title>The page you were looking for doesn't exist (404)</title>
  5 + <style type="text/css">
  6 + body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  7 + div.dialog {
  8 + width: 25em;
  9 + padding: 0 4em;
  10 + margin: 4em auto 0 auto;
  11 + border: 1px solid #ccc;
  12 + border-right-color: #999;
  13 + border-bottom-color: #999;
  14 + }
  15 + h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  16 + </style>
  17 +</head>
  18 +
  19 +<body>
  20 + <!-- This file lives in public/404.html -->
  21 + <div class="dialog">
  22 + <h1>The page you were looking for doesn't exist.</h1>
  23 + <p>You may have mistyped the address or the page may have moved.</p>
  24 + </div>
  25 +</body>
  26 +</html>
26 episode-272/blog-after/public/422.html
... ... @@ -0,0 +1,26 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <title>The change you wanted was rejected (422)</title>
  5 + <style type="text/css">
  6 + body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  7 + div.dialog {
  8 + width: 25em;
  9 + padding: 0 4em;
  10 + margin: 4em auto 0 auto;
  11 + border: 1px solid #ccc;
  12 + border-right-color: #999;
  13 + border-bottom-color: #999;
  14 + }
  15 + h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  16 + </style>
  17 +</head>
  18 +
  19 +<body>
  20 + <!-- This file lives in public/422.html -->
  21 + <div class="dialog">
  22 + <h1>The change you wanted was rejected.</h1>
  23 + <p>Maybe you tried to change something you didn't have access to.</p>
  24 + </div>
  25 +</body>
  26 +</html>
26 episode-272/blog-after/public/500.html
... ... @@ -0,0 +1,26 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <title>We're sorry, but something went wrong (500)</title>
  5 + <style type="text/css">
  6 + body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  7 + div.dialog {
  8 + width: 25em;
  9 + padding: 0 4em;
  10 + margin: 4em auto 0 auto;
  11 + border: 1px solid #ccc;
  12 + border-right-color: #999;
  13 + border-bottom-color: #999;
  14 + }
  15 + h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  16 + </style>
  17 +</head>
  18 +
  19 +<body>
  20 + <!-- This file lives in public/500.html -->
  21 + <div class="dialog">
  22 + <h1>We're sorry, but something went wrong.</h1>
  23 + <p>We've been notified about this issue and we'll take a look at it shortly.</p>
  24 + </div>
  25 +</body>
  26 +</html>
0  episode-272/blog-after/public/favicon.ico
No changes.
BIN  episode-272/blog-after/public/images/rails.png
2  episode-272/blog-after/public/javascripts/application.js
... ... @@ -0,0 +1,2 @@
  1 +// Place your application-specific JavaScript functions and classes here
  2 +// This file is automatically included by javascript_include_tag :defaults
965 episode-272/blog-after/public/javascripts/controls.js
... ... @@ -0,0 +1,965 @@
  1 +// script.aculo.us controls.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
  2 +
  3 +// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  4 +// (c) 2005-2009 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
  5 +// (c) 2005-2009 Jon Tirsen (http://www.tirsen.com)
  6 +// Contributors:
  7 +// Richard Livsey
  8 +// Rahul Bhargava
  9 +// Rob Wills
  10 +//
  11 +// script.aculo.us is freely distributable under the terms of an MIT-style license.
  12 +// For details, see the script.aculo.us web site: http://script.aculo.us/
  13 +
  14 +// Autocompleter.Base handles all the autocompletion functionality
  15 +// that's independent of the data source for autocompletion. This
  16 +// includes drawing the autocompletion menu, observing keyboard
  17 +// and mouse events, and similar.
  18 +//
  19 +// Specific autocompleters need to provide, at the very least,
  20 +// a getUpdatedChoices function that will be invoked every time
  21 +// the text inside the monitored textbox changes. This method
  22 +// should get the text for which to provide autocompletion by
  23 +// invoking this.getToken(), NOT by directly accessing
  24 +// this.element.value. This is to allow incremental tokenized
  25 +// autocompletion. Specific auto-completion logic (AJAX, etc)
  26 +// belongs in getUpdatedChoices.
  27 +//
  28 +// Tokenized incremental autocompletion is enabled automatically
  29 +// when an autocompleter is instantiated with the 'tokens' option
  30 +// in the options parameter, e.g.:
  31 +// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
  32 +// will incrementally autocomplete with a comma as the token.
  33 +// Additionally, ',' in the above example can be replaced with
  34 +// a token array, e.g. { tokens: [',', '\n'] } which
  35 +// enables autocompletion on multiple tokens. This is most
  36 +// useful when one of the tokens is \n (a newline), as it
  37 +// allows smart autocompletion after linebreaks.
  38 +
  39 +if(typeof Effect == 'undefined')
  40 + throw("controls.js requires including script.aculo.us' effects.js library");
  41 +
  42 +var Autocompleter = { };
  43 +Autocompleter.Base = Class.create({
  44 + baseInitialize: function(element, update, options) {
  45 + element = $(element);
  46 + this.element = element;
  47 + this.update = $(update);
  48 + this.hasFocus = false;
  49 + this.changed = false;
  50 + this.active = false;
  51 + this.index = 0;
  52 + this.entryCount = 0;
  53 + this.oldElementValue = this.element.value;
  54 +
  55 + if(this.setOptions)
  56 + this.setOptions(options);
  57 + else
  58 + this.options = options || { };
  59 +
  60 + this.options.paramName = this.options.paramName || this.element.name;
  61 + this.options.tokens = this.options.tokens || [];
  62 + this.options.frequency = this.options.frequency || 0.4;
  63 + this.options.minChars = this.options.minChars || 1;
  64 + this.options.onShow = this.options.onShow ||
  65 + function(element, update){
  66 + if(!update.style.position || update.style.position=='absolute') {
  67 + update.style.position = 'absolute';
  68 + Position.clone(element, update, {
  69 + setHeight: false,
  70 + offsetTop: element.offsetHeight
  71 + });
  72 + }
  73 + Effect.Appear(update,{duration:0.15});
  74 + };
  75 + this.options.onHide = this.options.onHide ||
  76 + function(element, update){ new Effect.Fade(update,{duration:0.15}) };
  77 +
  78 + if(typeof(this.options.tokens) == 'string')
  79 + this.options.tokens = new Array(this.options.tokens);
  80 + // Force carriage returns as token delimiters anyway
  81 + if (!this.options.tokens.include('\n'))
  82 + this.options.tokens.push('\n');
  83 +
  84 + this.observer = null;
  85 +
  86 + this.element.setAttribute('autocomplete','off');
  87 +
  88 + Element.hide(this.update);
  89 +
  90 + Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
  91 + Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
  92 + },
  93 +
  94 + show: function() {
  95 + if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
  96 + if(!this.iefix &&
  97 + (Prototype.Browser.IE) &&
  98 + (Element.getStyle(this.update, 'position')=='absolute')) {
  99 + new Insertion.After(this.update,
  100 + '<iframe id="' + this.update.id + '_iefix" '+
  101 + 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
  102 + 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
  103 + this.iefix = $(this.update.id+'_iefix');
  104 + }
  105 + if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
  106 + },
  107 +
  108 + fixIEOverlapping: function() {
  109 + Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
  110 + this.iefix.style.zIndex = 1;
  111 + this.update.style.zIndex = 2;
  112 + Element.show(this.iefix);
  113 + },
  114 +
  115 + hide: function() {
  116 + this.stopIndicator();
  117 + if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
  118 + if(this.iefix) Element.hide(this.iefix);
  119 + },
  120 +
  121 + startIndicator: function() {
  122 + if(this.options.indicator) Element.show(this.options.indicator);
  123 + },
  124 +
  125 + stopIndicator: function() {
  126 + if(this.options.indicator) Element.hide(this.options.indicator);
  127 + },
  128 +
  129 + onKeyPress: function(event) {
  130 + if(this.active)
  131 + switch(event.keyCode) {
  132 + case Event.KEY_TAB:
  133 + case Event.KEY_RETURN:
  134 + this.selectEntry();
  135 + Event.stop(event);
  136 + case Event.KEY_ESC:
  137 + this.hide();
  138 + this.active = false;
  139 + Event.stop(event);
  140 + return;
  141 + case Event.KEY_LEFT:
  142 + case Event.KEY_RIGHT:
  143 + return;
  144 + case Event.KEY_UP:
  145 + this.markPrevious();
  146 + this.render();
  147 + Event.stop(event);
  148 + return;
  149 + case Event.KEY_DOWN:
  150 + this.markNext();
  151 + this.render();
  152 + Event.stop(event);
  153 + return;
  154 + }
  155 + else
  156 + if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
  157 + (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
  158 +
  159 + this.changed = true;
  160 + this.hasFocus = true;
  161 +
  162 + if(this.observer) clearTimeout(this.observer);
  163 + this.observer =
  164 + setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
  165 + },
  166 +
  167 + activate: function() {
  168 + this.changed = false;
  169 + this.hasFocus = true;
  170 + this.getUpdatedChoices();
  171 + },
  172 +
  173 + onHover: function(event) {
  174 + var element = Event.findElement(event, 'LI');
  175 + if(this.index != element.autocompleteIndex)
  176 + {
  177 + this.index = element.autocompleteIndex;
  178 + this.render();
  179 + }
  180 + Event.stop(event);
  181 + },
  182 +
  183 + onClick: function(event) {
  184 + var element = Event.findElement(event, 'LI');
  185 + this.index = element.autocompleteIndex;
  186 + this.selectEntry();
  187 + this.hide();
  188 + },
  189 +
  190 + onBlur: function(event) {
  191 + // needed to make click events working
  192 + setTimeout(this.hide.bind(this), 250);
  193 + this.hasFocus = false;
  194 + this.active = false;
  195 + },
  196 +
  197 + render: function() {
  198 + if(this.entryCount > 0) {
  199 + for (var i = 0; i < this.entryCount; i++)
  200 + this.index==i ?
  201 + Element.addClassName(this.getEntry(i),"selected") :
  202 + Element.removeClassName(this.getEntry(i),"selected");
  203 + if(this.hasFocus) {
  204 + this.show();
  205 + this.active = true;
  206 + }
  207 + } else {
  208 + this.active = false;
  209 + this.hide();
  210 + }
  211 + },
  212 +
  213 + markPrevious: function() {
  214 + if(this.index > 0) this.index--;
  215 + else this.index = this.entryCount-1;
  216 + this.getEntry(this.index).scrollIntoView(true);
  217 + },
  218 +
  219 + markNext: function() {
  220 + if(this.index < this.entryCount-1) this.index++;
  221 + else this.index = 0;
  222 + this.getEntry(this.index).scrollIntoView(false);
  223 + },
  224 +
  225 + getEntry: function(index) {
  226 + return this.update.firstChild.childNodes[index];
  227 + },
  228 +
  229 + getCurrentEntry: function() {
  230 + return this.getEntry(this.index);
  231 + },
  232 +
  233 + selectEntry: function() {
  234 + this.active = false;
  235 + this.updateElement(this.getCurrentEntry());
  236 + },
  237 +
  238 + updateElement: function(selectedElement) {
  239 + if (this.options.updateElement) {
  240 + this.options.updateElement(selectedElement);
  241 + return;
  242 + }
  243 + var value = '';
  244 + if (this.options.select) {
  245 + var nodes = $(selectedElement).select('.' + this.options.select) || [];
  246 + if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
  247 + } else
  248 + value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
  249 +
  250 + var bounds = this.getTokenBounds();
  251 + if (bounds[0] != -1) {
  252 + var newValue = this.element.value.substr(0, bounds[0]);
  253 + var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
  254 + if (whitespace)
  255 + newValue += whitespace[0];
  256 + this.element.value = newValue + value + this.element.value.substr(bounds[1]);
  257 + } else {
  258 + this.element.value = value;
  259 + }
  260 + this.oldElementValue = this.element.value;
  261 + this.element.focus();
  262 +
  263 + if (this.options.afterUpdateElement)
  264 + this.options.afterUpdateElement(this.element, selectedElement);
  265 + },
  266 +
  267 + updateChoices: function(choices) {
  268 + if(!this.changed && this.hasFocus) {
  269 + this.update.innerHTML = choices;
  270 + Element.cleanWhitespace(this.update);
  271 + Element.cleanWhitespace(this.update.down());
  272 +
  273 + if(this.update.firstChild && this.update.down().childNodes) {
  274 + this.entryCount =
  275 + this.update.down().childNodes.length;
  276 + for (var i = 0; i < this.entryCount; i++) {