rails_javascript_log 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_javascript_log.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Vlado Cingel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # RailsJavascriptLog
2
+
3
+ Rails engine containing Adam Schwartz's javascript logging library [https://github.com/adamschwartz/log](https://github.com/adamschwartz/log).
4
+
5
+ This gem just saves you from having to locate and copy the javascript into place.
6
+
7
+ ## Features
8
+
9
+ * Safely call `log` (instead of `console.log`) in any browser.
10
+ * Use markdown syntax for quick formatting:
11
+ * *italic* — `log('this is *italic*')`
12
+ * **bold** — `log('this word _bold_')`
13
+ * `code` — ``log('this word `code`')``
14
+ * Use a custom syntax to style text however you want: `log('this is [c="color: red"]red[c]')`.
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'rails_javascript_log'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ ## Usage
27
+
28
+ Add this line to your `app/assets/javascripts/application.js`:
29
+
30
+ //= require rails_javascript_log
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ require "rails_javascript_log/version"
2
+
3
+ module RailsJavascriptLog
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module RailsJavascriptLog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_javascript_log/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_javascript_log"
8
+ spec.version = RailsJavascriptLog::VERSION
9
+ spec.authors = ["Vlado Cingel"]
10
+ spec.email = ["vladocingel@gmail.com"]
11
+ spec.description = %q{Rails engine containing Adam Schwartz's javascript logging library (Console.log with style) }
12
+ spec.summary = %q{Rails engine containing Adam Schwartz's javascript logging library (Console.log with style) }
13
+ spec.homepage = "https://github.com/vlado/rails_javascript_log"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,91 @@
1
+ return unless window.console and window.console.log
2
+
3
+ log = ->
4
+ args = []
5
+
6
+ makeArray(arguments).forEach (arg) ->
7
+ if typeof arg is 'string'
8
+ args = args.concat stringToArgs arg
9
+
10
+ else
11
+ args.push arg
12
+
13
+ _log.apply window, args
14
+
15
+ _log = ->
16
+ console.log.apply console, makeArray(arguments)
17
+
18
+ makeArray = (arrayLikeThing) ->
19
+ Array::slice.call arrayLikeThing
20
+
21
+ formats = [{
22
+ # Italic
23
+ regex: /\*([^\*)]+)\*/
24
+ replacer: (m, p1) -> "%c#{p1}%c"
25
+ styles: -> ['font-style: italic', '']
26
+ }, {
27
+ # Bold
28
+ regex: /\_([^\_)]+)\_/
29
+ replacer: (m, p1) -> "%c#{p1}%c"
30
+ styles: -> ['font-weight: bold', '']
31
+ }, {
32
+ # Code
33
+ regex: /\`([^\`)]+)\`/
34
+ replacer: (m, p1) -> "%c#{p1}%c"
35
+ styles: -> ['background: rgb(255, 255, 219); padding: 1px 5px; border: 1px solid rgba(0, 0, 0, 0.1)', '']
36
+ }, {
37
+ # Custom syntax: [c="color: red"]red[c]
38
+ regex: /\[c\=\"([^\")]+)\"\]([^\[)]+)\[c\]/
39
+ replacer: (m, p1, p2) -> "%c#{p2}%c"
40
+ styles: (match) -> [match[1], '']
41
+ }]
42
+
43
+ hasMatches = (str) ->
44
+ _hasMatches = false
45
+
46
+ formats.forEach (format) ->
47
+ if format.regex.test str
48
+ _hasMatches = true
49
+
50
+ return _hasMatches
51
+
52
+ getOrderedMatches = (str) ->
53
+ matches = []
54
+
55
+ formats.forEach (format) ->
56
+ match = str.match format.regex
57
+ if match
58
+ matches.push
59
+ format: format
60
+ match: match
61
+
62
+ return matches.sort((a, b) -> a.match.index - b.match.index)
63
+
64
+ stringToArgs = (str) ->
65
+ styles = []
66
+
67
+ while hasMatches str
68
+ matches = getOrderedMatches str
69
+ firstMatch = matches[0]
70
+ str = str.replace firstMatch.format.regex, firstMatch.format.replacer
71
+ styles = styles.concat firstMatch.format.styles(firstMatch.match)
72
+
73
+ [str].concat styles
74
+
75
+ # TODO - replace these with a feature test
76
+ isSafari = -> /Safari/.test(navigator.userAgent) and /Apple Computer/.test(navigator.vendor)
77
+ isIE = -> /MSIE/.test(navigator.userAgent)
78
+
79
+ # Safari starting supporting stylized logs in Nightly 537.38+
80
+ # See https://github.com/adamschwartz/log/issues/6
81
+ safariSupport = ->
82
+ m = navigator.userAgent.match /AppleWebKit\/(\d+)\.(\d+)(\.|\+|\s)/
83
+ return false unless m
84
+ return 537.38 >= parseInt(m[1], 10) + (parseInt(m[2], 10) / 100)
85
+
86
+ # Export
87
+ if (isSafari() and not safariSupport()) or isIE()
88
+ window.log = _log
89
+ else
90
+ window.log = log
91
+ window.log.l = _log
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_javascript_log
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Vlado Cingel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ none: false
21
+ name: bundler
22
+ type: :development
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.3'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ none: false
37
+ name: rake
38
+ type: :development
39
+ prerelease: false
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ description: ! 'Rails engine containing Adam Schwartz''s javascript logging library
47
+ (Console.log with style) '
48
+ email:
49
+ - vladocingel@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - lib/rails_javascript_log.rb
60
+ - lib/rails_javascript_log/version.rb
61
+ - rails_javascript_log.gemspec
62
+ - vendor/assets/javascripts/rails_javascript_log.js.coffee
63
+ homepage: https://github.com/vlado/rails_javascript_log
64
+ licenses:
65
+ - MIT
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ none: false
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ none: false
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.23
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Rails engine containing Adam Schwartz's javascript logging library (Console.log
88
+ with style)
89
+ test_files: []
90
+ has_rdoc: