Просмотр исходного кода

Refactor app size/theme methods

Thibaut 10 лет назад
Родитель
Сommit
b3c569bf6e
4 измененных файлов с 22 добавлено и 14 удалено
  1. 12 4
      lib/app.rb
  2. 4 4
      test/app_test.rb
  3. 5 5
      views/app.erb
  4. 1 1
      views/manifest.erb

+ 12 - 4
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
 

+ 4 - 4
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

+ 5 - 5
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)}();
 </script><% end %>
-<style data-size="<%= size %>" data-resizer>
-  ._container { margin-left: <%= size %>; }
-  ._search, ._list, ._sidebar-footer { width: <%= size %>; }
-  ._list-hover.clone { min-width: <%= size %>; }
-  ._notice, ._path, ._resizer { left: <%= size %>; }
+<style data-size="<%= app_size %>" data-resizer>
+  ._container { margin-left: <%= app_size %>; }
+  ._search, ._list, ._sidebar-footer { width: <%= app_size %>; }
+  ._list-hover.clone { min-width: <%= app_size %>; }
+  ._notice, ._path, ._resizer { left: <%= app_size %>; }
 </style>

+ 1 - 1
views/manifest.erb

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