Skip to content

Commit

Permalink
Merge branch 'master' of [email protected]:wycats/merb-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Oct 8, 2008
2 parents 3b7c33d + 42c99ea commit bb2b2c1
Show file tree
Hide file tree
Showing 161 changed files with 6,616 additions and 4,662 deletions.
74 changes: 55 additions & 19 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,56 @@
require "rake"
require "fileutils"
require "merb-core/tasks/merb_rake_helper"
## THESE ARE CRUCIAL
module Merb
# Set this to the version of merb-core that you are building against/for
VERSION = "0.9.8"

gems = %w[merb_activerecord merb_helpers merb_sequel merb_param_protection merb_test_unit merb_stories merb_screw_unit]
orm_gems = %w[merb_activerecord merb_sequel]
# Set this to the version of merb-more you plan to release
MORE_VERSION = "0.9.8"
end

GEM_VERSION = Merb::VERSION

require 'rubygems'
require "rake/clean"
require "rake/gempackagetask"
require 'merb-core/tasks/merb_rake_helper'
require 'fileutils'
include FileUtils


gems = %w[merb_activerecord merb_sequel merb_param_protection merb_test_unit merb_stories merb_screw_unit merb_exceptions]

# Implement standard Rake::GemPackageTask tasks - see merb.thor
task :clobber_package do; FileUtils.rm_rf('pkg'); end
task :package do; end

desc "Install it all"
task :install => "install:gems"
desc "Uninstall all gems"
task :uninstall => :uninstall_gems

namespace :install do
desc "Install the merb-plugins sub-gems"
task :gems do
gems.each do |dir|
Dir.chdir(dir){ sh "rake install" }
end
desc "Build the merb-more gems"
task :build_gems do
gems.each do |dir|
Dir.chdir(dir) { sh "#{Gem.ruby} -S rake package" }
end
end

desc "Install the ORM merb-plugins sub-gems"
task :orm do
orm_gems.each do |dir|
Dir.chdir(dir){ sh "rake install" }
end
desc "Install the merb-plugins sub-gems"
task :install_gems do
gems.each do |dir|
Dir.chdir(dir) { sh "#{Gem.ruby} -S rake install" }
end
end

desc "Uninstall the merb-plugins sub-gems"
task :uninstall_gems do
gems.each do |dir|
Dir.chdir(dir) { sh "#{Gem.ruby} -S rake uninstall" }
end
end

desc "Clobber the merb-plugins sub-gems"
task :clobber_gems do
gems.each do |dir|
Dir.chdir(dir) { sh "#{Gem.ruby} -S rake clobber" }
end
end

Expand All @@ -43,6 +69,16 @@ end
desc "Release gems in merb-plugins"
task :release do
gems.each do |dir|
Dir.chdir(dir){ sh "rake release" }
Dir.chdir(dir){ sh "#{Gem.ruby} -S rake release" }
end
end

desc "Run spec examples for Merb More gems, one by one."
task :spec do
gems.each do |gem|
Dir.chdir(gem) { sh "#{Gem.ruby} -S rake spec" }
end
end

desc 'Default: run spec examples for all the gems.'
task :default => 'spec'
39 changes: 26 additions & 13 deletions merb_activerecord/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GEM_NAME = "merb_activerecord"
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.8") + PKG_BUILD

RELEASE_NAME = "REL #{GEM_VERSION}"
RELEASE_NAME = "REL #{GEM_VERSION}"

require "extlib/tasks/release"

Expand All @@ -37,28 +37,41 @@ spec = Gem::Specification.new do |s|
s.homepage = PROJECT_URL
s.add_dependency('merb-core', '>= 0.9.8')
s.require_path = 'lib'
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*") end
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
end

Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end

desc "Install the gem"
task :install => [:package] do
sh install_command(GEM_NAME, GEM_VERSION)
task :install do
Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
end

namespace :jruby do
desc "Uninstall the gem"
task :uninstall do
Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
end

desc "Run :package and install the resulting .gem with jruby"
task :install => :package do
sh jinstall_command(GEM_NAME, GEM_VERSION)
desc "Create a gemspec file"
task :gemspec do
File.open("#{GEM_NAME}.gemspec", "w") do |file|
file.puts spec.to_ruby
end

end

desc "Run all specs"
Spec::Rake::SpecTask.new("specs") do |t|
t.spec_opts = ["--format", "specdoc", "--colour"]
t.spec_files = Dir["spec/**/*_spec.rb"].sort
desc "Run all examples (or a specific spec with TASK=xxxx)"
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_opts = ["-cfs"]
t.spec_files = begin
if ENV["TASK"]
ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
else
FileList['spec/**/*_spec.rb']
end
end
end

desc 'Default: run spec examples'
task :default => 'spec'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class <%= class_name %> < ActiveRecord::Migration
def self.up
<% if model -%>
create_table :<%= table_name %> do |t|
<% attributes.each do |name, type| -%>
<% attributes.each do |type, name| -%>
t.<%= name %> :<%= type %>
<% end -%>
Expand Down
3 changes: 3 additions & 0 deletions merb_activerecord/lib/merb_activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def self.run
Merb.logger.debug "Using ActiveRecord sessions"
require File.join(File.dirname(__FILE__) / "merb" / "session" / "active_record_session")
end
# The default identify is :id instead of :to_param so that the identify
# can be used as the default resource key
Merb::Router.root_behavior = Merb::Router.root_behavior.identify(ActiveRecord::Base => :id)
end

end
Expand Down
1 change: 0 additions & 1 deletion merb_activerecord/specs/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$TESTING = true
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
require 'merb-core'
require 'merb_activerecord'
16 changes: 16 additions & 0 deletions merb_auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
log/*
*.log
db/
*.db
.DStore
.DS_Store
pkg
pkg/*
:memory:
examples/example_app/config/open_id
merb-auth-core/coverage
examples/example_app/tmp
merb-auth-core/log
merb-auth-more/log
merb-auth-more/coverage

14 changes: 14 additions & 0 deletions merb_auth/README.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
h1. MerbAuth - Merb Authentication

h2. An extensible architecture for authentication

* Stupidly Simple
* Speaks fluent HTTP, even the errors
* Pluggable Architecture (so that you can use any authentication algorithms you like)
* Cascading Authentication (if one method fails, another is attempted, then another. When no methods succeed, authentication fails)

h2. Principles

# Sessions are authenticated, not users.
# Just because one method of authentication fails doesn't mean the session, can't be authenticated another way. This is especially true if your application has an external API as well as a public interface.
# HTTP has built-in "Errors":http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html which every web-browser (should) know how to speak. If you're application speaks in HTTP Verbs (GET, POST, PUT, DELETE), it should also serve the correct HTTP Errors when things go wrong.
75 changes: 75 additions & 0 deletions merb_auth/examples/example_app/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'rubygems'
Gem.clear_paths
Gem.path.unshift(File.join(File.dirname(__FILE__), "gems"))

require 'rake'
require 'rake/rdoctask'
require 'rake/testtask'
require 'spec/rake/spectask'
require 'fileutils'

##
# requires frozen merb-core (from /framework)
# adds the other components to the load path
def require_frozen_framework
framework = File.join(File.dirname(__FILE__), "framework")
if File.directory?(framework)
puts "Running from frozen framework"
core = File.join(framework,"merb-core")
if File.directory?(core)
puts "using merb-core from #{core}"
$:.unshift File.join(core,"lib")
require 'merb-core'
end
more = File.join(framework,"merb-more")
if File.directory?(more)
Dir.new(more).select {|d| d =~ /merb-/}.each do |d|
$:.unshift File.join(more,d,'lib')
end
end
plugins = File.join(framework,"merb-plugins")
if File.directory?(plugins)
Dir.new(plugins).select {|d| d =~ /merb_/}.each do |d|
$:.unshift File.join(plugins,d,'lib')
end
end
require "merb-core/core_ext/kernel"
require "merb-core/core_ext/rubygems"
else
p "merb doesn't seem to be frozen in /framework"
require 'merb-core'
end
end

if ENV['FROZEN']
require_frozen_framework
else
require 'merb-core'
end

require 'merb-core/tasks/merb'
include FileUtils

# Load the basic runtime dependencies; this will include
# any plugins and therefore plugin rake tasks.
init_env = ENV['MERB_ENV'] || 'rake'
Merb.load_dependencies(:environment => init_env)

# Get Merb plugins and dependencies
Merb::Plugins.rakefiles.each { |r| require r }

# Load any app level custom rakefile extensions from lib/tasks
tasks_path = File.join(File.dirname(__FILE__), "lib", "tasks")
rake_files = Dir["#{tasks_path}/*.rake"]
rake_files.each{|rake_file| load rake_file }


desc "start runner environment"
task :merb_env do
Merb.start_environment(:environment => init_env, :adapter => 'runner')
end

##############################################################################
# ADD YOUR CUSTOM TASKS IN /lib/tasks
# NAME YOUR RAKE FILES file_name.rake
##############################################################################
2 changes: 2 additions & 0 deletions merb_auth/examples/example_app/app/controllers/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Application < Merb::Controller
end
13 changes: 13 additions & 0 deletions merb_auth/examples/example_app/app/controllers/exceptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Exceptions < Application

# handle NotFound exceptions (404)
def not_found
render :format => :html
end

# handle NotAcceptable exceptions (406)
def not_acceptable
render :format => :html
end

end
8 changes: 8 additions & 0 deletions merb_auth/examples/example_app/app/controllers/welcome.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Welcome < Application
before :ensure_authenticated

def index
"We're In #{request.full_uri}"
end

end
5 changes: 5 additions & 0 deletions merb_auth/examples/example_app/app/helpers/global_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Merb
module GlobalHelpers
# helpers defined here available to all views.
end
end
40 changes: 40 additions & 0 deletions merb_auth/examples/example_app/app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class User
include DataMapper::Resource

property :id, Serial
property :login, String
property :email, String
property :crypted_password, String, :length => 150
property :salt, String, :length => 150
property :active, Boolean, :default => false
property :identity_url, String

validates_present :login, :email
validates_is_unique :login, :email
validates_format :email, :as => :email_address

attr_accessor :password, :password_confirmation
validates_is_confirmed :password

before :save, :encrypt_password

def active?
!!self.active
end

def self.encrypt(salt, password = nil)
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
end

def self.authenticate(login, password)
u = self.first(:login => login)
return nil unless u
u.crypted_password == encrypt(u.salt, password) ? u : nil
end

def encrypt_password
self.salt ||= Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--")
self.crypted_password ||= User.encrypt(salt, password)
end

end
Loading

0 comments on commit bb2b2c1

Please sign in to comment.