diff --git a/lib/app.rb b/lib/app.rb index bdb101fc..c4c69e90 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -128,11 +128,11 @@ class App < Sinatra::Application end def main_stylesheet_path - stylesheet_paths[cookies[:dark].nil? ? :default : :dark] + stylesheet_paths[dark_theme? ? :dark : :default] end def alternate_stylesheet_path - stylesheet_paths[cookies[:dark].nil? ? :dark : :default] + stylesheet_paths[dark_theme? ? :default : :dark] end def stylesheet_paths @@ -142,8 +142,16 @@ class App < Sinatra::Application } end - def size - @size ||= cookies[:size].nil? ? '18rem' : "#{cookies[:size]}px" + def app_size + @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 diff --git a/test/app_test.rb b/test/app_test.rb index f0f2cb5d..83d9b06c 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -69,17 +69,17 @@ class AppTest < MiniTest::Spec assert_includes last_response.body, '/html/index.json' 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' - assert_includes last_response.body, '# light' + assert_includes last_response.body, '# default' refute_includes last_response.body, '# dark' 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') get '/manifest.appcache' assert_includes last_response.body, '# dark' - refute_includes last_response.body, '# light' + refute_includes last_response.body, '# default' end it "sets default size" do diff --git a/views/app.erb b/views/app.erb index ca968c06..c6b66fad 100644 --- a/views/app.erb +++ b/views/app.erb @@ -44,9 +44,9 @@ a.src="//secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0]; b.parentNode.insertBefore(a,b)}(); <% end %> - diff --git a/views/manifest.erb b/views/manifest.erb index 9f613cd1..ca3a02f4 100644 --- a/views/manifest.erb +++ b/views/manifest.erb @@ -1,5 +1,5 @@ CACHE MANIFEST -# <%= cookies[:dark].nil? ? 'light' : 'dark' %> <%= size %> +# <%= app_theme %> <%= app_size %> CACHE: /