Permalink
Browse files

added carrierwave tweaks for heroku, removed subdomaining

  • Loading branch information...
1 parent 722d610 commit d6ea58dbc116ab9f48cd183405845db58373c563 @cyx cyx committed Mar 13, 2010
View
32 .gems
@@ -0,0 +1,32 @@
+activemodel --version 3.0.0.beta
+activerecord --version 3.0.0.beta
+activesupport --version 3.0.0.beta
+archive-tar-minitar --version 0.5.2
+arel --version 0.2.1
+aws-s3 --version 0.6.2
+builder --version 2.1.2
+carrierwave --version 0.4.5
+chronic --version 0.2.3
+columnize --version 0.3.1
+crack --version 0.1.7
+dependencies --version 0.0.8
+gem_plugin --version 0.2.3
+haml --version 2.2.20
+hashie --version 0.1.8
+hoe --version 2.5.0
+httparty --version 0.4.5
+i18n --version 0.3.5
+image_science --version 1.2.1
+memcache-client --version 1.7.8
+mime-types --version 1.16
+oauth --version 0.3.6
+ruby-hmac --version 0.4.0
+ruby_core_source --version 0.1.4
+rubyforge --version 2.0.4
+RubyInline --version 3.8.4
+sinatra --version 1.0.b
+thor --version 0.13.4
+twitter --version 0.8.4
+twitter-login --version 0.2.0
+tzinfo --version 0.3.17
+xml-simple --version 1.0.12
View
@@ -3,3 +3,29 @@ task :environment do
end
load 'lib/tasks/database.rake'
+
+desc "Generate a .gems manifest file for use with heroku"
+task :create_heroku_gems_manifest do
+ skip = %w(factory_girl database_cleaner daemons eventmachine faker
+ fakeweb fastthread gemcutter json json_pure linecache19
+ mysql sqlite3-ruby nokogiri rack rack-test rake
+ rspec-core rspec rspec-expectations rspec-mocks
+ rspec-rails-matchers ruby-debug-base19 ruby-debug19
+ thin timecop webrat ZenTest)
+
+ rvm_gems = File.read("config/rvm.gems").split("\n")
+
+ File.open('.gems', 'w') do |f|
+ rvm_gems.each do |gem|
+ name, version = gem.split(" -v")
+
+ next if gem.index('#') == 0
+ next if skip.include?(name)
+
+ f.write "#{name} --version #{version}\n"
+ end
+ end
+
+ puts " => Created .gems"
+ puts File.read('.gems')
+end
View
@@ -24,7 +24,7 @@ def inside?( *path_methods )
if path.blank?
request.request_method == method.upcase
elsif method.blank?
- path.index(request.fullpath)
+ request.fullpath.index(path)
else
request.fullpath.index(path) && method.upcase == request.request_method
end
@@ -1,31 +1,23 @@
class Main
helpers do
- def root_url( options = {} )
- if options.empty?
- '/'
- elsif options[:host]
- options[:host]
- end
+ def root_url
+ '/'
end
def user_url( user )
- account_url(user.username) + '/items'
+ '/%s/items' % user.username
end
def new_item_path
'/items/new'
end
- def everyone_items_url
- account_url('www') + '/items'
- end
-
- def absolute_item_url( item )
- account_url(item.user.username) + '/items/' + item.to_param
+ def everyones_items_url
+ '/%s/items' % AnonymousUser::USERNAME
end
def item_path( item )
- '/items/' + item.to_param
+ '/%s/%s' % [ item.user.username, item.to_param ]
end
def new_reply_path(options = {})
@@ -37,7 +29,7 @@ def retweets_path(options = {})
end
def most_viewed_url
- '/most-viewed'
+ '/%s/most-viewed' % AnonymousUser::USERNAME
end
def login_url
@@ -52,24 +44,30 @@ def items_path
'/items'
end
- def tagged_items_path( tag )
- '/items/tagged/' + tag
+ def tagged_items_path( user, tag )
+ '/%s/tagged/%s' % [ user.username, tag ]
end
- def liked_path
- '/liked'
+ def liked_path( user )
+ case user
+ when User
+ '/%s/liked' % user.username
+ else
+ '/%s/liked' % AnonymousUser::USERNAME
+ end
end
- def like_path( item )
- '/likes/' + item.to_s
+ def like_path( item_id )
+ raise TypeError unless Fixnum === item_id
+ '/likes/%s' % item_id
end
def likes_path( options = {} )
append_query_string( "/likes", options )
end
- def friends_items_path
- '/friends-items'
+ def friends_items_path( user )
+ '/%s/friends-items' % user.username
end
private
@@ -1,9 +1,15 @@
class AnonymousUser
+ USERNAME = 'everyone'
+
def items
Item.where
end
def likes_items
Item.most_liked
end
+
+ def username
+ USERNAME
+ end
end
View
@@ -18,7 +18,7 @@ class Item < ActiveRecord::Base
:uniqueness => { :allow_blank => true }
scope :latest, order('id DESC')
- scope :most_viewed, order('id DESC')
+ scope :most_viewed, order('views_count DESC')
scope :most_liked, where('likes_count != 0').order('likes_count DESC')
scope :tagged, lambda { |t| includes(:tags).where('tags.name' => t) }
@@ -78,6 +78,10 @@ def viewed!
self.class.increment_counter(:views_count, self.id)
end
+ def to_param
+ "%s-%s" % [ id, name.gsub(/[^a-zA-Z0-9]/, '-').downcase ]
+ end
+
private
def valid_amount?( amount )
begin
@@ -8,6 +8,6 @@ def initialize( url )
end
def original_filename
- [ Digest::SHA1.hexdigest(@url), File.extname(@url).downcase ].join('.')
+ [ Digest::SHA1.hexdigest(@url), File.extname(@url).downcase ].join
end
end
@@ -7,7 +7,7 @@ def initialize( user )
end
[ :get, :put, :delete, :post, :head ].each do |meth|
- if RACK_ENV == 'development' and not [ :get ].include?(meth)
+ if ENV["ENABLE_TWITTER_STATUS_POSTING"].nil?
define_method meth do |path, *arguments|
logger.info "#{meth}, #{path}, #{arguments.inspect}"
puts "#{meth}, #{path}, #{arguments.inspect}"
View
@@ -6,13 +6,18 @@ class Main
post "/api/v1/items" do
require_api_user
- @user = User.find_by_login!( params[:login] )
- @item = @user.items.build(params[:item])
-
- if @item.save
- @item.to_json
+ begin
+ @user = User.find_by_login!( params[:login] )
+ rescue ActiveRecord::RecordNotFound
+ "User not found #{params[:login]}"
else
- { :errors => @item.errors }.to_json
+ @item = @user.items.build(params[:item])
+
+ if @item.save
+ @item.to_json
+ else
+ { :errors => @item.errors }.to_json
+ end
end
end
end
View
@@ -1,32 +1,44 @@
class Main
- get "/" do
- if User === @account
- @items = @account.items.latest.paginate(page: params[:page])
-
- haml :'items/index'
- else
- haml :'home'
+ get '/:username/:filter' do |username, filter|
+ if %w(items most-viewed liked friends-items).include?(filter)
+ unless username == AnonymousUser::USERNAME
+ @account = User.find_by_username( username )
+ else
+ @account = AnonymousUser.new
+ end
end
+
+ pass
+ end
+
+ get '/' do
+ haml :'home'
end
- get "/items/?" do
+ get '/:username/items' do
@items = @account.items.latest.paginate(page: params[:page])
haml :'items/index'
end
- get "/most-viewed" do
- @items = @account.items.latest.paginate(page: params[:page])
+ get "/:username/most-viewed" do
+ @items = @account.items.most_viewed.paginate(page: params[:page])
haml :'items/index'
end
- get "/liked" do
+ get "/:username/liked" do
@items = @account.likes_items.latest.paginate(page: params[:page])
haml :'items/index'
end
+ get '/:username/friends-items' do
+ @items = @account.friends_items.latest.paginate(:page => params[:page])
+
+ haml :'items/index'
+ end
+
get "/items/new" do
login_required
@@ -35,8 +47,9 @@ class Main
haml :'items/new'
end
- get "/items/:id" do |id|
- @item = @account.items.find(id)
+ get "/:username/:id" do |username, id|
+ @account = User.find_by_username(username)
+ @item = @account.items.find(id)
@item.viewed!
haml :'items/show'
@@ -54,18 +67,12 @@ class Main
end
end
- delete "/items/:id" do |id|
+ delete "/item/:id" do |id|
login_required
@item = current_user.items.find(id)
@item.destroy
{ :location => user_url(@item.user) }.to_json
end
-
- get '/friends-items' do
- @items = @account.friends_items.latest.paginate(:page => params[:page])
-
- haml :'items/index'
- end
end
View
@@ -1,12 +1,4 @@
class Main
- before do
- if account_subdomain and account_subdomain != 'www'
- @account = User.find_by_username( account_subdomain )
- else
- @account = AnonymousUser.new
- end
- end
-
get '/authenticated' do
if twitter_user
self.current_user =
View
@@ -5,8 +5,29 @@ def cached_file_id( uploader )
end
def generate_unique_filename( filename )
- [ UUID.sha1, File.extname(filename).downcase ].join('.')
+ [ UUID.sha1, File.extname(filename).downcase ].join
end
+
+ def assert_valid_cache_id!( cache_id )
+ unless cache_id.match(Format::CARRIER_WAVE_CACHE_ID)
+ raise "Not a valid cache id #{cache_id}"
+ end
+ end
+
+ def assert_valid_filename!( filename )
+ unless filename.match(Format::CARRIER_WAVE_FILENAME)
+ raise "Not a valid filename #{filename}"
+ end
+ end
+ end
+
+ get '/tmp/uploads/:cache_id/:filename' do |cache_id, filename|
+ assert_valid_cache_id!( cache_id )
+ assert_valid_filename!( filename )
+
+
+ send_file root_path("tmp", "uploads", cache_id, filename),
+ :disposition => 'inline'
end
post '/uploader' do
@@ -1,5 +1,5 @@
class PhotoUploader < CarrierWave::Uploader::Base
- include CarrierWave::ImageScience
+ include CarrierWave::RMagick
settings(:photos).each do |key, value|
send key, String === value ? value.gsub(':root', root_path) : value
@@ -20,4 +20,9 @@ def extension_white_list
def default_url
"/photos/#{version_name}/missing.jpg"
end
+
+ def url( *args )
+ ret = super(*args)
+ ret.gsub(root_path, '')
+ end
end
Oops, something went wrong.

0 comments on commit d6ea58d

Please sign in to comment.