Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add downloads page #10

Merged
merged 2 commits into from

4 participants

@wasnotrice
Owner

This is my first date with Webmachine, so tell me, is this a good way to handle our offsite downloads? We provide a shoesrb.com URL, then redirect to an external file.

wasnotrice added some commits
@wasnotrice wasnotrice Ignore .rvmrc a685738
@wasnotrice wasnotrice Add downloads
Add a downloads page and a handler for individual downloads.
The download handler translates a URL that looks like this:

    http://shoesrb.com/downloads/filename.zip

into a redirect to an external URL, where the file is actually located.
To add a new download, just map the local filename to the remote url
in download_resource.rb.
7ae40db
@wpp
wpp commented

:+1: sweet! After this is merged I'll try to make it a bit prettier.

@steveklabnik steveklabnik commented on the diff
.gitignore
@@ -1,3 +1,5 @@
# IDEs
/.idea
+.rvmrc
@steveklabnik Owner

I generally think this is a bad idea, but I don't use rvm anymore, so I guess I don't care. :wink:

@PragTob Owner
PragTob added a note

Hm I also like to have the .rvmrc right in the repository... :o

@wasnotrice Owner

Feel free to revert. My intent was to make it easier for someone to work with whatever ruby they have on their system. For this project, it shouldn't really matter.

Certainly this line doesn't belong in this commit ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@steveklabnik steveklabnik merged commit e151380 into master
@steveklabnik
Owner

Seems good! :heart:

@wpp pretty away!

@wasnotrice wasnotrice referenced this pull request
Closed

Downloads are missing #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 4, 2013
  1. @wasnotrice

    Ignore .rvmrc

    wasnotrice authored
  2. @wasnotrice

    Add downloads

    wasnotrice authored
    Add a downloads page and a handler for individual downloads.
    The download handler translates a URL that looks like this:
    
        http://shoesrb.com/downloads/filename.zip
    
    into a redirect to an external URL, where the file is actually located.
    To add a new download, just map the local filename to the remote url
    in download_resource.rb.
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -1,3 +1,5 @@
# IDEs
/.idea
+.rvmrc
@steveklabnik Owner

I generally think this is a bad idea, but I don't use rvm anymore, so I guess I don't care. :wink:

@PragTob Owner
PragTob added a note

Hm I also like to have the .rvmrc right in the repository... :o

@wasnotrice Owner

Feel free to revert. My intent was to make it easier for someone to work with whatever ruby they have on their system. For this project, it shouldn't really matter.

Certainly this line doesn't belong in this commit ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
View
2  config.ru
@@ -15,6 +15,8 @@ Shoes = Webmachine::Application.new do |app|
add ["blog"], BlogResource
add ["blog", :slug], BlogResource
add ["contribute"], ContributePage
+ add ["downloads"], DownloadsPage
+ add ["downloads", :filename], DownloadResource
add ['*'], StaticResource, :root => "public"
end
app.configure do |config|
View
33 resources/download_resource.rb
@@ -0,0 +1,33 @@
+# Manager for downloads hosted elsewhere. Handles redirects from shoesrb.com
+# URLs to the URLs where resources actually live.
+#
+# Request downloads by filename like this:
+#
+# GET /downloads/filename.zip HTTP/1.1
+#
+# Manage redirects to actual resources by adding to the DOWNLOADS hash:
+#
+# "filename.zip" => "http://url/for/actual/filename.zip"
+#
+class DownloadResource < Webmachine::Resource
+ DOWNLOADS = {
+ "shoes-app-template-0.0.1.zip" => "https://s3.amazonaws.com/net.wasnotrice.shoes/wrappers/shoes-app-template-0.0.1.zip"
+ }
+
+ # shows up in the URL like so: http://shoesrb.com/downloads/:filename
+ def filename
+ @request.path_info[:filename]
+ end
+
+ def resource_exists?
+ false
+ end
+
+ def previously_existed?
+ DOWNLOADS.has_key?(filename)
+ end
+
+ def moved_permanently?
+ previously_existed? && DOWNLOADS[filename]
+ end
+end
View
5 resources/downloads_page.rb
@@ -0,0 +1,5 @@
+class DownloadsPage < Webmachine::Resource
+ def to_html
+ Template.new(:downloads).render
+ end
+end
View
19 views/downloads.html.haml
@@ -0,0 +1,19 @@
+.hero-unit
+ .downloads
+ %h1 Downloads
+ %p Get your Shoes and Shoes Accessories Here.
+
+.row
+ .span5
+ %h2 Shoes
+ #shoes
+
+ .span5
+ %h2 Shoes Accessories
+ #accessories
+
+ %h3 App Wrappers
+ %ul
+ %li
+ %a{:href => "/downloads/shoes-app-template-0.0.1.zip"} OS X .app wrapper
+
View
2  views/layout.html.haml
@@ -36,6 +36,8 @@
%li.active
%a{:href => "/"} Home
%li
+ %a{:href => "/downloads"} Downloads
+ %li
%a{:href => "/tutorials"} Tutorials
%li
%a{:href => "/blog"} Blog
Something went wrong with that request. Please try again.