Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
michi committed Apr 11, 2014
1 parent 583b0a6 commit c229ef2
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@ meta
upload/*
public/thumbnails
config/config.yml
.idea
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
2.1.1
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'sinatra', "~> 1.3"
gem 'sinatra', '~> 1.3'
gem 'compass'
gem 'zurb-foundation'
gem 'puma'
Expand Down
42 changes: 21 additions & 21 deletions app.rb
Expand Up @@ -35,11 +35,11 @@ class App < Sinatra::Base
configure do
Compass.configuration do |config|
config.project_path = File.dirname __FILE__
config.sass_dir = File.join "views", "scss"
config.images_dir = File.join "views", "images"
config.http_path = "/"
config.http_images_path = "/images"
config.http_stylesheets_path = "/stylesheets"
config.sass_dir = File.join 'views', 'scss'
config.images_dir = File.join 'views', 'images'
config.http_path = '/'
config.http_images_path = '/images'
config.http_stylesheets_path = '/stylesheets'
config.line_comments = false
config.output_style = :compressed
end
Expand Down Expand Up @@ -94,18 +94,18 @@ def sort_things_right
before do
@p = Picture.all
if @p.empty?
flash[:notice] = "No documents found!"
flash[:notice] = 'No documents found!'
end
end


helpers do
def asset_stylesheet(stylesheet)
"/stylesheets/#{stylesheet}.css?" + File.mtime(File.join(Sinatra::Application.views, "sass", "#{stylesheet}.scss")).to_i.to_s
"/stylesheets/#{stylesheet}.css?" + File.mtime(File.join(Sinatra::Application.views, 'sass', "#{stylesheet}.scss")).to_i.to_s
end

def asset_javascript(js)
"/javascripts/#{js}.js?" + File.mtime(File.join(Sinatra::Application.public_folder, "javascripts", "#{js}.js")).to_i.to_s
"/javascripts/#{js}.js?" + File.mtime(File.join(Sinatra::Application.public_folder, 'javascripts', "#{js}.js")).to_i.to_s
end

def admin?
Expand Down Expand Up @@ -153,8 +153,8 @@ def filter_item(url, text=url)

end

get "/stylesheets/*.css" do |path|
content_type "text/css", charset: "utf-8"
get '/stylesheets/*.css' do |path|
content_type 'text/css', charset: 'utf-8'
response['Expires'] = (Time.now + 60*60*24*356*3).httpdate
scss :"sass/#{path}"
end
Expand All @@ -172,10 +172,10 @@ def filter_item(url, text=url)
if params['username']==settings.username && params['password']==settings.password
response.set_cookie(settings.username, {:value => settings.login_token, :expires => Time.now + (60*60*24*2)})
response.set_cookie('view_token', {:value => settings.view_token, :path => '/'}) if settings.use_view_token
flash[:success] = "Login succeeded!"
flash[:success] = 'Login succeeded!'
redirect '/'
else
flash[:alert] = "Login failed!"
flash[:alert] = 'Login failed!'
redirect '/'
end
end
Expand All @@ -196,16 +196,16 @@ def filter_item(url, text=url)

get '/logout' do
response.set_cookie(settings.username, false)
flash[:success] = "Logout successful!"
flash[:success] = 'Logout successful!'
redirect '/'
end

get "/upload" do
get '/upload' do
protected!
haml :upload, :layout => !request.xhr?
end

post "/upload" do
post '/upload' do
protected!
content_type 'application/json', :charset => 'utf-8' if request.xhr?
if params[:file] && params[:file][:type].match(/image\/(gif|png|jpe?g)/)
Expand All @@ -225,7 +225,7 @@ def filter_item(url, text=url)
picture.to_json
else
flash[:alert] = 'You have to choose an image file first'
redirect "/upload"
redirect '/upload'
end

end
Expand All @@ -246,7 +246,7 @@ def filter_item(url, text=url)
end

get '/t/:image_id' do |image_id|
Picture.find(image_id).image.thumb("400x400#").to_response(env)
Picture.find(image_id).image.thumb('400x400#').to_response(env)
end

delete '/d/:image_id' do |image_id|
Expand All @@ -262,28 +262,28 @@ def filter_item(url, text=url)
redirect '/'
end
else
flash[:alert] = "ERROR!"
flash[:alert] = 'ERROR!'
end
end

get '/date/:date_time' do |date_time|
need_token!
@awl = "http://www.amazon.de/registry/wishlist/#{settings.amazon_whishlist}"
@all_year = Picture.all.map{|p| p.created_at.year}.uniq
@all_year = Picture.all.map{|p| p.created_at.year}.uniq.sort
@pictures = Picture.where(:created_at.gte => "#{date_time}-01-01", :created_at.lte => "#{date_time}-12-31").asc(:sort_key)
haml :index
end

get '/' do
need_token!
@awl = "http://www.amazon.de/registry/wishlist/#{settings.amazon_whishlist}"
@all_year = Picture.all.map{|p| p.created_at.year}.uniq
@all_year = Picture.all.map{|p| p.created_at.year}.uniq.sort
@pictures = Picture.all.asc(:sort_key)
haml :index
end

not_found do
flash[:notice] = "404 - Page not found"
flash[:notice] = '404 - Page not found'
redirect '/'
end

Expand Down
4 changes: 2 additions & 2 deletions config.ru
@@ -1,9 +1,9 @@
require 'rubygems' unless RUBY_VERSION >= '1.9'
require 'sinatra'
require 'rack/cache'
require "./app"
require './app'

if ENV["RACK_ENV"] == 'production'
if ENV['RACK_ENV'] == 'production'
use Rack::Cache,
:metastore => 'memcached://localhost:11211/meta',
:entitystore => 'memcached://localhost:11211/body',
Expand Down
4 changes: 2 additions & 2 deletions seed.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require 'rubygems' unless RUBY_VERSION >= '1.9'
require "./app"
require './app'

App::Picture.all.each do |p|
if p.delete
Expand All @@ -27,5 +27,5 @@ def run(command)
raise("error, process exited with status #{$?.exitstatus}") unless result
end

cmd = "bundle exec puma config.ru"
cmd = 'bundle exec puma config.ru'
run cmd
12 changes: 6 additions & 6 deletions views/edit.haml
Expand Up @@ -7,13 +7,13 @@

.large-4.columns
- if admin?
%form(action="/e/#{@picture.id}" method="post")
%form(action="/e/#{@picture.id}" method='post')
%fieldset
%legend Edit image
.row
.large-12.columns
%label Picture ID
%input{:type => 'text', :placeholder => "#{@picture.id}", :disabled => ""}
%input{:type => 'text', :placeholder => "#{@picture.id}", :disabled => ''}
.row
.large-12.columns
%label Sort key
Expand All @@ -26,10 +26,10 @@
.small-6.large-6.columns
%a.small.button.info.radius{:href => '/'} Go Back
.small-6.large-6.columns
%input{:type => :hidden, :name => "_method", :value => "put"}
%input.small.button.success.radius.right{:type => "submit", :value => "Update"}
%input{:type => :hidden, :name => 'method', :value => 'put'}
%input.small.button.success.radius.right{:type => 'submit', :value => 'Update'}
%form{:action => "/d/#{@picture.id}", :method => 'post'}
.row
.large-12.columns
%input{:type => :hidden, :name => "_method", :value => "delete"}
%input.button.alert.expand.radius{:type => "submit", :value => "Delete this Image"}
%input{:type => :hidden, :name => 'method', :value => 'delete'}
%input.button.alert.expand.radius{:type => 'submit', :value => 'Delete this Image'}
4 changes: 2 additions & 2 deletions views/error.haml
Expand Up @@ -5,5 +5,5 @@
%p An error accured. Our techs are on it.
%p
In the meantime you can always go
= succeed "." do
%a{:href => "/"} back
= succeed '.' do
%a{:href => '/'} back
42 changes: 21 additions & 21 deletions views/index.haml
Expand Up @@ -2,7 +2,7 @@
.large-8.columns
%dl.sub-nav
%dt Filter:
= filter_item("/", "Alle")
= filter_item('/', 'Alle')
- @all_year.each do |year|
= filter_item("/date/#{year}", "#{year}")

Expand All @@ -12,34 +12,34 @@
- @pictures.each do |key|
%li{'sort_key' => "#{key.sort_key}"}
%a.fancybox{:href => "#{key.image.thumb('800x800').url}", 'data-fancybox-group' => 'button', :title => "#{key.image_title}"}
%img.lazy{'data-original' => "#{key.image.thumb('200x200#ne').url}", :src => "/image/grey.gif"}
%img.lazy{'data-original' => "#{key.image.thumb('200x200#ne').url}", :src => '/image/grey.gif'}
-if admin?
%form(action="/d/#{key.id}" method="post")
%input{:type => :hidden, :name => "_method", :value => "delete"}
%form(action="/d/#{key.id}" method='post')
%input{:type => :hidden, :name => 'method', :value => 'delete'}
%a.tiny.button.info.radius{:href => "/e/#{key.id}"} Edit
%input.tiny.button.alert.radius{:type => "submit", :value => "Delete"}
%input.tiny.button.alert.radius{:type => 'submit', :value => 'Delete'}

- if @pictures.count > 12
.row
.large-6.columns
.paging
-#.large-6.columns
%form.custom.right
%label{:for => "customDropdown"} Bilder pro Seite
%label{:for => 'customDropdown'} Bilder pro Seite
%select#customDropdown.small
%option 12
%option 18
%option alle

= haml :sidebar

%script{:src => asset_javascript('jquery.fancybox.pack'), :type => "text/javascript"}
%script{:src => asset_javascript('jquery.fancybox.pack'), :type => 'text/javascript'}
%script{:src => asset_javascript('jquery.lazyload.min'), :type => 'text/javascript'}
%script{:src => asset_javascript('jPages.min'), :type => 'text/javascript'}
-if admin?
:javascript
$(document).ready(function() {
$( "#gallery" ).sortable({
$('#gallery').sortable({
distance: 30,
cursor: 'move',
update: function(event, ui) {
Expand All @@ -48,7 +48,7 @@
console.log('item after:' + ui.item.next().attr('sort_key'));
}
});
$( "#gallery" ).disableSelection();
$('#gallery').disableSelection();
});

:javascript
Expand Down Expand Up @@ -79,24 +79,24 @@
//});


$("img").lazyload({
event: "turnPage",
effect: "fadeIn"
$('img').lazyload({
event: 'turnPage',
effect: 'fadeIn'
});

$(".paging").jPages({
containerID: "gallery",
animation: "flipInY",
direction: "random",
$('.paging').jPages({
containerID: 'gallery',
animation: 'flipInY',
direction: 'random',
perPage: 12,
keyBrowse: true,
previous : "",
next : "",
previous : '',
next : '',
callback: function(pages, items ){
/* lazy load current images */
items.showing.find("img").trigger("turnPage");
items.showing.find('img').trigger('turnPage');
/* lazy load next page images */
items.oncoming.find("img").trigger("turnPage");
items.oncoming.find('img').trigger('turnPage');
}
});

Expand All @@ -119,7 +119,7 @@
},
beforeShow: function () {
/* Disable right click */
$.fancybox.wrap.bind("contextmenu", function (e) {
$.fancybox.wrap.bind('contextmenu', function (e) {
return false;
});
},
Expand Down
16 changes: 8 additions & 8 deletions views/layout.haml
Expand Up @@ -4,27 +4,27 @@
/[if IE 7] <html class="no-js lt-ie9 lt-ie8" lang="en">
/[if IE 8] <html class="no-js lt-ie9" lang="en">
/ [if gt IE 8]><!
%html.no-js{:lang => "de"}
%html.no-js{:lang => 'de'}
/ <![endif]
%head
%meta{:charset => "utf-8"}/
%meta{:charset => 'utf-8'}/
/ Set the viewport width to device width for mobile
%meta{:content => "width=device-width", :name => "viewport"}/
%meta{:content => 'width=device-width', :name => 'viewport'}/
%title= page_title
/ Included CSS Files
%link{:href => asset_stylesheet('app'), :rel => "stylesheet"}
%link{:href => asset_stylesheet('app'), :rel => 'stylesheet'}

%script{:src => asset_javascript('jquery.min'), :type => 'text/javascript'}
-if admin?
%script{:src => asset_javascript('jquery-ui-1.9.2.custom.min'), :type => "text/javascript"}
%script{:src => asset_javascript('jquery-ui-1.9.2.custom.min'), :type => 'text/javascript'}
%script{:src => asset_javascript('modernizr.custom'), :type => 'text/javascript'}
/:javascript
/ document.write('<script src=' +
/ ('__proto__' in {} ? 'javascripts/vendor/zepto' : 'javascripts/vendor/jquery') +
/ '.js><\/script>')
/ IE Fix for HTML5 Tags
/[if lt IE 9]
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src='http://html5shiv.googlecode.com/svn/trunk/html5.js'></script>
%body
.row
.large-12.columns
Expand All @@ -47,7 +47,7 @@
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://#{piwik_site}//";
var u=(('https:' == document.location.protocol) ? 'https' : 'http') + "://#{piwik_site}//";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', "#{piwik_id}"]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
Expand All @@ -56,5 +56,5 @@

%noscript
%p
%img{:alt => "", :src => "http://#{piwik_site}/piwik.php?idsite=#{piwik_id}", :style => "border:0"}/
%img{:alt => '', :src => "http://#{piwik_site}/piwik.php?idsite=#{piwik_id}", :style => 'border:0'}/
/ End Piwik Code
2 changes: 1 addition & 1 deletion views/need_token.haml
Expand Up @@ -2,4 +2,4 @@
.large-12.columns
.panel.radius
%h3.subheader Oops.
%p Diese Webseiten benötigen einen Zugangsschlüssel.
%p Diese Webseiten benötigen einen Zugangsschlüssel.
4 changes: 2 additions & 2 deletions views/notification.haml
@@ -1,5 +1,5 @@
- %w[alert success notice].each do |key|
- if flash[key]
%div{:class => "alert-box #{key}", "data-alert" => ""}
%div{:class => "alert-box #{key}", 'data-alert' => ''}
= flash[key]
%a.close{:href => "#"} &times;
%a.close{:href => '#'} &times;
4 changes: 1 addition & 3 deletions views/sidebar.haml
Expand Up @@ -10,6 +10,4 @@
.large-7.columns
-# %a{:href => item.css('span[class="small productTitle"] a').attr('href').value}
%a{:href => @awl, :target => '_blank'}
= item.css('span[class="small productTitle"] a').text


= item.css('span[class="small productTitle"] a').text

0 comments on commit c229ef2

Please sign in to comment.