Permalink
Browse files

Who knows, lots of changes.

  • Loading branch information...
1 parent 3a88379 commit 020f57b66d883a866051c8c16d4f9e8675a23dad Michael Bleigh committed Oct 17, 2010
View
@@ -8,6 +8,8 @@ gem 'mongo_mapper', :git => 'git://github.com/jnunemaker/mongomapper.git', :bran
gem 'omniauth'
gem 'git-deploy'
gem 'haml'
+gem 'maruku'
+gem 'tweet-button'
group :test, :development do
gem 'rspec-rails', '~> 2.0.1'
View
@@ -66,6 +66,8 @@ GEM
activesupport (>= 2.3.6)
mime-types
treetop (>= 1.4.5)
+ maruku (0.6.0)
+ syntax (>= 1.0.0)
mime-types (1.16)
mongo (1.1.1)
bson (>= 1.1.1)
@@ -155,9 +157,11 @@ GEM
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
rubyntlm (0.1.1)
+ syntax (1.0.0)
thor (0.14.3)
treetop (1.4.8)
polyglot (>= 0.3.1)
+ tweet-button (0.1.0)
tzinfo (0.3.23)
PLATFORMS
@@ -168,8 +172,10 @@ DEPENDENCIES
git-deploy
haml
machinist (= 2.0.0.beta2)
+ maruku
mongo_mapper!
omniauth
rails (= 3.0.1)
rails3-generators
rspec-rails (~> 2.0.1)
+ tweet-button
@@ -12,5 +12,10 @@ def current_user
@current_user ||= User.find(session[:user_id])
end
+ def current_user=(user)
+ session[:user_id] = user.id
+ @current_user = user
+ end
+
helper_method :signed_in?, :current_user
end
@@ -1,5 +1,12 @@
class SessionsController < ApplicationController
def create
- render :text => request.env['rack.auth'].inspect
+ self.current_user = User.from_hash(request.env['omniauth.auth'])
+ redirect_to '/'
+ end
+
+ def destroy
+ session.delete(:user_id)
+ flash[:notice] = 'You are now signed out.'
+ redirect_to '/'
end
end
@@ -6,8 +6,17 @@ class TemplatesController < ApplicationController
@page_title = template.name if template
end
+ def index
+ @page_title = "Template Directory"
+ @templates = RailsTemplate.listed.recent.limit(30)
+ render :action => 'index', :layout => 'application'
+ end
+
def create
- if @template = RailsTemplate.create(params[:rails_template])
+ @template = RailsTemplate.new(params[:rails_template])
+ @template.user = current_user if signed_in?
+
+ if @template.save
redirect_to edit_path(@template)
else
flash[:alert] = 'Unable to create a template. Something is wrong.'
@@ -1,4 +1,12 @@
class UsersController < ApplicationController
- def destroy
+ def show
+ @page_title = user.name
end
+
+ protected
+
+ def user
+ @user ||= User.find_by_id(params[:id])
+ end
+ helper_method :user
end
@@ -1,4 +1,6 @@
module ApplicationHelper
+ include TweetButton
+
def bespin_setup(dom_id)
render "layouts/bespin", :dom_id => dom_id
end
@@ -7,6 +7,12 @@ class RailsTemplate
key :name, String
key :slug, String
key :listed, Boolean
+ key :description, String
+ def description_html; Maruku.new(description).to_html.html_safe end
+ belongs_to :user
+
+ scope :listed, :listed => true
+ scope :recent, :order => [[:updated_at, -1]]
RECIPE_FIELDS = %w(orm unit_testing integration_testing javascript authentication)
RECIPE_FIELDS.each{|f| key f, String}
@@ -19,6 +25,10 @@ class RailsTemplate
validates_presence_of :name, :slug
validates_uniqueness_of :slug
+ def can_edit?(user)
+ self.user.nil? || user.id == self.user_id
+ end
+
# Params
def to_param
self.slug
View
@@ -1,9 +1,12 @@
class User
include MongoMapper::Document
- many :authorizations
+ one :authorization
key :name, String
+ has_many :recipes
+ has_many :rails_templates
+
def self.from_hash(auth_hash)
user = authorize(auth_hash['provider'], auth_hash['uid'])
user ||= User.create(
@@ -16,6 +19,6 @@ def self.from_hash(auth_hash)
end
def self.authorize(provider, uid)
- user.where('authorizations.provider' => provider, 'authorizations.uid' => uid).first
+ User.where('authorization.provider' => provider, 'authorization.uid' => uid).first
end
end
@@ -11,12 +11,20 @@
<header id='top'>
<section>
<h1><%= link_to image_tag('/images/logo.png', :alt => 'RailsWizard'), '/' %></h1>
+ <nav>
+ <ul>
+ <li><%= link_to 'Template Directory', templates_path %></li>
+ <!--<li><%= link_to 'Recipes', recipes_path %></li>-->
+ </ul>
+ </nav>
<aside id='user_bar'>
<% if signed_in? %>
+ <div id='signed_in'>
<%= link_to user_path(current_user) do %>
- <%= image_tag '/asdouasf', :width => 20, :height => 20 %>
<b><%= current_user.name %></b>
<% end %>
+ <%= link_to 'Sign Out', sign_out_path %>
+ </div>
<% else %>
<div id='sign_in'>
<span>Sign In</span>
@@ -39,4 +47,5 @@
<h2><%= link_to compile_url(template), compile_url(template), :target => '_template' %></h2>
<% end %>
<h1><%= @page_title || "Create a Rails Application Template" %></h1>
+ <%= yield :after_page_title %>
</header>
@@ -1,7 +1,7 @@
<%= render "layouts/head"%>
<nav id='sidebar'>
<ul>
- <li><%= step 'app_info' do %><b>Application Info</b> <em>Basic information about your app.</em><% end %></li>
+ <li><%= step 'app_info' do %><b>Template Info</b> <em>Basic information about your template.</em><% end %></li>
<li><%= step 'orm' do %><b>Database/ORM</b> <em>Choose your database and ORM.</em><% end %></li>
<li><%= step 'testing' do %><b>Testing</b> <em>Unit and integration testing.</em><% end %></li>
<li><%= step 'javascript' do %><b>Javascript</b> <em>Framework and plugins for JS</em><% end %></li>
@@ -10,6 +10,12 @@
<%= f.text_field :slug, :placeholder => 'Template URL' %>
</div>
+<div class='field text'>
+ <%= f.label :description, "Description"%>
+ <%= f.label :description, "Some (Markdown) text about your template. Will be displayed in the directory and/or on your template's homepage.", :class => 'help' %>
+ <%= f.text_area :description %>
+</div>
+
<div class='field check'>
<%= f.check_box :listed %>
<%= f.label :listed, "List Template in Directory?"%>
@@ -0,0 +1,12 @@
+<article class='template_listing'>
+ <ul class='recipes'>
+ <% for recipe in template.recipes %>
+ <li><%= link_to recipe.name, recipe %></li>
+ <% end %>
+ </ul>
+ <h1>
+ <%= link_to template.name, show_path(template) %>
+ <%= link_to 'Edit', edit_path(template), :class => 'edit' if template.can_edit?(current_user) %>
+ </h1>
+ <% if template.description? %><div class='description'><%=raw template.description_html %></div><% end %>
+</article>
@@ -0,0 +1,11 @@
+<aside id='sidebar'>
+ <p>Welcome to the recipe creator. It's
+ a bit daunting at first, but there will
+ be documentation (someday).</p>
+</aside>
+<h1 id='heading'>Recent Templates</h1>
+<section id='main'>
+ <% for template in @templates %>
+ <%= render "template", :template => template %>
+ <% end %>
+</section>
@@ -1,3 +1,11 @@
+<% content_for(:after_page_title) do %><%= tweet_button :text => "Check out the '#{template.name}' Rails template", :count => 'horizontal', :via => 'railswizard' %><% end %>
+
+<% if template.description? %>
+<section id='template_description'>
+ <%= template.description_html %>
+</section>
+<% end %>
+
<section id='main' class='fill'>
<p>This template is ready to go, you just need to run the Rails application generator.
Simply choose a directory name below and then copy and paste the command that's in the
@@ -0,0 +1,3 @@
+<% for template in user.rails_templates %>
+ <%= link_to template.name, show_path(template) %>
+<% end %>
View
@@ -3,7 +3,10 @@
resources :templates
resources :recipes
-
+ resources :users
+
+ match '/auth/sign_out', :to => 'sessions#destroy', :as => 'sign_out'
+
match '/:id.rb', :to => 'templates#compile', :as => 'compile'
match '/:id', :to => 'templates#show', :as => 'show'
match '/:id/edit', :to => 'templates#edit', :as => 'edit'
Binary file not shown.
Oops, something went wrong.

0 comments on commit 020f57b

Please sign in to comment.