delogger 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fbef0668a642331e5096b767f11653c6d5b2617
4
- data.tar.gz: 8e01c55ea71d437d25e005cdaac787c7fc15b53b
3
+ metadata.gz: ec79336b89d1bd048e47fd1740706bb6ec0e41fb
4
+ data.tar.gz: 7190f5b8f2bd83fce6f463b5df60d717814b486e
5
5
  SHA512:
6
- metadata.gz: 3f49acb8a053f32bac14bccbf7322aa7f6fa571091b79cdcbaa8d2e5054fbbe9d56a00b98bb225c884b3442304e4a246d48cf78e708d55811e9d8af8a634a334
7
- data.tar.gz: 7ff26d70e023c4df3342dc0f56ebe61d12e468cadec4d03147081fb29bf3ebc4de6155dc8c29e05fc37e55635c650510443a50c9ed955c47c6dab7b786ca32cf
6
+ metadata.gz: ec68b265b5d8412a85437be839f0cbd7f43a2013deed9698f8b2d92fde1e1547870be64f61d7c3085e46407d232c7237df9ee9f989fa38279cdcd17d3588f437
7
+ data.tar.gz: 84e147d6b7675326d54622f5cb04a752d918f163dda408d0ed35d99a8d1d3e46a6e4aff60140e61bb5137b102db89c7a8fa890e43777d9c566539e9d9f10a6ac
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Alexander Komarov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ [![Gem Version](https://badge.fury.io/rb/delogger.svg)](https://badge.fury.io/rb/delogger)
2
+
3
+ # Delogger
4
+
5
+ Make your browser console beautiful. This gem is a work in progress.
6
+ ![Demo](/images/demo.png?raw=true)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'delogger'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install delogger
23
+
24
+ Add this to your `application.js`:
25
+ ```
26
+ //= require delogger
27
+ ```
28
+
29
+ And `application.css`:
30
+ ```
31
+ *= require delogger
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ These methods work similarly to `console.log`, but they support [formatting](#formatting):
37
+ - `DeLogger.debug`
38
+ - `DeLogger.warn`
39
+ - `DeLogger.error`
40
+
41
+ By default, DeLogger is **disabled**. To enable it, use `DeLogger.enable()`. You can disable it again
42
+ using `DeLogger.disable()`.
43
+
44
+ ## Logging levels
45
+
46
+ DeLogger has three logging levels: `debug`, `warn` and `error`. Level can be set using `DeLogger.level`
47
+ (default is `debug`). (TODO)
48
+
49
+ ## Formatting
50
+
51
+ DeLogger supports string formatting. Syntax: `"(my text).class1.class2"`. Classes are specific for
52
+ the logger and are not being fetched from stylesheets.
53
+ Supported classes: `badge`, `debug`, `warn`, `error`, `bold`, `italic`.
54
+ See also: [color classes](#color-classes).
55
+
56
+ Example:
57
+ ```js
58
+ DeLogger.log("(MyClass#myMethod).badge", "(@akxcv).badge.warn", "(bold).bold", { foo: 'bar' })
59
+ ```
60
+ ![Example output](/images/example.png?raw=true)
61
+
62
+ TODO
63
+
64
+ ## Color classes
65
+
66
+ DeLogger supports following color classes (both for badges and normal text):
67
+ - `.blue`
68
+ - `.orange`
69
+ - `.red`
70
+ - `.green`
71
+ - `.cyan`
72
+ - `.yellow`
73
+ - `.gray`
74
+ - `.brown`
75
+ - `.purple`
76
+ - `.pink`
77
+
78
+ ## Adding custom / overriding existing styles
79
+
80
+ All styles are declared in a stylesheet and thus are easily extensible.
81
+ See [`assets/stylesheets/delogger.scss`](assets/stylesheets/delogger.scss).
82
+ At the moment, only these attributes are supported: `margin-left`, `color`, `background-color`,
83
+ `border-radius`, `padding`, `font-weight`, `font-style`.
84
+
85
+ ## Development
86
+
87
+ TODO
88
+
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/akxcv/delogger.
92
+
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,62 @@
1
+ class @DeLogger
2
+ @debug: (args...) ->
3
+ print('debug', computeStyle('badge debug'), args...)
4
+
5
+ @warn: (args...) ->
6
+ print('warn', computeStyle('badge warn'), args...)
7
+
8
+ @error: (args...) ->
9
+ print('error', computeStyle('badge error'), args...)
10
+
11
+ @enable: ->
12
+ localStorage.setItem("deloggerEnabled", true)
13
+
14
+ @disable: ->
15
+ localStorage.removeItem("deloggerEnabled")
16
+
17
+ @setLevel: (level) ->
18
+ localStorage.setItem("deloggerLevel", level)
19
+
20
+ # private
21
+
22
+ print = (level, initialStyles, args...) ->
23
+ return unless canPrint(level)
24
+ text = "%c#{level}"
25
+ styles = [initialStyles]
26
+ formattedArgumentCount = 0
27
+
28
+ for arg in args
29
+ break unless typeof arg is 'string'
30
+ [string, style] = parseString(arg)
31
+ text += string
32
+ styles.push(style)
33
+ formattedArgumentCount += 1
34
+
35
+ args.splice(0, formattedArgumentCount)
36
+ console.log text, styles..., args...
37
+
38
+ canPrint = (level) ->
39
+ localStorage.deloggerEnabled? and availableLevels().indexOf(level) != -1
40
+
41
+ availableLevels = ->
42
+ switch localStorage.deloggerLevel
43
+ when 'debug' then ['debug', 'warn', 'error']
44
+ when 'warn' then ['warn', 'error']
45
+ when 'error' then ['error']
46
+ else ['debug', 'warn', 'error']
47
+
48
+ parseString = (string) ->
49
+ if match = string.match(/^\((.+)\)(\..+)$/)
50
+ classes = match[2].split('.').join(' ')
51
+ return ["%c#{match[1]}", computeStyle("#{classes} after")]
52
+ ["%c#{string}", computeStyle('default after')]
53
+
54
+ computeStyle = (classes) ->
55
+ div = $("<div id='delogger_temp' class='delogger #{classes}' style='display: none;'>")
56
+ $('body').append(div)
57
+ style = ("#{key}:#{value}" for key, value of div.css(supportedStyles)).join(';')
58
+ $('#delogger_temp').remove()
59
+ style
60
+
61
+ supportedStyles = ['margin-left', 'color', 'background-color', 'border-radius', 'padding',
62
+ 'font-weight', 'font-style']
@@ -0,0 +1,119 @@
1
+ .delogger {
2
+ color: black;
3
+ background-color: transparent;
4
+ border-radius: 0;
5
+ padding: 0;
6
+ margin-left: 0;
7
+ font-weight: normal;
8
+ font-style: normal;
9
+
10
+ &.default {}
11
+ &.after {
12
+ margin-left: 3px;
13
+ }
14
+
15
+ &.badge {
16
+ color: white;
17
+ background-color: black;
18
+ border-radius: 9px;
19
+ padding: 1px 5px;
20
+
21
+ &.debug, &.blue {
22
+ color: white;
23
+ background-color: blue;
24
+ }
25
+
26
+ &.warn, &.orange {
27
+ color: white;
28
+ background-color: orange;
29
+ }
30
+
31
+ &.error, &.red {
32
+ color: white;
33
+ background-color: red;
34
+ }
35
+
36
+ &.green {
37
+ color: white;
38
+ background-color: green;
39
+ }
40
+
41
+ &.cyan {
42
+ color: gray;
43
+ background-color: cyan;
44
+ }
45
+
46
+ &.yellow {
47
+ color: gray;
48
+ background-color: yellow;
49
+ }
50
+
51
+ &.gray {
52
+ color: white;
53
+ background-color: gray;
54
+ }
55
+
56
+ &.brown {
57
+ color: white;
58
+ background-color: brown;
59
+ }
60
+
61
+ &.purple {
62
+ color: white;
63
+ background-color: purple;
64
+ }
65
+
66
+ &.pink {
67
+ color: gray;
68
+ background-color: pink;
69
+ }
70
+ }
71
+
72
+ &.blue {
73
+ color: blue;
74
+ }
75
+
76
+ &.orange {
77
+ color: orange;
78
+ }
79
+
80
+ &.red {
81
+ color: red;
82
+ }
83
+
84
+ &.green {
85
+ color: green;
86
+ }
87
+
88
+ &.cyan {
89
+ color: cyan;
90
+ }
91
+
92
+ &.yellow {
93
+ color: yellow;
94
+ }
95
+
96
+ &.gray {
97
+ color: gray;
98
+ }
99
+
100
+ &.brown {
101
+ color: brown;
102
+ }
103
+
104
+ &.purple {
105
+ color: purple;
106
+ }
107
+
108
+ &.pink {
109
+ color: pink;
110
+ }
111
+
112
+ &.bold {
113
+ font-weight: bold;
114
+ }
115
+
116
+ &.italic {
117
+ font-style: italic;
118
+ }
119
+ }
data/bin/compile ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ Bundler.setup
4
+
5
+ require 'coffee-script'
6
+ require 'uglifier'
7
+ require 'sass'
8
+
9
+ JS_IN_PATH = 'assets/javascripts/delogger.coffee'
10
+ JS_OUT_PATH = 'vendor/assets/javascripts/delogger.js'
11
+ CSS_IN_PATH = 'assets/stylesheets/delogger.scss'
12
+ CSS_OUT_PATH = 'vendor/assets/stylesheets/delogger.css'
13
+
14
+ compiled_coffee = CoffeeScript.compile(File.read(JS_IN_PATH))
15
+ File.write JS_OUT_PATH, Uglifier.compile(compiled_coffee)
16
+ File.write CSS_OUT_PATH, Sass.compile(File.read(CSS_IN_PATH))
data/delogger.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'delogger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "delogger"
8
+ spec.version = DeLogger::VERSION
9
+ spec.authors = ["Alexander Komarov"]
10
+ spec.email = ["ak@akxcv.com"]
11
+
12
+ spec.summary = %q{Pretty output for browser console}
13
+ spec.description = %q{Format your browser console output with colors, badges and more}
14
+ spec.homepage = "https://github.com/akxcv/delogger"
15
+ spec.license = "MIT"
16
+
17
+ spec.require_path = "lib"
18
+ spec.files = `git ls-files`.split("\n")
19
+
20
+ %w[bundler coffee-script coffee-script-source uglifier sass].each { |x| spec.add_development_dependency x }
21
+ end
data/images/demo.png ADDED
Binary file
Binary file
data/lib/delogger.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "delogger/version"
2
+ require "delogger/rails"
3
+
4
+ module DeLogger
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ require "delogger/rails/engine"
2
+
3
+ module DeLogger
4
+ module Rails
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module DeLogger
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module DeLogger
2
+ VERSION = "0.2.1"
3
+ end
@@ -0,0 +1 @@
1
+ (function(){var e=[].slice;this.DeLogger=function(){function r(){}var n,l,t,o,a,c;return r.debug=function(){var r;return r=1<=arguments.length?e.call(arguments,0):[],a.apply(null,["debug",t("badge debug")].concat(e.call(r)))},r.warn=function(){var r;return r=1<=arguments.length?e.call(arguments,0):[],a.apply(null,["warn",t("badge warn")].concat(e.call(r)))},r.error=function(){var r;return r=1<=arguments.length?e.call(arguments,0):[],a.apply(null,["error",t("badge error")].concat(e.call(r)))},r.enable=function(){return localStorage.setItem("deloggerEnabled",!0)},r.disable=function(){return localStorage.removeItem("deloggerEnabled")},r.setLevel=function(e){return localStorage.setItem("deloggerLevel",e)},a=function(){var r,n,t,a,c,u,g,i,d,f,s,p;if(g=arguments[0],c=arguments[1],n=3<=arguments.length?e.call(arguments,2):[],l(g)){for(p="%c"+g,s=[c],t=0,a=0,u=n.length;a<u&&(r=n[a],"string"==typeof r);a++)i=o(r),d=i[0],f=i[1],p+=d,s.push(f),t+=1;return n.splice(0,t),console.log.apply(console,[p].concat(e.call(s),e.call(n)))}},l=function(e){return null!=localStorage.deloggerEnabled&&n().indexOf(e)!==-1},n=function(){switch(localStorage.deloggerLevel){case"debug":return["debug","warn","error"];case"warn":return["warn","error"];case"error":return["error"];default:return["debug","warn","error"]}},o=function(e){var r,n;return(n=e.match(/^\((.+)\)(\..+)$/))?(r=n[2].split(".").join(" "),["%c"+n[1],t(r+" after")]):["%c"+e,t("default after")]},t=function(e){var r,n,l,t;return r=$("<div id='delogger_temp' class='delogger "+e+"' style='display: none;'>"),$("body").append(r),l=function(){var e,l;e=r.css(c),l=[];for(n in e)t=e[n],l.push(n+":"+t);return l}().join(";"),$("#delogger_temp").remove(),l},c=["margin-left","color","background-color","border-radius","padding","font-weight","font-style"],r}()}).call(this);
@@ -0,0 +1,69 @@
1
+ .delogger {
2
+ color: black;
3
+ background-color: transparent;
4
+ border-radius: 0;
5
+ padding: 0;
6
+ margin-left: 0;
7
+ font-weight: normal;
8
+ font-style: normal; }
9
+ .delogger.after {
10
+ margin-left: 3px; }
11
+ .delogger.badge {
12
+ color: white;
13
+ background-color: black;
14
+ border-radius: 9px;
15
+ padding: 1px 5px; }
16
+ .delogger.badge.debug, .delogger.badge.blue {
17
+ color: white;
18
+ background-color: blue; }
19
+ .delogger.badge.warn, .delogger.badge.orange {
20
+ color: white;
21
+ background-color: orange; }
22
+ .delogger.badge.error, .delogger.badge.red {
23
+ color: white;
24
+ background-color: red; }
25
+ .delogger.badge.green {
26
+ color: white;
27
+ background-color: green; }
28
+ .delogger.badge.cyan {
29
+ color: gray;
30
+ background-color: cyan; }
31
+ .delogger.badge.yellow {
32
+ color: gray;
33
+ background-color: yellow; }
34
+ .delogger.badge.gray {
35
+ color: white;
36
+ background-color: gray; }
37
+ .delogger.badge.brown {
38
+ color: white;
39
+ background-color: brown; }
40
+ .delogger.badge.purple {
41
+ color: white;
42
+ background-color: purple; }
43
+ .delogger.badge.pink {
44
+ color: gray;
45
+ background-color: pink; }
46
+ .delogger.blue {
47
+ color: blue; }
48
+ .delogger.orange {
49
+ color: orange; }
50
+ .delogger.red {
51
+ color: red; }
52
+ .delogger.green {
53
+ color: green; }
54
+ .delogger.cyan {
55
+ color: cyan; }
56
+ .delogger.yellow {
57
+ color: yellow; }
58
+ .delogger.gray {
59
+ color: gray; }
60
+ .delogger.brown {
61
+ color: brown; }
62
+ .delogger.purple {
63
+ color: purple; }
64
+ .delogger.pink {
65
+ color: pink; }
66
+ .delogger.bold {
67
+ font-weight: bold; }
68
+ .delogger.italic {
69
+ font-style: italic; }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Komarov
@@ -86,7 +86,23 @@ email:
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
- files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - assets/javascripts/delogger.coffee
95
+ - assets/stylesheets/delogger.scss
96
+ - bin/compile
97
+ - delogger.gemspec
98
+ - images/demo.png
99
+ - images/example.png
100
+ - lib/delogger.rb
101
+ - lib/delogger/rails.rb
102
+ - lib/delogger/rails/engine.rb
103
+ - lib/delogger/version.rb
104
+ - vendor/assets/javascripts/delogger.js
105
+ - vendor/assets/stylesheets/delogger.css
90
106
  homepage: https://github.com/akxcv/delogger
91
107
  licenses:
92
108
  - MIT