tell-them 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57fcbb4894e21105e91f9d0a1b9bd03db6c72488
4
- data.tar.gz: ef79de9024e1c7123157b804b52d33269b1d1d59
3
+ metadata.gz: d432d6888bcade75af163344773ac696555f5e8a
4
+ data.tar.gz: 4f7f8fa63b1729a69120501b82c1f16ae9c72c4e
5
5
  SHA512:
6
- metadata.gz: 478ba1fd87a296f7a7aeea5850746568bec309767bace103aeb5b0383794fc520bf92f096d808e97ba75c57a22511cf2b38e61122d11bcf01a65d69ee0261e6a
7
- data.tar.gz: c995c555664c41604994589058be470c730bfdc5c31a2dc4d3767be25ca5ce7be6da02733ccea182a32225a33f8fe12b0eaf394d1e4322c9952d05bd2d8404b3
6
+ metadata.gz: c5099bbe8569dc8d24ef7d7a4dcb55e68d0710989a4d328128fdd3f8cc561adedf675513f92963e788b3b5094c105d0676d882dd8b09f9a3b352b4ee97eb2d3a
7
+ data.tar.gz: 6819f981782d8b6fedb86e006f95365d63a7de144a3a511d1db62e3d0f93e3d4093e1908a667349c4123d5f792eaea7fe1532bc6153960194e8d864ce03162ab
data/README.md CHANGED
@@ -25,25 +25,17 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
- You'll need to include the tell-them style file in app/assets/stylesheets/application.scss,
29
-
30
- ```
31
- //= require tell-them
32
- ```
33
-
34
- ...and add a line into your layout (say in apps/views/layouts/application.html.erb) that will insert the necessary HTML:
28
+ You'll need to add a line into your layout (say in apps/views/layouts/application.html.erb) that will insert the necessary HTML, along with JS and CSS links (I've assumed that because this is development only, JS and CSS pipeline optimisation is probably unnecessary):
35
29
 
36
30
  ```
37
31
  <%= TellThem.html %>
38
32
  ```
39
33
 
40
- [OPTIONAL] add the script files in app/assets/javascripts/application.js (TellThem doesn't need the javascript to work, but it enables a few nice features like saved prefs, choosing the position of the pop-up debugging box and allowing you to pin it open)
34
+ Once that's done, TellThem is ready to use!
41
35
 
42
- ```
43
- //= require tell-them
44
- ```
36
+ ### Data
45
37
 
46
- When all that's done, TellThem is ready to use! Whenever you want to expose internal data from the controller to the developer in the webpage, just add it as one or more key:value pairs using a map:
38
+ Whenever you want to expose internal data from the controller to the developer in the webpage, just add it as one or more key:value pairs using a map:
47
39
 
48
40
  ```
49
41
  TellThem.add(this: 'this is some data!', :'Become Admin' => '/become_admin?source=tell-them')
@@ -54,4 +46,30 @@ This data will now appear in a little pop-up box on the webpage. Note that the p
54
46
  * No data? No box
55
47
  * In production/staging/test? No box
56
48
 
57
- If the value of any item will parse as a URI, TellThem will wrap it in a link so that it's clickable.
49
+ If the value of any item will parse as a URI, TellThem will wrap it in a link so that it's clickable.
50
+
51
+ ### Media Indicators
52
+
53
+ If you would like TellThem to help you debug your breakpoints and responsive behaviour, it can do that too. Using an array of maps, you can enable a set of CSS-styled indicators to appear on the box. Supply a `min` and/or `max` selector to match your breakpoints, and a `name` item that will display in the box header when the specified breakpoint is active. If you also add an `initial` item the ? in the TellThem box will be replaced, so that you don't have to open or pin the box to see the current breakpoint.
54
+
55
+ ```
56
+ TellThem.enable_media_queries([
57
+ { initial: "M", name: 'mobile', max: '767px' },
58
+ { initial: "T", name: 'tablet', min: '768px', max: '889px' },
59
+ { initial: "S", name: 'screen', min: '890px', max: '1249px' },
60
+ { initial: "W", name: 'wide', min: '1250px' },
61
+ ])
62
+ ```
63
+
64
+ ### Grid overlays
65
+
66
+ If you would like TellThem to help you debug grid layout as well, you can add column count, width, and spacing to the media query block. It will add a "Grid" button to the controls to toggle grid visibility, or in non-js land the grid will always be visible.
67
+
68
+ ```
69
+ TellThem.enable_media_queries([
70
+ { initial: "M", name: 'mobile', max: '767px', columns: 1, margins: '20px' },
71
+ { initial: "T", name: 'tablet', min: '768px', max: '889px', columns: 18, column_width: '20px', column_space: '15px' },
72
+ { initial: "S", name: 'screen', min: '890px', max: '1249px', columns: 24, column_width: '20px', column_space: '15px' },
73
+ { initial: "W", name: 'wide', min: '1250px', columns: 36, column_width: '20px', column_space: '15px' },
74
+ ])
75
+ ```
@@ -5,6 +5,10 @@ load_prefs = ->
5
5
  if prefs.pinned == 1
6
6
  $('#tell-them-box').addClass('pinned')
7
7
  $('#tell-them-box .controls .pin').text('Unpin')
8
+ $('#tell-them-box').removeClass('grid-on')
9
+ if prefs.grid == 1
10
+ $('#tell-them-box').addClass('grid-on')
11
+ $('#tell-them-box .controls .pin').text('No Grid')
8
12
  $('#tell-them-box').addClass(prefs.corner)
9
13
  $('#tell-them-box .controls .corners button').removeClass('current')
10
14
  $('#tell-them-box .controls .corners button[data-target-corner=' + prefs.corner + ']').addClass('current')
@@ -13,10 +17,12 @@ save_prefs = ->
13
17
  pin_value = 0
14
18
  if $('#tell-them-box').hasClass('pinned')
15
19
  pin_value = 1
16
- prefs = {
20
+ grid_value = 0
21
+ if $('#tell-them-box').hasClass('grid-on')
22
+ grid_value = 1
23
+ prefs =
17
24
  corner: $('#tell-them-box .controls .corners button.current').data('target-corner'),
18
- pinned: pin_value
19
- }
25
+ pinned: pin_value,
20
26
  localStorage.setItem("tellThemPrefs", JSON.stringify(prefs))
21
27
 
22
28
  change_corners = (e) ->
@@ -34,8 +40,17 @@ toggle_pin = (e) ->
34
40
  $('#tell-them-box .controls .pin').text('Pin')
35
41
  save_prefs()
36
42
 
43
+ toggle_grid = (e) ->
44
+ $('#tell-them-box').toggleClass('grid-on')
45
+ if $('#tell-them-box').hasClass('grid-on')
46
+ $('#tell-them-box .controls .grid').text('No Grid')
47
+ else
48
+ $('#tell-them-box .controls .grid').text('Grid')
49
+ save_prefs()
50
+
37
51
  $ ->
38
52
  load_prefs()
39
53
  $('#tell-them-box .controls .corners button').on 'click', change_corners
40
- $('#tell-them-box .controls .pin').on 'click', toggle_pin
54
+ $('#tell-them-box .controls .grid').on 'click', toggle_grid
55
+ $('#tell-them-box .controls .pin').on 'click', toggle_pin
41
56
  $('#tell-them-box .controls').css('display', 'block')
@@ -0,0 +1,19 @@
1
+ #tell-them-box:hover+#grid-overlay, #tell-them-box.grid-on+#grid-overlay
2
+ position: fixed
3
+ top: 0px
4
+ bottom: 0px
5
+ left: 0px
6
+ right: 0px
7
+ z-index: 500
8
+ .grid-content
9
+ font-size: 0
10
+ height: 100%
11
+ margin: 0 auto
12
+ background-color: rgba(181,76,12,0.3)
13
+ .grid-column
14
+ height: 100%
15
+ background-color: rgba(0,0,0,0.2)
16
+ display: inline-block
17
+ .grid-space
18
+ height: 100%
19
+ display: inline-block
@@ -1,3 +1,5 @@
1
+ @import 'grid-overlay'
2
+
1
3
  =positionable-box($distance)
2
4
  position: fixed
3
5
  bottom: $distance
@@ -88,15 +90,18 @@ $pad: 2%
88
90
  position: absolute
89
91
  top: 40%
90
92
  right: 45%
91
- .pin
93
+ .grid, .pin
92
94
  position: absolute
93
95
  top: 40%
94
- right: $pad
95
96
  border-radius: $pad
96
97
  padding: 0.3em 0.3em
97
98
  background-color: white
98
99
  color: black
99
100
  cursor: pointer
101
+ .grid
102
+ right: $pad + 10%
103
+ .pin
104
+ right: $pad
100
105
  .list
101
106
  margin: $pad
102
107
  border-radius: 1em
@@ -121,3 +126,9 @@ $pad: 2%
121
126
  .pin
122
127
  background-color: black
123
128
  color: white
129
+ &.grid-on
130
+ .contents
131
+ .controls
132
+ .grid
133
+ background-color: black
134
+ color: white
@@ -27,10 +27,18 @@ module TellThem
27
27
  TellThemStore.instance.has_media_queries?
28
28
  end
29
29
 
30
+ def self.has_media_grid_info?
31
+ TellThemStore.instance.has_media_grid_info?
32
+ end
33
+
30
34
  def self.media_queries
31
35
  TellThemStore.instance.media_queries
32
36
  end
33
37
 
38
+ def self.media_grid_max_columns
39
+ TellThemStore.instance.media_grid_max_columns
40
+ end
41
+
34
42
  def self.html
35
43
  return '' unless (has_data? || has_media_queries?) && ::Rails.env.development?
36
44
  return ActionController::Base.helpers.stylesheet_link_tag('tell-them') +
@@ -53,6 +61,7 @@ module TellThem
53
61
  box += ' <button class="current" data-target-corner="bottom-right"></button>'
54
62
  box += ' </div>'
55
63
  box += media_queries_flag_html
64
+ box += ' <button class="grid">Grid</button>'
56
65
  box += ' <button class="pin">Pin</button>'
57
66
  box += ' </div>'
58
67
  box += ' <dl class="list">'
@@ -69,6 +78,7 @@ module TellThem
69
78
  box += ' </dl>'
70
79
  box += ' </div>'
71
80
  box += '</div>'
81
+ box += media_grid_html
72
82
  box
73
83
  end
74
84
 
@@ -90,6 +100,7 @@ module TellThem
90
100
  style_box += "{ \n"
91
101
  style_box += " \#tell-them-box:before { content: \"#{query_data[:initial]}\"; }\n" if query_data[:initial]
92
102
  style_box += " \#tell-them-box .#{query_data[:name]} { display: block; }\n"
103
+ style_box += media_grid_css(query_data)
93
104
  style_box += " } \n"
94
105
  end
95
106
  style_box += "</style>"
@@ -104,6 +115,52 @@ module TellThem
104
115
  flag_div += '</div>'
105
116
  end
106
117
 
118
+ def self.media_grid_html
119
+ return '' unless has_media_grid_info?
120
+ grid_box = ' <div id="grid-overlay">' + "\n"
121
+ grid_box += ' <div class="grid-content">' + "\n"
122
+ grid_box += " <div class=\"grid-column #{validity_string}\"></div>" + "\n"
123
+ (2..media_grid_max_columns).each do |c|
124
+ grid_box += " <div class=\"grid-space #{validity_string(c)}\"></div>" + "\n"
125
+ grid_box += " <div class=\"grid-column #{validity_string(c)}\"></div>" + "\n"
126
+ end
127
+ grid_box += ' </div>' + "\n"
128
+ grid_box += ' </div>' + "\n"
129
+ end
130
+
131
+ def self.validity_string(columns = nil)
132
+ validity_string = ""
133
+ column_array.each { |c| validity_string += "valid-for-#{c} " if columns.nil? || c >= columns }
134
+ validity_string
135
+ end
136
+
137
+ def self.column_array
138
+ array = []
139
+ media_queries.each { |mq| array << mq[:columns] }
140
+ array
141
+ end
142
+
143
+ def self.media_grid_css(query_data)
144
+ return '' unless has_media_grid_info?
145
+ grid_css = " \#grid-overlay .grid-content .grid-column { display: none !important; }\n"
146
+ grid_css += " \#grid-overlay .grid-content .grid-space { display: none !important; }\n"
147
+ grid_css += " \#grid-overlay .grid-content { margin-top: #{query_data[:margin_top]} !important; }\n" if query_data.has_key?(:margin_top)
148
+
149
+ if query_data[:columns] == 1
150
+ grid_css += " \#grid-overlay .grid-content { margin-left: #{query_data[:margins]} !important; margin-right: #{query_data[:margins]} !important }\n"
151
+ grid_css += " \#grid-overlay .grid-content .grid-column.valid-for-1 { display: inline-block; width: 100%; }\n"
152
+ else
153
+ units = query_data[:column_width].gsub(/[0-9]/,'')
154
+ total_c_width = query_data[:column_width].gsub(units,'').to_i * query_data[:columns]
155
+ total_s_width = query_data[:column_space].gsub(units,'').to_i * (query_data[:columns] - 1)
156
+ total_width = (total_c_width + total_s_width).to_s + units
157
+ grid_css += " \#grid-overlay .grid-content { width: #{total_width}; }\n"
158
+ grid_css += " \#grid-overlay .grid-content .grid-column.valid-for-#{query_data[:columns]} { display: inline-block !important; width: #{query_data[:column_width]} }\n"
159
+ grid_css += " \#grid-overlay .grid-content .grid-space.valid-for-#{query_data[:columns]} { display: inline-block !important; width: #{query_data[:column_space]} }\n"
160
+ end
161
+ end
162
+
163
+
107
164
  class TellThemStore
108
165
  include Singleton
109
166
 
@@ -136,8 +193,24 @@ module TellThem
136
193
  @media_queries.any?
137
194
  end
138
195
 
196
+ def has_media_grid_info?
197
+ return false unless has_media_queries?
198
+ @media_queries.each do |mq|
199
+ next unless mq.has_key?(:columns)
200
+ return true if mq[:columns] == 1 && mq.has_key?(:margins)
201
+ return true if mq[:columns] > 1 && mq.has_key?(:column_width) && mq.has_key?(:column_space)
202
+ end
203
+ false
204
+ end
205
+
139
206
  def media_queries
140
207
  @media_queries
141
208
  end
209
+
210
+ def media_grid_max_columns
211
+ columns = 0
212
+ media_queries.each { |mq| columns = [columns, mq[:columns]].max }
213
+ columns
214
+ end
142
215
  end
143
216
  end
@@ -1,5 +1,5 @@
1
1
  module TellThem
2
2
  module Rails
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tell-them
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - K M Lawrence
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-27 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -99,6 +99,7 @@ files:
99
99
  - README.md
100
100
  - Rakefile
101
101
  - app/assets/javascripts/tell-them.js.coffee
102
+ - app/assets/stylesheets/grid-overlay.sass
102
103
  - app/assets/stylesheets/tell-them.sass
103
104
  - bin/console
104
105
  - bin/setup