megatron 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d49ef672f2a5da108bc4176b923c941859e1a84e
4
- data.tar.gz: 89439c3591c4386a03a4e2bda43bd49b3c7d8365
3
+ metadata.gz: 2cd450213b9cd53cbdffd9b8b7c0b153f4fecab3
4
+ data.tar.gz: 5d9d2df16b081a5305690561d8094d8961f78a5f
5
5
  SHA512:
6
- metadata.gz: 7f3917fe2d5fc87d653d3f8a87370568dfee854c2dca5cf77607b29092b93a97ff12e782139513922a0a5c895d9ec694d9196ed8aae7ff1ec41acd4582a7ff3f
7
- data.tar.gz: a0d16880727aac310b0d5ab14e37b934efc05300aa6000816be412788d93b769949aea7fb1fc089f9a0b3a7343fe7457ca5c5b72243c98ea38b1cd7732c34c07
6
+ metadata.gz: 86485b8fbcdbd10e16025c3c39621971a0d8ac2b42a6b43c36aaf120a68ed7a9e4d53748e6065e50a976ac599dc0bd5635580bc447156bff8def0cdcdc666f78
7
+ data.tar.gz: a1da662b73b82b8daf49c80b0e84501f27d2d49b9321cf4ac1364137d8f0eaf807a309127c2e8d54e11fdfd16dc757e0cff7777e35fc598680a8fcccc56c89b5
data/Rakefile CHANGED
@@ -14,58 +14,11 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- load 'rails/tasks/statistics.rake'
18
-
19
17
  Bundler::GemHelper.install_tasks
20
18
 
21
- desc "Pick a random user as the winner"
22
- task :sass_watch do
23
- require 'listen'
24
- listen
25
- end
26
-
27
- def listen
28
- listener = Listen.to('app/assets/stylesheets/megatron/', only: /\.scss$/) do |modified, added, removed|
29
- output_paths("Changes detected to", modified)
30
- output_paths("Added", added)
31
- output_paths("Removed", removed)
32
-
33
- build
34
- end
35
-
36
- build
37
-
38
- listener.start # not blocking
39
- sleep
40
- end
41
-
42
- def output_paths(prefix, paths)
43
- unless paths.empty?
44
- paths.map! { |p| localize_path(p) }
45
- puts "#{prefix}: #{paths.join("\n")}"
46
- end
47
- end
48
-
49
- def localize_path(path)
50
- path.sub(/#{Dir.pwd}\//, '')
51
- end
52
-
53
- def destination
54
- "public/assets/megatron/megatron-#{version}.css"
55
- end
56
-
57
- def build
58
- system "sass app/assets/stylesheets/megatron/megatron.scss:#{destination}"
59
- system "./node_modules/postcss-cli/bin/postcss --use autoprefixer #{destination} -o #{destination}"
60
- puts "Built: #{destination}"
61
- end
62
-
63
- def version
64
- Gem.loaded_specs["megatron"].version
65
- end
66
-
67
19
  namespace :megatron do
68
20
 
21
+ require 'megatron'
69
22
  require 's3'
70
23
 
71
24
  task :upload do
@@ -104,4 +57,58 @@ namespace :megatron do
104
57
 
105
58
  end
106
59
 
60
+ namespace :css do
61
+
62
+ task :watch do
63
+
64
+ require 'listen'
65
+
66
+ listener = Listen.to('app/assets/stylesheets/megatron/', only: /\.scss$/) do |modified, added, removed|
67
+ build_css
68
+ end
69
+
70
+ build_css
71
+
72
+ puts "Initial CSS build, done. Listening for changes..."
73
+
74
+ listener.start # not blocking
75
+ sleep
76
+
77
+ end
78
+
79
+ end
80
+
81
+ namespace :svg do
82
+
83
+ task :watch do
84
+ require 'listen'
85
+ require 'esvg'
86
+
87
+ listener = Listen.to('app/assets/esvg/megatron/', only: /\.svg$/) do |modified, added, removed|
88
+ build_svg
89
+ end
90
+
91
+ build_svg
92
+
93
+ puts "Initial SVG build, done. Listening for changes..."
94
+
95
+ listener.start # not blocking
96
+ sleep
97
+
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+
104
+ def build_css
105
+ destination = "public/assets/megatron/megatron-#{Megatron::VERSION}.css"
106
+ system "sass app/assets/stylesheets/megatron/megatron.scss:#{destination}"
107
+ system "./node_modules/postcss-cli/bin/postcss --use autoprefixer #{destination} -o #{destination}"
108
+ puts "Built: #{destination}"
109
+ end
110
+
111
+ def build_svg
112
+ puts "building svg..."
113
+ Esvg::SVG.new(path: 'app/assets/esvg/megatron', output_path: 'app/assets/javascripts/megatron').write
107
114
  end
@@ -10,7 +10,7 @@ var MegatronForm = module.exports = RemoteForm.extend({
10
10
  error: 'Something went wrong.'
11
11
  },
12
12
 
13
- messageFor: function(type){
13
+ messageFor: function formMessageFor(type){
14
14
  if (this.el.dataset[type])
15
15
  return this.el.dataset[type]
16
16
  else {
@@ -22,15 +22,15 @@ var MegatronForm = module.exports = RemoteForm.extend({
22
22
  }
23
23
  },
24
24
 
25
- beforeSend: function(req){
25
+ beforeSend: function formBeforeSend(req){
26
26
  notify.progress(this.messageFor('beforeSend'))
27
27
  },
28
28
 
29
- success: function(body, status, xhr){
29
+ success: function formSuccessHandler(body, status, xhr){
30
30
  notify.success(this.messageFor('success'))
31
31
  },
32
32
 
33
- error: function(xhr, error){
33
+ error: function formErrorHandler(xhr, error){
34
34
  notify.error(this.messageFor('error'))
35
35
  }
36
36
  })
@@ -9,7 +9,7 @@ var DEFAULT_CONTINUE_BUTTON = 'Yes'
9
9
 
10
10
  function Link(){}
11
11
 
12
- Link.click = function(event){
12
+ Link.click = function linkClick(event){
13
13
  event.preventDefault()
14
14
  var el = event.currentTarget
15
15
  var form = null
@@ -42,7 +42,7 @@ Link.click = function(event){
42
42
  }
43
43
  }
44
44
 
45
- Link.buildForm = function(el){
45
+ Link.buildForm = function buildForm(el){
46
46
  var method = el.dataset.method || 'post'
47
47
  var csrfToken = document.querySelector('meta[name=csrf-token]')
48
48
  var csrfParam = document.querySelector('meta[name=csrf-param]')
@@ -4,11 +4,11 @@ var classie = require('classie')
4
4
  require('compose-tap-event')
5
5
 
6
6
  var AutoNavigate = {
7
- listen: function(){
7
+ listen: function autoNavigateListen(){
8
8
  bean.on(document, "click", ".auto-navigate", AutoNavigate.trigger)
9
9
  },
10
10
 
11
- trigger: function(event) {
11
+ trigger: function autoNavigateTrigger(event) {
12
12
  var target = event.target
13
13
  if (target.tagName.toLowerCase() != 'a') {
14
14
  var link = event.currentTarget.querySelector('a.navigate')
@@ -2,7 +2,7 @@ var bean = require('bean')
2
2
  var notify = require('notify')
3
3
 
4
4
  module.exports = {
5
- notify: function(el, type){
5
+ notify: function formNotify(el, type){
6
6
  if(type == 'success')
7
7
  notify.success(this.getMessage(el, 'success'))
8
8
  else if(type == 'error')
@@ -11,7 +11,7 @@ module.exports = {
11
11
  notify.progress(this.getMessage(el, 'beforeSend'))
12
12
  },
13
13
 
14
- getMessage: function(el, type){
14
+ getMessage: function formGetMessage(el, type){
15
15
  if (el.dataset[type])
16
16
  return el.dataset[type]
17
17
  else {
@@ -27,7 +27,7 @@ module.exports = {
27
27
  }
28
28
  },
29
29
 
30
- listen: function() {
30
+ listen: function formListen() {
31
31
  bean.on(document.querySelector('body'), 'submit', 'form', function(event){
32
32
  if(!event.target.dataset['remote']) {
33
33
  event.preventDefault()
@@ -2,15 +2,15 @@ var request = require('superagent')
2
2
  var bean = require('bean')
3
3
 
4
4
  var Messages = {
5
- el: function(){
5
+ el: function messagesEl(){
6
6
  return document.querySelector('.pop-message')
7
7
  },
8
8
 
9
- fetch: function(){
9
+ fetch: function messagesFetch(){
10
10
  request.get('/messages.json').end(this.end.bind(this));
11
11
  },
12
12
 
13
- dismiss: function(event){
13
+ dismiss: function messagesDismiss(event){
14
14
  self = this
15
15
  event.preventDefault()
16
16
  event.stopPropagation()
@@ -27,7 +27,7 @@ var Messages = {
27
27
 
28
28
  },
29
29
 
30
- end: function(error, response) {
30
+ end: function messagesEnd(error, response) {
31
31
  if (error || response.serverError) {
32
32
  return
33
33
  } else {
@@ -41,7 +41,7 @@ var Messages = {
41
41
  }
42
42
  },
43
43
 
44
- messageHTML: function(options){
44
+ messageHTML: function messagesMessageHTML(options){
45
45
  options.style = options.style || ''
46
46
  var classnames = "message-content "
47
47
  if (options.style)
@@ -65,11 +65,11 @@ var Messages = {
65
65
  return html
66
66
  },
67
67
 
68
- saveMessage: function(content){
68
+ saveMessage: function messagesSaveMessage(content){
69
69
  window.Megatron.accountMessage = content
70
70
  },
71
71
 
72
- showMessage: function(content) {
72
+ showMessage: function messagesShowMessage(content) {
73
73
  if(this.el()) {
74
74
  this.el().innerHTML = content
75
75
  } else {
@@ -82,7 +82,7 @@ var Messages = {
82
82
  }
83
83
  },
84
84
 
85
- load: function(){
85
+ load: function messagesLoad(){
86
86
  if(window.location.hostname.match(/app\.compose\.(io|dev)/)){
87
87
  var message = window.Megatron.accountMessage
88
88
  if(!message) {
@@ -7,7 +7,7 @@
7
7
  // Returns: HTML which is "2014-01-28 18:00:00 CST", separated and wrapped with spans
8
8
  // with classnames: date, time and timezone
9
9
  //
10
- var dateToHtml = function (dateString, zone) {
10
+ var dateToHtml = function dateToHtml(dateString, zone) {
11
11
 
12
12
  if(isNaN(new Date("2014-01-29T18:14:29+00:00").getDate())) {
13
13
  return false
@@ -48,7 +48,7 @@ var dateToHtml = function (dateString, zone) {
48
48
  return str
49
49
  }
50
50
 
51
- var pad = function(num, pad){
51
+ var pad = function datePad(num, pad){
52
52
  pad = pad || 2
53
53
  while(String(num).length < pad) {
54
54
  num = '0' + num
@@ -8,7 +8,7 @@ require('compose-dataset-shim')
8
8
  var TimeSwitch = {
9
9
 
10
10
  // Attach listeners, setup HTML templates
11
- setup: function() {
11
+ setup: function timeSwitchSetup() {
12
12
  if(!timeago.browserSupport()) return false
13
13
  if(!this.listening) this.listen()
14
14
 
@@ -25,13 +25,13 @@ var TimeSwitch = {
25
25
  },
26
26
 
27
27
  // Attach listeners to toggle time zones whine clicked
28
- listen: function() {
28
+ listen: function timeSwitchListen() {
29
29
  bean.on(document, "click", ".time-switch", TimeSwitch.toggle)
30
30
  this.listening = true
31
31
  },
32
32
 
33
33
  // Switch between UTC and local time
34
- toggle: function(event) {
34
+ toggle: function timeSwitchToggle(event) {
35
35
  var timeEls = document.querySelectorAll('.time-switch')
36
36
 
37
37
  Array.prototype.forEach.call(timeEls, function(el) {
@@ -45,7 +45,7 @@ var TimeSwitch = {
45
45
  // - date (a date object)
46
46
  // - timeagoPosition, String, either 'before' or 'after'
47
47
  //
48
- template: function(date, timeagoPosition, timeagoStyle) {
48
+ template: function timeSwitchTemplate(date, timeagoPosition, timeagoStyle) {
49
49
  var utc = dateToHtml(date, 'UTC')
50
50
  var local = dateToHtml(date)
51
51
  var t = '';
@@ -67,7 +67,7 @@ var TimeSwitch = {
67
67
  },
68
68
 
69
69
  // Converts a date to relative time string wrapped in a span
70
- timeagoTemplate: function(date, position, style) {
70
+ timeagoTemplate: function timeSwitchTimeagoTemplate(date, position, style) {
71
71
  var relative = timeago.parse(date, style)
72
72
  var dash = "<span class='dash'>&nbsp;-&nbsp;</span>"
73
73
  var html = ''
@@ -3,7 +3,7 @@
3
3
 
4
4
  let Timeago = {
5
5
  // setup HTML templates
6
- setup: function() {
6
+ setup: function timeagoSetup() {
7
7
 
8
8
  var timeEls = document.querySelectorAll('.timeago[datetime]')
9
9
 
@@ -15,11 +15,11 @@ let Timeago = {
15
15
  },
16
16
 
17
17
  // If a browser can't handle dates, bail.
18
- browserSupport: function() {
18
+ browserSupport: function timeagoBrowserSupport() {
19
19
  return !isNaN(new Date("2014-01-29T18:14:29+00:00").getDate())
20
20
  },
21
21
 
22
- parse: function(time, style) {
22
+ parse: function timeagoParse(time, style) {
23
23
 
24
24
  style = style || "normal"
25
25
  if (typeof(time) == 'string') {
@@ -6,19 +6,18 @@ require('compose-tap-event')
6
6
  require('compose-dataset-shim')
7
7
 
8
8
  var Toggler = {
9
- listen: function(){
10
- bean.on(document, "click", "[data-toggle], [data-show], [data-hide]", Toggler.trigger)
9
+ listen: function togglerListen(){
10
+ bean.on(document, "click", "[data-toggle], [data-show], [data-hide], [data-toggle-class], [data-add-class], [data-remove-class]", Toggler.trigger)
11
11
  bean.on(document, "change", ".select-toggler", Toggler.trigger)
12
12
  },
13
13
 
14
- refresh: function(){
14
+ refresh: function togglerRefresh(){
15
15
  Toggler.toggleRadios()
16
16
  Toggler.toggleCheckboxes()
17
17
  Toggler.setupSelects()
18
18
  },
19
19
 
20
- trigger: function(event) {
21
-
20
+ trigger: function togglerTrigger(event) {
22
21
  var target = event.currentTarget
23
22
 
24
23
  if (target.tagName.toLowerCase() == 'a' && target.getAttribute('href') == "#") {
@@ -36,16 +35,51 @@ var Toggler = {
36
35
  Toggler.dispatch(target, 'hide')
37
36
  Toggler.dispatch(target, 'toggle')
38
37
  Toggler.dispatch(target, 'show')
38
+ Toggler.dispatch(target, 'addClass')
39
+ Toggler.dispatch(target, 'removeClass')
40
+ Toggler.dispatch(target, 'toggleClass')
39
41
  }
40
42
  },
41
43
 
42
- dispatch: function(el, type, force) {
44
+ dispatch: function togglerDispatch(el, type, force) {
43
45
  if (el.dataset[type]){
44
- Toggler.setState(el.dataset[type], type)
46
+ if (type.match(/class/i)){
47
+ Toggler.setClass(el, type)
48
+ } else {
49
+ Toggler.setState(el.dataset[type], type)
50
+ }
51
+ }
52
+ },
53
+
54
+ // Add, remove, or toggle classnames, triggered by elements with:
55
+ // data-hide-class, data-show-class, and data-toggle-class values
56
+ //
57
+ // Data value examples:
58
+ // - "classname" - add/remove/toggle classname on current element
59
+ // - "foo bar" - multiple classnames, separated by spaces (like html class property)
60
+ // - "foo bar; selector" - change classnames on elements matched by selector
61
+ // - "foo bar; selector, selector" - match multiple selectors
62
+ setClass: function (el, action){
63
+ // Get selector and classnames, format: "classname classname; selector,selector"
64
+ var settings = el.dataset[action].split(';')
65
+ var classnames = settings[0].trim()
66
+
67
+ // If no slectors are present, use the current el for classnames
68
+ var matches = document.querySelectorAll(settings[1])
69
+ if (matches.length == 0) matches = [el]
70
+
71
+ if (typeof(action) == 'boolean') {
72
+ action = (action ? 'addClass' : 'removeClass')
45
73
  }
74
+
75
+ Array.prototype.forEach.call(matches, function(match){
76
+ Array.prototype.forEach.call(classnames.split(' '), function(classname) {
77
+ classie[action](match, classname)
78
+ })
79
+ })
46
80
  },
47
81
 
48
- setState: function(selectors, state) {
82
+ setState: function toggletSetState(selectors, state) {
49
83
  var matches = document.querySelectorAll(selectors)
50
84
  if (typeof(state) == 'boolean') {
51
85
  state = (state ? 'show' : 'hide')
@@ -56,7 +90,7 @@ var Toggler = {
56
90
  })
57
91
  },
58
92
 
59
- toggle: function(el) {
93
+ toggle: function togglerToggle(el) {
60
94
 
61
95
  if (el.offsetParent === null) {
62
96
  Toggler.show(el)
@@ -66,7 +100,7 @@ var Toggler = {
66
100
 
67
101
  },
68
102
 
69
- show: function(el) {
103
+ show: function togglerShow(el) {
70
104
  classie.remove(el, 'hidden')
71
105
  classie.add(el, 'visible')
72
106
  var focusEl = el.querySelector('[data-focus]')
@@ -76,12 +110,12 @@ var Toggler = {
76
110
  }
77
111
  },
78
112
 
79
- hide: function(el) {
113
+ hide: function togglerHide(el) {
80
114
  classie.remove(el, 'visible')
81
115
  classie.add(el, 'hidden')
82
116
  },
83
117
 
84
- toggleRadios: function(radios) {
118
+ toggleRadios: function togglerToggleRadio(radios) {
85
119
  var radios = radios || 'input[type=radio][data-show]'
86
120
 
87
121
  Array.prototype.forEach.call(document.querySelectorAll(radios), function(radio) {
@@ -89,19 +123,19 @@ var Toggler = {
89
123
  })
90
124
  },
91
125
 
92
- toggleCheckbox: function(checkbox) {
126
+ toggleCheckbox: function togglerToggeCheckbox(checkbox) {
93
127
  Toggler.setState(checkbox.dataset.hide, !checkbox.checked)
94
128
  Toggler.setState(checkbox.dataset.toggle, 'toggle')
95
129
  Toggler.setState(checkbox.dataset.show, checkbox.checked)
96
130
  },
97
131
 
98
- toggleSelect: function(select) {
132
+ toggleSelect: function togglerToggleSelect(select) {
99
133
  var option = select.selectedOptions[0]
100
134
  Toggler.dispatch(option, 'hide')
101
135
  Toggler.dispatch(option, 'show')
102
136
  },
103
137
 
104
- toggleCheckboxes: function() {
138
+ toggleCheckboxes: function togglerToggleCheckboxes() {
105
139
  var checkboxes = 'input[type=checkbox][data-toggle]'
106
140
  Array.prototype.forEach.call(document.querySelectorAll(checkboxes), Toggler.toggleCheckbox)
107
141
  },
@@ -109,7 +143,7 @@ var Toggler = {
109
143
  // Add data-hide to each <option> containing the selectors from other
110
144
  // option's data-show. This makes the toggling of elements exclusive.
111
145
  //
112
- setupSelects: function(select){
146
+ setupSelects: function togglerSetupSelects(select){
113
147
  Array.prototype.forEach.call(document.querySelectorAll('option[data-show]'), function(option){
114
148
  if (!option.dataset.hide) {
115
149
 
@@ -133,7 +167,7 @@ var Toggler = {
133
167
 
134
168
  // Find parent <select> for an option (accounts for option groups)
135
169
  //
136
- getSelectFromOption: function(el) {
170
+ getSelectFromOption: function togglerGetSelectFromOption(el) {
137
171
  var p = el.parentElement
138
172
 
139
173
  if (p.tagName.toLowerCase() == 'select') {
@@ -145,13 +179,13 @@ var Toggler = {
145
179
 
146
180
  // Return an array of all data-show values from elements
147
181
  //
148
- showAttributes: function(elements) {
182
+ showAttributes: function togglerShowAttributes(elements) {
149
183
  return Array.prototype.map.call(elements, function(el) {
150
184
  return el.dataset.show
151
185
  })
152
186
  },
153
187
 
154
- toggleSelects: function(selects) {
188
+ toggleSelects: function togglerToggleSelects(selects) {
155
189
  var selects = selects || 'option[data-show]'
156
190
 
157
191
  Array.prototype.forEach.call(document.querySelectorAll(radios), function(radio) {