History

Refactor app size/theme methods

Thibaut committed 11 years ago

Commit b3c569b1 parent e2b86744 files · +22 −14Browse files

Unified · Split

4 files
  1. lib/app.rb +12 −4
  2. test/app_test.rb +4 −4
  3. views/app.erb +5 −5
  4. views/manifest.erb +1 −1
lib/app.rb+12−4
@@ -128,11 +128,11 @@ class App < Sinatra::Application · 127 unmodified lines
128128 end
129129
130130 def main_stylesheet_path
131− stylesheet_paths[cookies[:dark].nil? ? :default : :dark]
131+ stylesheet_paths[dark_theme? ? :dark : :default]
132132 end
133133
134134 def alternate_stylesheet_path
135− stylesheet_paths[cookies[:dark].nil? ? :dark : :default]
135+ stylesheet_paths[dark_theme? ? :default : :dark]
136136 end
137137
138138 def stylesheet_paths
@@ -142,8 +142,16 @@ class App < Sinatra::Application · 3 unmodified lines
142142 }
143143 end
144144
145− def size
146− @size ||= cookies[:size].nil? ? '18rem' : "#{cookies[:size]}px"
145+ def app_size
146+ @app_size ||= cookies[:size].nil? ? '18rem' : "#{cookies[:size]}px"
147+ end
148+
149+ def app_theme
150+ @app_theme ||= cookies[:dark].nil? ? 'default' : 'dark'
151+ end
152+
153+ def dark_theme?
154+ app_theme == 'dark'
147155 end
148156 end
149157
test/app_test.rb+4−4
@@ -69,17 +69,17 @@ class AppTest < MiniTest::Spec · 68 unmodified lines
6969 assert_includes last_response.body, '/html/index.json'
7070 end
7171
72− it "includes has the word 'light' by default" do
72+ it "has the word 'default' when no 'dark' cookie is set" do
7373 get '/manifest.appcache'
74− assert_includes last_response.body, '# light'
74+ assert_includes last_response.body, '# default'
7575 refute_includes last_response.body, '# dark'
7676 end
7777
78− it "includes has the word 'dark' when the cookie is set" do
78+ it "has the word 'dark' when the cookie is set" do
7979 set_cookie('dark=1')
8080 get '/manifest.appcache'
8181 assert_includes last_response.body, '# dark'
82− refute_includes last_response.body, '# light'
82+ refute_includes last_response.body, '# default'
8383 end
8484
8585 it "sets default size" do
views/app.erb+5−5
@@ -44,9 +44,9 @@ · 43 unmodified lines
4444 a.src="//secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0];
4545 b.parentNode.insertBefore(a,b)}();
4646 </script><% end %>
47−<style data-size="<%= size %>" data-resizer>
48− ._container { margin-left: <%= size %>; }
49− ._search, ._list, ._sidebar-footer { width: <%= size %>; }
50− ._list-hover.clone { min-width: <%= size %>; }
51− ._notice, ._path, ._resizer { left: <%= size %>; }
47+<style data-size="<%= app_size %>" data-resizer>
48+ ._container { margin-left: <%= app_size %>; }
49+ ._search, ._list, ._sidebar-footer { width: <%= app_size %>; }
50+ ._list-hover.clone { min-width: <%= app_size %>; }
51+ ._notice, ._path, ._resizer { left: <%= app_size %>; }
5252 </style>
views/manifest.erb+1−1
@@ -1,5 +1,5 @@
11 CACHE MANIFEST
2−# <%= cookies[:dark].nil? ? 'light' : 'dark' %> <%= size %>
2+# <%= app_theme %> <%= app_size %>
33
44 CACHE:
55 /