mxit-rails 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/app/assets/images/mxit_rails/home.png +0 -0
  2. data/app/assets/javascripts/mxit_rails/emulator.js +33 -6
  3. data/app/assets/stylesheets/mxit_rails/emulator.css.scss +16 -21
  4. data/app/helpers/mxit_rails_helper.rb +22 -0
  5. data/app/views/emulator/index.html.erb +7 -5
  6. data/app/views/layouts/mxit.html.erb +5 -16
  7. data/config/routes.rb +3 -1
  8. data/lib/mxit_rails/descriptor.rb +2 -0
  9. data/lib/mxit_rails/engine.rb +0 -3
  10. data/lib/mxit_rails/page.rb +6 -1
  11. data/lib/mxit_rails/version.rb +1 -1
  12. data/test/dummy/app/controllers/form_controller.rb +3 -1
  13. data/test/dummy/app/controllers/welcome_controller.rb +2 -2
  14. data/test/dummy/app/views/form/index/age.html.erb +9 -2
  15. data/test/dummy/app/views/form/index/done.html.erb +6 -3
  16. data/test/dummy/app/views/form/index/name.html.erb +10 -2
  17. data/test/dummy/app/views/form/index/start.html.erb +10 -3
  18. data/test/dummy/app/views/form/index/surname.html.erb +9 -2
  19. data/test/dummy/app/views/index/index.html.erb +6 -4
  20. data/test/dummy/app/views/index/success.html.erb +5 -2
  21. data/test/dummy/app/views/welcome/easter_egg.html.erb +5 -2
  22. data/test/dummy/app/views/welcome/index.html.erb +11 -4
  23. data/test/dummy/config/application.rb +0 -3
  24. data/test/dummy/config/routes.rb +4 -2
  25. data/test/dummy/log/development.log +4629 -0
  26. data/test/dummy/log/production.log +30 -0
  27. data/test/dummy/tmp/cache/assets/D2C/AA0/sprockets%2F7bdf74c64e17769ae77b616e6dc39287 +0 -0
  28. data/test/dummy/tmp/cache/assets/D54/750/sprockets%2Fc16371b1a234c7c56cb01cb28a8bc5c3 +0 -0
  29. data/test/dummy/tmp/cache/assets/D9F/2D0/sprockets%2Fbd11d44fd5d620d8e6fb3953bd831dc8 +0 -0
  30. data/test/dummy/tmp/cache/assets/DAA/B80/sprockets%2Ff8082150f8c8beafcd445cc79a9a6a85 +0 -0
  31. data/test/dummy/tmp/cache/assets/DFB/940/sprockets%2F2faff4be90929be6a1b1de49ea25e33b +0 -0
  32. data/test/dummy/tmp/cache/assets/E15/260/sprockets%2Fea9c788716af4ccb19ff8e1d7ea47b8e +0 -0
  33. data/test/dummy/tmp/cache/assets/E26/4F0/sprockets%2F1cd8dafcb93f36aea8c2cf9d04c322d3 +0 -0
  34. data/test/dummy/tmp/cache/assets/E4F/E70/sprockets%2Fd9fffd76ac7c8ee08bedf3e257c81f99 +0 -0
  35. metadata +7 -4
  36. data/test/dummy/public/index.html +0 -26
@@ -42,7 +42,7 @@ Emulator = (function() {
42
42
  if (MXIT_PATH && (MXIT_PATH != ''))
43
43
  Emulator.setUrl(MXIT_PATH);
44
44
  else
45
- Emulator.setUrl(MXIT_ROOT);
45
+ Emulator.home();
46
46
  },
47
47
 
48
48
  clearCookie: function() {
@@ -54,7 +54,11 @@ Emulator = (function() {
54
54
  if (MXIT_PATH && (MXIT_PATH != ''))
55
55
  Emulator.setUrl(MXIT_PATH);
56
56
  else
57
- Emulator.setUrl(MXIT_ROOT);
57
+ Emulator.home();
58
+ },
59
+
60
+ home: function() {
61
+ Emulator.setUrl(MXIT_ROOT);
58
62
  },
59
63
 
60
64
  getUrl: function() {
@@ -119,13 +123,27 @@ Emulator = (function() {
119
123
  },
120
124
 
121
125
  collapse: function() {
122
- $('#phone').removeClass('collapse');
123
- $('#fadeout').show();
126
+ $('body').removeClass('collapse');
124
127
  },
125
128
 
126
129
  expand: function() {
127
- $('#phone').addClass('collapse');
128
- $('#fadeout').hide();
130
+ $('body').addClass('collapse');
131
+ },
132
+
133
+ expandCollapse: function(val) {
134
+ if (val) {
135
+ if (val == 'expand')
136
+ localStorage.setItem('expanded', true);
137
+ else
138
+ localStorage.removeItem('expanded');
139
+ }
140
+
141
+ var expanded = localStorage.getItem('expanded');
142
+ if (expanded) {
143
+ Emulator.expand();
144
+ } else {
145
+ Emulator.collapse();
146
+ }
129
147
  },
130
148
 
131
149
  refresh: function() {
@@ -149,6 +167,13 @@ Emulator = (function() {
149
167
  this.activeLink = 0;
150
168
  }
151
169
  this.focusLink();
170
+
171
+ // Look for Rails default stacktrace and expand if it's there. Otherwise use the localstorage expanded setting
172
+ if ((Emulator.iframeElement('#env_dump').length > 0) && (Emulator.iframeElement('#session_dump').length > 0)) {
173
+ Emulator.expand();
174
+ } else {
175
+ Emulator.expandCollapse();
176
+ }
152
177
  },
153
178
 
154
179
  key: function(e) {
@@ -220,6 +245,8 @@ $(function() {
220
245
  Emulator.clearCredentials();
221
246
  }
222
247
 
248
+ Emulator.expandCollapse();
249
+
223
250
  $('body').on('keydown', $.proxy(Emulator, 'key'));
224
251
  $('#phone-input').on('keypress', $.proxy(Emulator, 'submit'))
225
252
 
@@ -13,7 +13,7 @@ html, body {
13
13
  margin: 35px auto 0 auto;
14
14
  position: relative;
15
15
  }
16
- #phone.collapse {
16
+ .collapse #phone {
17
17
  background: none;
18
18
  position: absolute;
19
19
  top: 37px;
@@ -31,7 +31,7 @@ html, body {
31
31
  position: relative;
32
32
  overflow: hidden;
33
33
  }
34
- #phone.collapse #screen {
34
+ .collapse #screen {
35
35
  position: static;
36
36
  width: 100%;
37
37
  height: 100%;
@@ -49,7 +49,7 @@ iframe {
49
49
  position: absolute;
50
50
  z-index: 1;
51
51
  }
52
- #phone.collapse .content {
52
+ .collapse .content {
53
53
  width: 100%;
54
54
  height: 100%;
55
55
  }
@@ -145,28 +145,20 @@ a.link {
145
145
  left: -1px;
146
146
  position: relative;
147
147
  }
148
-
149
- #phone-links {
150
- position: absolute;
151
- display: block;
152
- right: 19px;
153
- top: 27px;
154
- z-index: 10;
155
- width: 90px;
156
- height: 40px;
157
- text-align: right;
158
- }
159
- #phone.collapse #phone-links {
160
- right: 1px;
161
- top: 5px;
148
+ .home .icon .image {
149
+ background-size: 21px;
150
+ top: -2px;
151
+ left: -1px;
152
+ position: relative;
162
153
  }
154
+
163
155
  #collapse {
164
156
  display: none;
165
157
  }
166
- #phone.collapse #expand {
158
+ .collapse #expand {
167
159
  display: none;
168
160
  }
169
- #phone.collapse #collapse {
161
+ .collapse #collapse {
170
162
  display: inline;
171
163
  }
172
164
 
@@ -180,7 +172,7 @@ a.link {
180
172
  line-height: 30px;
181
173
  margin-top: 10px;
182
174
  }
183
- #phone.collapse #phone-input {
175
+ .collapse #phone-input {
184
176
  position: fixed;
185
177
  bottom: 5px;
186
178
  left: 5px;
@@ -200,4 +192,7 @@ a.link {
200
192
  right: 0;
201
193
  background: -webkit-linear-gradient(90deg, #fff 0%, #fff 5%, rgba(255,255,255,0.95) 15%, rgba(255,255,255,0) 100%);;
202
194
  z-index: 10;
203
- }
195
+ }
196
+ .collapse #fadeout {
197
+ display: none;
198
+ }
@@ -1,5 +1,27 @@
1
1
  module MxitRailsHelper
2
2
 
3
+ def mxit_validation_message
4
+ @_mxit_validation_messages.first
5
+ end
6
+
7
+ def mxit_table_row *styles
8
+ str = ''
9
+ if @_mxit.has_table
10
+ # Close the previous row if there is one
11
+ str += "</td></tr>"
12
+ else
13
+ # Start a new table
14
+ str += '<table title="mxit:table:full" style="width:100%" name="main_table" cellspacing="0" cellpadding="0">'
15
+ str += '<colgroup span="1" width="100%"></colgroup>'
16
+ end
17
+ @_mxit.has_table = true
18
+
19
+ # Start the new row
20
+ style = mxit_style *styles
21
+ str += "<tr><td style=\"#{ style }\">"
22
+ str.html_safe
23
+ end
24
+
3
25
  def mxit_link route, label, variables=nil
4
26
  unless variables.nil?
5
27
  var_strings = []
@@ -21,6 +21,7 @@
21
21
  .in > .icon .image { background-image: url(<%= image_path("mxit_rails/in.png"); %>) }
22
22
  .out > .icon .image { background-image: url(<%= image_path("mxit_rails/out.png"); %>) }
23
23
  .refresh > .icon .image { background-image: url(<%= image_path("mxit_rails/refresh.png"); %>) }
24
+ .home > .icon .image { background-image: url(<%= image_path("mxit_rails/home.png"); %>) }
24
25
  </style>
25
26
  </head>
26
27
  <body>
@@ -34,6 +35,12 @@
34
35
  <a id="link" class="go link" onclick="Emulator.enterCredentials()">Set Credentials <span class="icon"><span class="image"></span></span></a>
35
36
  </div>
36
37
 
38
+ <div id="phone-links">
39
+ <a id="home" class="home link" onclick="Emulator.home()"><span class="icon"><span class="image"></span></span></a>
40
+ <a id="refresh" class="refresh link" onclick="Emulator.refresh()"><span class="icon"><span class="image"></span></span></a>
41
+ <a id="expand" class="out link" onclick="Emulator.expandCollapse('expand')"><span class="icon"><span class="image"></span></span></a>
42
+ <a id="collapse" class="in link" onclick="Emulator.expandCollapse('collapse')"><span class="icon"><span class="image"></span></span></a>
43
+ </div>
37
44
  <div id="inputs">
38
45
  <input type="text" placeholder="Mxit ID" id="mxit-id-input" />
39
46
  <input type="text" placeholder="MSISDN" id="msisdn-input" />
@@ -43,11 +50,6 @@
43
50
  </div>
44
51
 
45
52
  <div id="phone">
46
- <div id="phone-links">
47
- <a id="refresh" class="refresh link" onclick="Emulator.refresh()"><span class="icon"><span class="image"></span></span></a>
48
- <a id="expand" class="out link" onclick="Emulator.expand()"><span class="icon"><span class="image"></span></span></a>
49
- <a id="collapse" class="in link" onclick="Emulator.collapse()"><span class="icon"><span class="image"></span></span></a>
50
- </div>
51
53
  <div id="screen">
52
54
  <iframe id="center" class="content" onLoad="Emulator.updateIframe()"></iframe>
53
55
  </div>
@@ -23,22 +23,11 @@
23
23
 
24
24
  <body style="<%= mxit_style :body %>">
25
25
 
26
- <table title="mxit:table:full" style="width:100%" name="title_table" cellspacing="0" cellpadding="0">
27
- <colgroup span="1" width="100%"></colgroup>
28
- <tr>
29
- <td style="<%= mxit_style :title %>">
30
- <b><%= yield :title %></b>
31
- </td>
32
- </tr>
33
- </table>
34
-
35
- <%= yield :navigation %>
36
-
37
- <% if !@_mxit_validated %>
38
- <%= @_mxit_validation_messages.first %>
39
-
40
- <% else %>
41
- <%= yield %>
26
+ <%= yield %>
27
+
28
+ <% if @_mxit.has_table %>
29
+ <!-- Close the table if there is one -->
30
+ </table>
42
31
  <% end %>
43
32
 
44
33
  <% if @_mxit.input %>
data/config/routes.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- match '/emulator(/*path)', :controller => 'emulator', :action => 'index'
3
+ if Rails.env.development?
4
+ match '/emulator(/*path)', :controller => 'emulator', :action => 'index'
5
+ end
4
6
 
5
7
  end
@@ -23,6 +23,8 @@ module MxitRails
23
23
  attr_accessor :input
24
24
  attr_accessor :input_label
25
25
 
26
+ attr_accessor :has_table
27
+
26
28
  def initialize name, action, parent=nil
27
29
  @parent_descriptor = parent
28
30
  @name = name.to_sym
@@ -1,7 +1,4 @@
1
1
  module MxitRails
2
2
  class Engine < ::Rails::Engine
3
- initializer "precompile", :group => :all do |app|
4
- app.config.assets.precompile += %w( mxit_rails/emulator.js mxit_rails/emulator.css mxit_rails/included.css )
5
- end
6
3
  end
7
4
  end
@@ -30,7 +30,12 @@ module MxitRails
30
30
  end
31
31
 
32
32
  def get_mxit_header_field key
33
- request.headers[key] || cookies[key.downcase]
33
+ output = request.headers[key]
34
+ # Only allow cookie-based headers in development
35
+ if Rails.env.development?
36
+ output ||= cookies[key.downcase]
37
+ end
38
+ output
34
39
  end
35
40
 
36
41
  def get_mxit_info
@@ -1,3 +1,3 @@
1
1
  module MxitRails
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -18,6 +18,8 @@ class FormController < ApplicationController
18
18
 
19
19
  step :surname do
20
20
  input :surname, 'What is your surname?'
21
+
22
+ @name = params[:name]
21
23
  end
22
24
 
23
25
  step :age do
@@ -37,7 +39,7 @@ class FormController < ApplicationController
37
39
 
38
40
  submit do
39
41
  logger.info "Form Completed!\nname: #{params[:name]}; surname: #{params[:surname]}; age: #{params[:age]}\n******\n\n"
40
- redirect! '/mxit/index/success'
42
+ redirect_to '/index/success' and return
41
43
  end
42
44
  end
43
45
  end
@@ -18,10 +18,10 @@ class WelcomeController < ApplicationController
18
18
 
19
19
  submit do
20
20
  if params[:phone_number] == '1234567890'
21
- redirect! :easter_egg
21
+ redirect_to '/welcome/easter_egg' and return
22
22
  end
23
23
  logger.info "This won't execute if an error occurred or if error! or redirect! was called"
24
- redirect! '/mxit/index/success'
24
+ redirect_to '/index/success' and return
25
25
  end
26
26
  end
27
27
 
@@ -1,4 +1,11 @@
1
- <%= content_for :title do %>Step 3 of 3<% end %>
2
- <%= content_for :navigation do %><%= mxit_nav_link '/mxit/index', 'Back' %><% end %>
1
+ <%= mxit_table_row :title %>
2
+ <b>Step 3 of 3</b>
3
+
4
+ <%= mxit_table_row %>
5
+ <%= mxit_nav_link '/', 'Back' %>
3
6
 
4
7
  <p>Great! The last thing we'll need before we can finish the process is your age.</p>
8
+
9
+ <% if mxit_validation_message %>
10
+ <p><%= mxit_validation_message %></p>
11
+ <% end %>
@@ -1,7 +1,10 @@
1
- <%= content_for :title do %>Confirm<% end %>
2
- <%= content_for :navigation do %><%= mxit_nav_link '/mxit/index', 'Back' %><% end %>
1
+ <%= mxit_table_row :title %>
2
+ <b>Confirm</b>
3
+
4
+ <%= mxit_table_row %>
5
+ <%= mxit_nav_link '/', 'Back' %>
3
6
 
4
7
  <p>That's it. Please just confirm your information below:</p>
5
8
  <p>First name: <b><%= @name %></b></p>
6
9
  <p>Surname: <b><%= @surname %></b></p>
7
- <p>Age: <b><%= @age %></b></p>
10
+ <p>Age: <b><%= @age %></b></p>
@@ -1,4 +1,12 @@
1
- <%= content_for :title do %>Step 1 of 3<% end %>
2
- <%= content_for :navigation do %><%= mxit_nav_link '/mxit/index', 'Back' %><% end %>
1
+ <%= mxit_table_row :title %>
2
+ <b>Step 1 of 3</b>
3
+
4
+ <%= mxit_table_row %>
5
+ <%= mxit_nav_link '/', 'Back' %>
3
6
 
4
7
  <p>Hi there! To get started, we'll need your first name.</p>
8
+
9
+ <% if mxit_validation_message %>
10
+ <p><%= mxit_validation_message %></p>
11
+ <% end %>
12
+
@@ -1,4 +1,11 @@
1
- <%= content_for :title do %>The Form<% end %>
2
- <%= content_for :navigation do %><%= mxit_nav_link '/mxit/index', 'Back' %><% end %>
1
+ <%= mxit_table_row :title %>
2
+ <b>The Form</b>
3
3
 
4
- <p>Please take a minute to complete this fast, simple form.</p>
4
+ <%= mxit_table_row %>
5
+ <%= mxit_nav_link '/', 'Back' %>
6
+
7
+ <p>Please take a minute to complete this fast, simple form.</p>
8
+
9
+ <% if mxit_validation_message %>
10
+ <p><%= mxit_validation_message %></p>
11
+ <% end %>
@@ -1,4 +1,11 @@
1
- <%= content_for :title do %>Step 2 of 3<% end %>
2
- <%= content_for :navigation do %><%= mxit_nav_link '/mxit/index', 'Back' %><% end %>
1
+ <%= mxit_table_row :title %>
2
+ <b>Step 2 of 3</b>
3
+
4
+ <%= mxit_table_row %>
5
+ <%= mxit_nav_link '/', 'Back' %>
3
6
 
4
7
  <p>Thanks <%= @name %>. Next we'll need your surname.</p>
8
+
9
+ <% if mxit_validation_message %>
10
+ <p><%= mxit_validation_message %></p>
11
+ <% end %>
@@ -1,7 +1,9 @@
1
- <%= content_for :title do %>Templater<% end %>
1
+ <%= mxit_table_row :title %>
2
+ <b>Templater</b>
2
3
 
4
+ <%= mxit_table_row %>
3
5
  <p>This is the root of the dummy app...</p>
4
6
 
5
- <p><%= mxit_link '/mxit/welcome', 'Single-page form' %><p>
6
- <p><%= mxit_link '/mxit/form', 'Multi-step form' %><p>
7
- <p><%= mxit_link '/mxit/index', 'An extra link' %><p>
7
+ <p><%= mxit_link '/welcome', 'Single-page form' %><p>
8
+ <p><%= mxit_link '/form', 'Multi-step form' %><p>
9
+ <p><%= mxit_link '/index', 'An extra link' %><p>
@@ -1,4 +1,7 @@
1
- <%= content_for :title do %>Success!<% end %>
2
- <%= content_for :navigation do %><%= mxit_nav_link '/mxit', 'Done' %><% end %>
1
+ <%= mxit_table_row :title %>
2
+ <b>Success!</b>
3
+
4
+ <%= mxit_table_row %>
5
+ <%= mxit_nav_link '/', 'Done' %>
3
6
 
4
7
  <p>Your information was successfully received.</p>
@@ -1,4 +1,7 @@
1
- <%= content_for :title do %>Easter Egg<% end %>
2
- <%= content_for :navigation do %><%= mxit_nav_link '/mxit/welcome/index', 'Back' %><% end %>
1
+ <%= mxit_table_row :title %>
2
+ <b>Easter Egg</b>
3
+
4
+ <%= mxit_table_row %>
5
+ <%= mxit_nav_link '/welcome', 'Back' %>
3
6
 
4
7
  <p>This is the awesome easter egg :-)</p>