Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rails integration

  • Loading branch information...
commit ef726a5cc5075689c6e6ddd4643b7b1b7a7c13fc 1 parent 93dd1ca
@moonmaster9000 authored
Showing with 225 additions and 349 deletions.
  1. +27 −27 Gemfile.lock
  2. +14 −0 app/frills/view_context_frill.rb
  3. +1 −1  frill.gemspec
  4. +1 −0  lib/frill.rb
  5. +26 −0 lib/frill/engine.rb
  6. +2 −0  lib/frill/frill.rb
  7. +5 −0 lib/frill/rails.rb
  8. +0 −23 readme.markdown
  9. +1 −0  test_frill_rails/.rspec
  10. +5 −3 test_frill_rails/Gemfile
  11. +63 −39 test_frill_rails/Gemfile.lock
  12. +0 −14 test_frill_rails/app/assets/javascripts/application.js
  13. +8 −0 test_frill_rails/app/controllers/home_controller.rb
  14. +12 −0 test_frill_rails/app/frills/bold_title_frill.rb
  15. +11 −0 test_frill_rails/app/frills/pretty_title_frill.rb
  16. +5 −0 test_frill_rails/app/models/model.rb
  17. +1 −0  test_frill_rails/app/views/home/index.erb
  18. +1 −1  test_frill_rails/config/initializers/secret_token.rb
  19. +1 −0  test_frill_rails/config/routes.rb
  20. 0  test_frill_rails/{public → public.old}/404.html
  21. 0  test_frill_rails/{public → public.old}/422.html
  22. 0  test_frill_rails/{public → public.old}/500.html
  23. 0  test_frill_rails/{public → public.old}/favicon.ico
  24. 0  test_frill_rails/{public → public.old}/robots.txt
  25. +0 −241 test_frill_rails/public/index.html
  26. +8 −0 test_frill_rails/spec/integration/test_frill_integration_spec.rb
  27. +33 −0 test_frill_rails/spec/spec_helper.rb
View
54 Gemfile.lock
@@ -6,31 +6,31 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.2.3)
- actionpack (= 3.2.3)
- mail (~> 2.4.4)
- actionpack (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ actionmailer (3.2.2)
+ actionpack (= 3.2.2)
+ mail (~> 2.4.0)
+ actionpack (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
- rack-cache (~> 1.2)
+ rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
- activemodel (3.2.3)
- activesupport (= 3.2.3)
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
builder (~> 3.0.0)
- activerecord (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ activerecord (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
- activesupport (3.2.3)
+ activeresource (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
@@ -55,17 +55,17 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.2.3)
- actionmailer (= 3.2.3)
- actionpack (= 3.2.3)
- activerecord (= 3.2.3)
- activeresource (= 3.2.3)
- activesupport (= 3.2.3)
+ rails (3.2.2)
+ actionmailer (= 3.2.2)
+ actionpack (= 3.2.2)
+ activerecord (= 3.2.2)
+ activeresource (= 3.2.2)
+ activesupport (= 3.2.2)
bundler (~> 1.0)
- railties (= 3.2.3)
- railties (3.2.3)
- actionpack (= 3.2.3)
- activesupport (= 3.2.3)
+ railties (= 3.2.2)
+ railties (3.2.2)
+ actionpack (= 3.2.2)
+ activesupport (= 3.2.2)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
@@ -97,5 +97,5 @@ PLATFORMS
DEPENDENCIES
frill!
- rails (~> 3.2.2)
+ rails (= 3.2.2)
rspec
View
14 app/frills/view_context_frill.rb
@@ -0,0 +1,14 @@
+module ViewContextFrill
+ include Frill
+ first
+
+ def self.frill? object, controller
+ object.class_eval do
+ define_method :helper do
+ @frill_helper ||= controller.view_context
+ end
+ end
+
+ false
+ end
+end
View
2  frill.gemspec
@@ -6,6 +6,6 @@ Gem::Specification.new do |s|
s.files = Dir["lib/**/*"] << "VERSION" << "readme.markdown"
s.test_files = Dir["spec/**/*"]
- s.add_development_dependency "rails", "~> 3.2.2"
+ s.add_development_dependency "rails", "= 3.2.2"
s.add_development_dependency "rspec"
end
View
1  lib/frill.rb
@@ -1 +1,2 @@
require 'frill/frill'
+require 'frill/engine' if defined? Rails
View
26 lib/frill/engine.rb
@@ -0,0 +1,26 @@
+require 'rails'
+
+module Frill
+ class Engine < Rails::Engine
+ config.autoload_paths << "app/frills"
+
+ initializer "frill.rails_integration" do
+ require 'frill/rails'
+ end
+
+ config.to_prepare do
+ if Rails.env.development? && !Rails.application.config.cache_classes
+ Frill.reset!
+
+ Frill::Engine.force_load Dir["#{Frill::Engine.root}/app/frills/*"]
+ Frill::Engine.force_load Dir["#{Rails.root}/app/frills/*"]
+ end
+ end
+
+ def self.force_load files
+ files.each do |f|
+ load f
+ end
+ end
+ end
+end
View
2  lib/frill/frill.rb
@@ -16,6 +16,8 @@ def self.decorate object, context
decorators.each do |d|
object.extend d if d.frill? object, context
end
+
+ object
end
module ClassMethods
View
5 lib/frill/rails.rb
@@ -0,0 +1,5 @@
+class ActionController::Base
+ def frill object
+ Frill.decorate object, self
+ end
+end
View
23 readme.markdown
@@ -1,7 +1,5 @@
# Frill
- NOTE: THIS GEM IS NOT YET RELEASED
-
Simple decoration of objects for presentation. If you don't know what I'm talking
about, reading up on decorators and their role in MVC.
@@ -15,10 +13,6 @@ Throw this in your Gemfile:
gem "frill"
```
-If you're placing this in a Rails app, run the following command:
-
- $ rails g frill:install
-
## Usage
(For the purposes of this tutorial, I'm going to assume you're using
@@ -56,8 +50,6 @@ to `created_at`.
Next, let's create an `HtmlTimestampFrill` module:
```ruby
-require_relative 'timestamp_frill'
-
module HtmlTimestampFrill
include Frill
after TimestampFrill
@@ -113,21 +105,6 @@ simply call `Frill.decorate`:
Frill.decorate my_object, my_context
```
-If you want to replicate the `helper` behavior you get for free in a
-Rails app, consider how simple it was to make that `helper` method
-possible:
-
-```ruby
-module ActionViewFrill
- include Frill
- first
-
- def helper
- @helper ||= Object.new.extend ActionView::Helpers
- end
-end
-```
-
## License
MIT.
View
1  test_frill_rails/.rspec
@@ -0,0 +1 @@
+--colour
View
8 test_frill_rails/Gemfile
@@ -1,8 +1,10 @@
-source 'http://rubygems.org'
+source 'https://rubygems.org'
+
+gem 'rails', '3.2.2'
-gem 'rails', '3.2.3'
gem 'frill', path: '../'
group :test do
- gem 'rspec-rails'
+ gem 'rspec-rails', '~> 2.8.0'
+ gem 'capybara'
end
View
102 test_frill_rails/Gemfile.lock
@@ -4,49 +4,63 @@ PATH
frill (0.0.0)
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
- actionmailer (3.2.3)
- actionpack (= 3.2.3)
- mail (~> 2.4.4)
- actionpack (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ actionmailer (3.2.2)
+ actionpack (= 3.2.2)
+ mail (~> 2.4.0)
+ actionpack (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
- rack-cache (~> 1.2)
+ rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
- activemodel (3.2.3)
- activesupport (= 3.2.3)
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
builder (~> 3.0.0)
- activerecord (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ activerecord (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
- activesupport (3.2.3)
+ activeresource (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
+ addressable (2.2.7)
arel (3.0.2)
builder (3.0.0)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.2)
+ ffi (~> 1.0.6)
diff-lcs (1.1.3)
erubis (2.7.0)
+ ffi (1.0.11)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
json (1.7.0)
+ libwebsocket (0.1.3)
+ addressable
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.3.4)
+ nokogiri (1.5.2)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
@@ -55,17 +69,17 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.2.3)
- actionmailer (= 3.2.3)
- actionpack (= 3.2.3)
- activerecord (= 3.2.3)
- activeresource (= 3.2.3)
- activesupport (= 3.2.3)
+ rails (3.2.2)
+ actionmailer (= 3.2.2)
+ actionpack (= 3.2.2)
+ activerecord (= 3.2.2)
+ activeresource (= 3.2.2)
+ activesupport (= 3.2.2)
bundler (~> 1.0)
- railties (= 3.2.3)
- railties (3.2.3)
- actionpack (= 3.2.3)
- activesupport (= 3.2.3)
+ railties (= 3.2.2)
+ railties (3.2.2)
+ actionpack (= 3.2.2)
+ activesupport (= 3.2.2)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
@@ -73,19 +87,26 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
- rspec (2.9.0)
- rspec-core (~> 2.9.0)
- rspec-expectations (~> 2.9.0)
- rspec-mocks (~> 2.9.0)
- rspec-core (2.9.0)
- rspec-expectations (2.9.1)
- diff-lcs (~> 1.1.3)
- rspec-mocks (2.9.0)
- rspec-rails (2.9.0)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ rspec-rails (2.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
- rspec (~> 2.9.0)
+ rspec (~> 2.8.0)
+ rubyzip (0.9.8)
+ selenium-webdriver (2.21.2)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ libwebsocket (~> 0.1.3)
+ multi_json (~> 1.0)
+ rubyzip
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
@@ -96,11 +117,14 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
+ capybara
frill!
- rails (= 3.2.3)
- rspec-rails
+ rails (= 3.2.2)
+ rspec-rails (~> 2.8.0)
View
14 test_frill_rails/app/assets/javascripts/application.js
@@ -1,15 +1 @@
-// This is a manifest file that'll be compiled into application.js, which will include all the files
-// listed below.
-//
-// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
-// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
-//
-// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
-// the compiled file.
-//
-// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
-// GO AFTER THE REQUIRES BELOW.
-//
-//= require jquery
-//= require jquery_ujs
//= require_tree .
View
8 test_frill_rails/app/controllers/home_controller.rb
@@ -0,0 +1,8 @@
+class HomeController < ApplicationController
+ respond_to :html
+
+ def index
+ @model = frill Model.new
+ respond_with @model
+ end
+end
View
12 test_frill_rails/app/frills/bold_title_frill.rb
@@ -0,0 +1,12 @@
+module BoldTitleFrill
+ include Frill
+ after PrettyTitleFrill
+
+ def self.frill? object, context
+ context.request.format == "text/html"
+ end
+
+ def title
+ helper.content_tag :b, "#{super} #{helper.root_url}"
+ end
+end
View
11 test_frill_rails/app/frills/pretty_title_frill.rb
@@ -0,0 +1,11 @@
+module PrettyTitleFrill
+ include Frill
+
+ def self.frill?(*)
+ true
+ end
+
+ def title
+ "Decorated #{super} is Pretty"
+ end
+end
View
5 test_frill_rails/app/models/model.rb
@@ -0,0 +1,5 @@
+class Model
+ def title
+ "Title"
+ end
+end
View
1  test_frill_rails/app/views/home/index.erb
@@ -0,0 +1 @@
+<%= raw @model.title %>
View
2  test_frill_rails/config/initializers/secret_token.rb
@@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
-TestFrillRails::Application.config.secret_token = 'e7ad4ef915c1a614564a492d0c24ca1dcfbc11a98349ea0bf64ae37eb677f9ba7b5bb20a70965a80ec77a93fe9b84e6906ce2ef6da36be768efb34b872fcf248'
+TestFrillRails::Application.config.secret_token = '785f27ffaf02531fe6035ec503a45c9e0bd9455f8e723714e1b15e8011ba8566d5de266d6e1f29e80267a5f85f92ac55fbfd57b4e7a94ccc1ecfbedab2ef73f6'
View
1  test_frill_rails/config/routes.rb
@@ -1,4 +1,5 @@
TestFrillRails::Application.routes.draw do
+ root to: "home#index"
# The priority is based upon order of creation:
# first created -> highest priority.
View
0  test_frill_rails/public/404.html → test_frill_rails/public.old/404.html
File renamed without changes
View
0  test_frill_rails/public/422.html → test_frill_rails/public.old/422.html
File renamed without changes
View
0  test_frill_rails/public/500.html → test_frill_rails/public.old/500.html
File renamed without changes
View
0  test_frill_rails/public/favicon.ico → test_frill_rails/public.old/favicon.ico
File renamed without changes
View
0  test_frill_rails/public/robots.txt → test_frill_rails/public.old/robots.txt
File renamed without changes
View
241 test_frill_rails/public/index.html
@@ -1,241 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("assets/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- .filename {
- font-style: italic;
- }
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
- <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
- <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
View
8 test_frill_rails/spec/integration/test_frill_integration_spec.rb
@@ -0,0 +1,8 @@
+require 'spec_helper'
+
+describe 'Frill integration' do
+ it "should work" do
+ visit root_path
+ page.should have_content "Decorated Title"
+ end
+end
View
33 test_frill_rails/spec/spec_helper.rb
@@ -0,0 +1,33 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+require 'capybara/rspec'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ # config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+end

0 comments on commit ef726a5

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