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
128 end128 end
129 129
130 def main_stylesheet_path130 def main_stylesheet_path
131 stylesheet_paths[cookies[:dark].nil? ? :default : :dark]131 stylesheet_paths[dark_theme? ? :dark : :default]
132 end132 end
133 133
134 def alternate_stylesheet_path134 def alternate_stylesheet_path
135 stylesheet_paths[cookies[:dark].nil? ? :dark : :default]135 stylesheet_paths[dark_theme? ? :default : :dark]
136 end136 end
137 137
138 def stylesheet_paths138 def stylesheet_paths
@@ -142,8 +142,16 @@ class App < Sinatra::Application · 3 unmodified lines
142 }142 }
143 end143 end
144 144
145 def size145 def app_size
146 @size ||= cookies[:size].nil? ? '18rem' : "#{cookies[:size]}px"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'
147 end155 end
148 end156 end
149 157
test/app_test.rb+4−4
@@ -69,17 +69,17 @@ class AppTest < MiniTest::Spec · 68 unmodified lines
69 assert_includes last_response.body, '/html/index.json'69 assert_includes last_response.body, '/html/index.json'
70 end70 end
71 71
72 it "includes has the word 'light' by default" do72 it "has the word 'default' when no 'dark' cookie is set" do
73 get '/manifest.appcache'73 get '/manifest.appcache'
74 assert_includes last_response.body, '# light'74 assert_includes last_response.body, '# default'
75 refute_includes last_response.body, '# dark'75 refute_includes last_response.body, '# dark'
76 end76 end
77 77
78 it "includes has the word 'dark' when the cookie is set" do78 it "has the word 'dark' when the cookie is set" do
79 set_cookie('dark=1')79 set_cookie('dark=1')
80 get '/manifest.appcache'80 get '/manifest.appcache'
81 assert_includes last_response.body, '# dark'81 assert_includes last_response.body, '# dark'
82 refute_includes last_response.body, '# light'82 refute_includes last_response.body, '# default'
83 end83 end
84 84
85 it "sets default size" do85 it "sets default size" do
views/app.erb+5−5
@@ -44,9 +44,9 @@ · 43 unmodified lines
44 a.src="//secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0];44 a.src="//secure.gaug.es/track.js";var b=document.getElementsByTagName("script")[0];
45 b.parentNode.insertBefore(a,b)}();45 b.parentNode.insertBefore(a,b)}();
46</script><% end %>46</script><% end %>
47<style data-size="<%= size %>" data-resizer>47<style data-size="<%= app_size %>" data-resizer>
48 ._container { margin-left: <%= size %>; }48 ._container { margin-left: <%= app_size %>; }
49 ._search, ._list, ._sidebar-footer { width: <%= size %>; }49 ._search, ._list, ._sidebar-footer { width: <%= app_size %>; }
50 ._list-hover.clone { min-width: <%= size %>; }50 ._list-hover.clone { min-width: <%= app_size %>; }
51 ._notice, ._path, ._resizer { left: <%= size %>; }51 ._notice, ._path, ._resizer { left: <%= app_size %>; }
52</style>52</style>
views/manifest.erb+1−1
@@ -1,5 +1,5 @@
1CACHE MANIFEST1CACHE MANIFEST
2# <%= cookies[:dark].nil? ? 'light' : 'dark' %> <%= size %>2# <%= app_theme %> <%= app_size %>
3 3
4CACHE:4CACHE:
5/5/