Skip to content

Commit

Permalink
run-hobo
Browse files Browse the repository at this point in the history
OUTPUT_FILE: agility.markdown

## Before you start

You'll need a working Ruby on Rails setup. We're assuming you know at least the basics of Rails. If not, you should probably work through a Rails tutorial before attempting this one.

## Create the application with Hobo gem

Although Hobo is in fact a group of Rails plugins, it is also available as a gem which gives you the useful `hobo` command:

    $ gem install hobo

The `hobo` command is like the Rails command, it will create a new blank Rails app that is set-up for Hobo. It's the equivalent of running the `rails` command, installing a few plugins and running a few generators.

    $ hobo agility
    $ cd agility

## Alternately: Create the application with Hobo plugin

If you wish to use hobo as a plugin instead of a gem, see the [sidebar](hobo-as-plugin).
  • Loading branch information
bryanlarsen committed Dec 1, 2009
1 parent d20dadd commit 28fdfbf
Show file tree
Hide file tree
Showing 78 changed files with 10,376 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Rakefile
@@ -0,0 +1,12 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'

require 'hobo/tasks/rails'
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
@@ -0,0 +1,10 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details

# Scrub sensitive parameters from your log
# filter_parameter_logging :password
end
19 changes: 19 additions & 0 deletions app/controllers/front_controller.rb
@@ -0,0 +1,19 @@
class FrontController < ApplicationController

hobo_controller

def index; end

def summary
if !current_user.administrator?
redirect_to user_login_path
end
end

def search
if params[:query]
site_search(params[:query])
end
end

end
7 changes: 7 additions & 0 deletions app/controllers/users_controller.rb
@@ -0,0 +1,7 @@
class UsersController < ApplicationController

hobo_user_controller

auto_actions :all, :except => [ :index, :new, :create ]

end
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
@@ -0,0 +1,3 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
2 changes: 2 additions & 0 deletions app/helpers/front_helper.rb
@@ -0,0 +1,2 @@
module FrontHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
module UsersHelper
end
7 changes: 7 additions & 0 deletions app/models/guest.rb
@@ -0,0 +1,7 @@
class Guest < Hobo::Guest

def administrator?
false
end

end
61 changes: 61 additions & 0 deletions app/models/user.rb
@@ -0,0 +1,61 @@
class User < ActiveRecord::Base

hobo_user_model # Don't put anything above this

fields do
name :string, :unique
email_address :email_address, :login => true
administrator :boolean, :default => false
timestamps
end

validates_presence_of :name

# This gives admin rights to the first sign-up.
# Just remove it if you don't want that
before_create { |user| user.administrator = true if !Rails.env.test? && count == 0 }


# --- Signup lifecycle --- #

lifecycle do

state :active, :default => true

create :signup, :available_to => "Guest",
:params => [:name, :email_address, :password, :password_confirmation],
:become => :active

transition :request_password_reset, { :active => :active }, :new_key => true do
UserMailer.deliver_forgot_password(self, lifecycle.key)
end

transition :reset_password, { :active => :active }, :available_to => :key_holder,
:params => [ :password, :password_confirmation ]

end


# --- Permissions --- #

def create_permitted?
false
end

def update_permitted?
acting_user.administrator? ||
(acting_user == self && only_changed?(:email_address, :crypted_password,
:current_password, :password, :password_confirmation))
# Note: crypted_password has attr_protected so although it is permitted to change, it cannot be changed
# directly from a form submission.
end

def destroy_permitted?
acting_user.administrator?
end

def view_permitted?(field)
true
end

end
14 changes: 14 additions & 0 deletions app/models/user_mailer.rb
@@ -0,0 +1,14 @@
class UserMailer < ActionMailer::Base

def forgot_password(user, key)
host = Hobo::Controller.request_host
app_name = Hobo::Controller.app_name || host
@subject = "#{app_name} -- forgotten password"
@body = { :user => user, :key => key, :host => host, :app_name => app_name }
@recipients = user.email_address
@from = "no-reply@#{host}"
@sent_on = Time.now
@headers = {}
end

end
29 changes: 29 additions & 0 deletions app/views/front/index.dryml
@@ -0,0 +1,29 @@
<page title="Home">

<body: class="front-page"/>

<content:>
<header class="content-header">
<h1>Welcome to <app-name/></h1>
<section class="welcome-message">
<h3>Congratulations! Your Hobo Rails App is up and running</h3>
<ul>
<li>To customise this page: edit app/views/front/index.dryml</li>
</ul>

<% if User.count == 0 -%>
<h3 style="margin-top: 20px;">There are no user accounts - please provide the details of the site administrator</h3>
<do with="&User.new"><% this.exempt_from_edit_checks = true %>
<signup-form/>
</do>
<% end -%>


</section>
</header>

<section class="content-body">
</section>
</content:>

</page>
103 changes: 103 additions & 0 deletions app/views/front/summary.dryml
@@ -0,0 +1,103 @@
<page>
<content:>
<div class="content-body">
<h2>Application Summary</h2>

<table class="app-summary">
<tr> <th></th><th></th></tr>
<tr> <td>Application Name</td> <td><app-name/></td> </tr>
<tr> <td>Application Location</td> <td><rails-root/></td> </tr>
<tr> <td>Rails Version</td> <td><rails-version/></td> </tr>
<tr> <td>Rails Location</td> <td><rails-location/></td> </tr>
<tr> <td>Mode</td> <td><rails-env/></td> </tr>
</table>

<h3>Change Control</h3>
<table class="app-summary">
<tr> <th></th><th></th></tr>
<tr> <td>Method</td> <td><cms-method/></td> </tr>
<if test="&cms_method.strip=='git'">
<tr> <td>Version</td> <td><cms-version/></td> </tr>
<tr> <td>Date</td> <td><cms-last-commit-time/></td> </tr>
<tr> <td>Branch</td> <td><cms-branch/></td> </tr>
<tr> <td>Clean?</td> <td><cms-clean/></td></tr>
</if>
</table>


<h3>Gems</h3>
<table class="app-summary">
<with-gems>
<tr if="&first_item?"><th></th><th>Required</th><th>Installed</th><th>Status</th><th>Dependencies</th></tr>
<tr>
<td><gem-name/></td>
<td><gem-version-required/></td>
<td><gem-version/></td>
<td><gem-frozen/></td>
<td><gem-dependencies/></td>
</tr>
</with-gems>
</table>

<h3>Plugins</h3>
<table class="app-summary">
<with-plugins>
<tr if="&first_item?"><th></th><th>Location</th><th>Method</th><th>Clean?</th><th>Version</th></tr>
<tr>
<td><plugin-name/></td>
<td><plugin-location/></td>
<td><plugin-method/></td>
<td><plugin-clean/></td>
<td><plugin-version/></td>
</tr>
</with-plugins>
</table>

<h3>Environments</h3>
<table class="app-summary">
<tr><th></th><th colspan='2'>database</th></tr>
<with-environments>
<tr>
<td><environment-name /></td>
<td><database-type /></td>
<td><database-name /></td>
</tr>
</with-environments>
</table>

<h2>Models</h2>
<table class="app-summary">
<tr><th>Class</th><th>Table</th></tr>
<with-models>
<tr>
<td><model-name/></td>
<td><model-table-name/></td>
</tr>
</with-models>
</table>

<with-models>
<h3 if="&this.try.table_name"><model-name /></h3>
<table class="app-summary">
<with-model-columns>
<tr if="&first_item?"><th>Column</th><th>Type</th></tr>
<tr>
<td><model-column-name/></td>
<td><model-column-type/></td>
</tr>
</with-model-columns>
</table>
<table class="app-summary">
<with-model-associations>
<tr if="&first_item?"><th>Association</th><th>Macro</th><th>Class</th></tr>
<tr>
<td><model-association-name/></td>
<td><model-association-macro/></td>
<td><model-association-class-name/></td>
</tr>
</with-model-associations>
</table>
</with-models>
</div>
</content:>
</page>
9 changes: 9 additions & 0 deletions app/views/taglibs/application.dryml
@@ -0,0 +1,9 @@
<include src="rapid" plugin="hobo"/>

<include src="taglibs/auto/rapid/cards"/>
<include src="taglibs/auto/rapid/pages"/>
<include src="taglibs/auto/rapid/forms"/>

<set-theme name="clean"/>

<def tag="app-name">Agility</def>
10 changes: 10 additions & 0 deletions app/views/taglibs/themes/clean/clean.dryml
@@ -0,0 +1,10 @@
<extend tag="page">
<old-page merge>
<stylesheets: param>
<stylesheet name="reset"/>
<theme-stylesheet/>
<theme-stylesheet name="rapid-ui"/>
<stylesheet name="application" param="app-stylesheet"/>
</stylesheets:>
</old-page>
</extend>
10 changes: 10 additions & 0 deletions app/views/user_mailer/forgot_password.erb
@@ -0,0 +1,10 @@
<%= @user %>,

If you have forgotten your password for <%= @app_name %>, you can choose
a new one by clicking on this link:

<%= user_reset_password_url :host => @host, :id => @user, :key => @key %>

Thank you,

The <%= @app_name %> team.

0 comments on commit 28fdfbf

Please sign in to comment.