Refactor app size/theme methods

pull/241/head
Thibaut 10 years ago
parent e2b86742a4
commit b3c569bf6e

@ -128,11 +128,11 @@ class App < Sinatra::Application
end end
def main_stylesheet_path def main_stylesheet_path
stylesheet_paths[cookies[:dark].nil? ? :default : :dark] stylesheet_paths[dark_theme? ? :dark : :default]
end end
def alternate_stylesheet_path def alternate_stylesheet_path
stylesheet_paths[cookies[:dark].nil? ? :dark : :default] stylesheet_paths[dark_theme? ? :default : :dark]
end end
def stylesheet_paths def stylesheet_paths
@ -142,8 +142,16 @@ class App < Sinatra::Application
} }
end end
def size def app_size
@size ||= cookies[:size].nil? ? '18rem' : "#{cookies[:size]}px" @app_size ||= cookies[:size].nil? ? '18rem' : "#{cookies[:size]}px"
end
def app_theme
@app_theme ||= cookies[:dark].nil? ? 'default' : 'dark'
end
def dark_theme?
app_theme == 'dark'
end end
end end

@ -69,17 +69,17 @@ class AppTest < MiniTest::Spec
assert_includes last_response.body, '/html/index.json' assert_includes last_response.body, '/html/index.json'
end end
it "includes has the word 'light' by default" do it "has the word 'default' when no 'dark' cookie is set" do
get '/manifest.appcache' get '/manifest.appcache'
assert_includes last_response.body, '# light' assert_includes last_response.body, '# default'
refute_includes last_response.body, '# dark' refute_includes last_response.body, '# dark'
end end
it "includes has the word 'dark' when the cookie is set" do it "has the word 'dark' when the cookie is set" do
set_cookie('dark=1') set_cookie('dark=1')
get '/manifest.appcache' get '/manifest.appcache'
assert_includes last_response.body, '# dark' assert_includes last_response.body, '# dark'
refute_includes last_response.body, '# light' refute_includes last_response.body, '# default'
end end
it "sets default size" do it "sets default size" do

@ -44,9 +44,9 @@
a.src="//secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0]; a.src="//secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0];
b.parentNode.insertBefore(a,b)}(); b.parentNode.insertBefore(a,b)}();
</script><% end %> </script><% end %>
<style data-size="<%= size %>" data-resizer> <style data-size="<%= app_size %>" data-resizer>
._container { margin-left: <%= size %>; } ._container { margin-left: <%= app_size %>; }
._search, ._list, ._sidebar-footer { width: <%= size %>; } ._search, ._list, ._sidebar-footer { width: <%= app_size %>; }
._list-hover.clone { min-width: <%= size %>; } ._list-hover.clone { min-width: <%= app_size %>; }
._notice, ._path, ._resizer { left: <%= size %>; } ._notice, ._path, ._resizer { left: <%= app_size %>; }
</style> </style>

@ -1,5 +1,5 @@
CACHE MANIFEST CACHE MANIFEST
# <%= cookies[:dark].nil? ? 'light' : 'dark' %> <%= size %> # <%= app_theme %> <%= app_size %>
CACHE: CACHE:
/ /

Loading…
Cancel
Save