debug-extras 0.2.0 → 0.3.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: e28babbb91f3d8087f3fed430c67c8c4f6ab32d6
4
- data.tar.gz: 29c8e723fc8c897a55150d4ebe5e81c0a6146adb
3
+ metadata.gz: 22f0e2df357a2929bee4703f660b777bad7eae9c
4
+ data.tar.gz: 37da334a490125800388a00ce5dee88b0eed0362
5
5
  SHA512:
6
- metadata.gz: 31b4776464461e21d70791796ee805bd7282a47d48cd3a31ce94ea4fa0a36f7414ec475750b72b222febac4451732b281bf1d8acb34299b9d480d3f631f7f01e
7
- data.tar.gz: f9ff33003fbb0559a1100ab9bd3ec051b3c9ddf9a95008e8e035fece2adab39f5446363c7e296a31135eddf237122a5a82874d69583748108e063ac394017dcc
6
+ metadata.gz: e44b543a282aa88c2d10111afc9e1270ab5320b6cb06a2c2a3151b67af925437c770fb754fe3c83de19c7afaa0d8f306a7e0edab8b8fc2f09292e39ffedbd49b
7
+ data.tar.gz: bac5229d5b6bde0dee0bbcca118b8e9439cba96ef42cd16a72fe7ad2ee964cfc2c1a3f22cb16461ef21c1a767f50fda4cec16c76135c4765c9f7e81b3a67ffd9
data/README.md CHANGED
@@ -1,21 +1,58 @@
1
+ TODO: move to js
2
+ TODO: check with rspec
3
+ TODO: check with pure ruby
4
+ TODO: make PR to better_errors? -
5
+ TODO: check byebug
6
+ TODO: update pivotal
7
+ TODO: update REAMDE
8
+
1
9
  # DebugExtras [![Gem](https://img.shields.io/gem/v/debug-extras.svg)](https://rubygems.org/gems/debug-extras) [![Build Status](https://img.shields.io/travis/vavgustov/debug-extras/master.svg)](https://travis-ci.org/vavgustov/debug-extras) [![Code Climate](https://img.shields.io/codeclimate/github/vavgustov/debug-extras.svg)](https://codeclimate.com/github/vavgustov/debug-extras)
2
10
 
3
- Extras for rails debugging.
11
+ Extras for Ruby on Rails debugging.
12
+
13
+ TODO: add image here with dd results
14
+
15
+ ## Features
16
+
17
+ At this moment provide next things:
18
+ 1. `dd <variable>` at any place of your application
19
+ (controllers/models/views/services/etc). After that you can see dump of this
20
+ variable without any other stuff at your web browser.
21
+ It's something like simple alternative to `dd` function from
22
+ [Laravel](https://laravel.com/) for [Ruby on Rails](http://rubyonrails.org/).
23
+
24
+ 2. `dump <variable>` at your views. It's alternative for `debug` method from `ActionView::Helpers::DebugHelper`.
25
+
26
+ 3. fix for `better_errors` and `binding_or_caller` performance
4
27
 
5
28
  ## Installation
6
29
 
30
+ Add this line to your Gemfile:
31
+
7
32
  ```ruby
8
- gem 'debug-extras'
33
+ gem 'debug-extras', group: :development
9
34
  ```
10
35
 
11
36
  And then execute:
12
37
 
13
38
  $ bundle
14
39
 
15
- Or install it yourself as:
40
+ Or you can install it using [rgversion](https://github.com/vavgustov/rgversion) like any other gems.
41
+
42
+ ## Samples
43
+
44
+ ```ruby
45
+ dd self.instance_variables
46
+ ```
47
+
48
+ ![image](https://user-images.githubusercontent.com/312873/28998770-ddfc7b74-7a3b-11e7-905b-52b3c1c797a4.png)
49
+
50
+ ```erb
51
+ <%= rap self.instance_variables %>
52
+ ```
53
+
54
+ ![image](https://user-images.githubusercontent.com/312873/28998927-9111f88a-7a3f-11e7-9c8d-cb825472d8ca.png)
55
+
16
56
 
17
- $ gem install debug-extras
18
57
 
19
- ## Usage
20
58
 
21
- Coming soon...
data/debug-extras.gemspec CHANGED
@@ -1,32 +1,32 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'debug_extras/version'
4
+ require "debug_extras/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "debug-extras"
8
- spec.version = DebugExtras.version
8
+ spec.version = DebugExtras::VERSION
9
9
  spec.authors = ["Vladimir Avgustov"]
10
10
  spec.email = ["vavgustov@gmail.com"]
11
11
 
12
- spec.summary = 'Extras for rails debugging.'
13
- spec.description = 'Provide debug helper methods for ActionController::Base and ActionView::Base.'
14
- spec.homepage = 'https://github.com/vavgustov/debug-extras'
15
- spec.license = 'MIT'
12
+ spec.summary = "Extras for rails debugging."
13
+ spec.description = "Provide debug helper methods for ActionController::Base and ActionView::Base."
14
+ spec.homepage = "https://github.com/vavgustov/debug-extras"
15
+ spec.license = "MIT"
16
16
 
17
- spec.required_ruby_version = '>= 2.1.0'
17
+ spec.required_ruby_version = ">= 2.1.0"
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
20
  f.match(%r{^(test|spec|features)/})
21
21
  end
22
22
 
23
- spec.require_paths = ['lib']
23
+ spec.require_paths = ["lib"]
24
24
 
25
- spec.add_development_dependency 'bundler', '~> 1.15'
26
- spec.add_development_dependency 'rake', '~> 10.0'
27
- spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency "bundler", "~> 1.15"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
28
 
29
- spec.add_runtime_dependency 'awesome_print', '~> 1.8'
30
- spec.add_runtime_dependency 'actionview', '> 4.0', '< 6'
31
- spec.add_runtime_dependency 'activesupport', '> 4.0', '< 6'
29
+ spec.add_runtime_dependency "awesome_print", "~> 1.8"
30
+ spec.add_runtime_dependency "actionview", "> 4.0", "< 6"
31
+ spec.add_runtime_dependency "activesupport", "> 4.0", "< 6"
32
32
  end
data/lib/debug-extras.rb CHANGED
@@ -1,21 +1,19 @@
1
- require "debug_extras/version"
2
- require "active_support/concern"
3
- require "active_support/core_ext/string/output_safety"
4
1
  require "active_support/dependencies/autoload"
5
2
  require "active_support/lazy_load_hooks"
6
- require "action_view/helpers/output_safety_helper"
7
- require "awesome_print"
8
- require "debug_extras/middleware"
9
- require "debug_extras/core_ext/object"
10
- require "debug_extras/helpers/view_helpers"
3
+ require "debug_extras/core_ext/kernel"
4
+ require "debug_extras/version"
11
5
 
12
6
  module DebugExtras
13
7
  extend ActiveSupport::Autoload
14
8
 
9
+ autoload :DebugPage
10
+ autoload :Dumper
11
+ autoload :Middleware
15
12
  autoload :Settings
16
13
 
17
14
  ActiveSupport.on_load :action_view do
18
- ActionView::Base.send :include, DebugExtras::Helpers::ViewHelpers
15
+ require "debug_extras/helpers/view_helpers"
16
+ ::ActionView::Base.send :include, DebugExtras::Helpers::ViewHelpers
19
17
  end
20
18
  end
21
19
 
@@ -0,0 +1,10 @@
1
+ require "debug_extras/exceptions"
2
+
3
+ module Kernel
4
+ # dump object through exception message
5
+ def dd(dump, settings = {})
6
+ DebugExtras::Dumper.new(dump, settings).render do |message|
7
+ raise DebugExtras::DebugData, message
8
+ end
9
+ end
10
+ end
@@ -1,15 +1,15 @@
1
1
  require "erb"
2
2
 
3
3
  module DebugExtras
4
- class ErrorPage
4
+ class DebugPage
5
5
  def initialize(exception, request_path)
6
6
  @exception = exception
7
7
  @request_path = request_path
8
- @template = File.read(File.expand_path("../templates/main.html.erb", __FILE__))
8
+ @template = File.read(File.expand_path("../templates/debug.html.erb", __FILE__))
9
9
  end
10
10
 
11
11
  def render
12
- ERB.new(@template).result( binding )
12
+ ERB.new(@template).result(binding)
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -0,0 +1,64 @@
1
+ require "action_view"
2
+ require "awesome_print"
3
+
4
+ module DebugExtras
5
+ class Dumper
6
+ include ActionView::Context
7
+ include ActionView::Helpers::TagHelper
8
+
9
+ def initialize(dump, settings)
10
+ @dump = dump
11
+ @settings = settings
12
+ end
13
+
14
+ def render
15
+ message = content_tag(:div, class: 'debug-extras') do
16
+ @settings.merge! Settings.ap_options
17
+
18
+ output = @dump.ai Settings.ap_options
19
+ output = render_object_names output
20
+ output = add_styles_to_tag(:pre, output)
21
+ output = add_styles_to_tag(:kbd, output)
22
+
23
+ output.html_safe
24
+ end
25
+
26
+ yield message if block_given?
27
+
28
+ message
29
+ end
30
+
31
+ private
32
+
33
+ def convert_hash_to_style(styles)
34
+ styles.map { |k, v| "#{k}: #{v}" }.join('; ')
35
+ end
36
+
37
+ def add_styles_to_tag(tag, output)
38
+ case tag
39
+ when :pre
40
+ output.sub!("<pre>", "<pre style=\"#{convert_hash_to_style(Settings.ap_styles(:pre))}\">")
41
+ when :kbd
42
+ output.gsub!("<kbd style=\"", "<kbd style=\"#{convert_hash_to_style(Settings.ap_styles(:kbd))}; ")
43
+ else
44
+ output
45
+ end
46
+ output
47
+ end
48
+
49
+ def render_object_names(dump)
50
+ output = ""
51
+
52
+ dump.split("<").map.with_index do |v, k|
53
+ if v.include? ":0x" and not v.include? "kbd"
54
+ v.sub!(">", "")
55
+ else
56
+ output << "<" unless k.zero?
57
+ end
58
+ output << v
59
+ end
60
+
61
+ output
62
+ end
63
+ end
64
+ end
@@ -1,10 +1,12 @@
1
+ require "active_support/concern"
2
+
1
3
  module DebugExtras
2
4
  module Helpers
3
5
  module ViewHelpers
4
6
  extend ActiveSupport::Concern
5
7
 
6
- def rap(object)
7
- raw ap(object, DebugExtras::Settings.ap_options)
8
+ def dump(object, settings = {})
9
+ Dumper.new(object, settings).render
8
10
  end
9
11
  end
10
12
  end
@@ -1,5 +1,3 @@
1
- require 'debug_extras/error_page'
2
-
3
1
  module DebugExtras
4
2
  class Middleware
5
3
  def initialize(app)
@@ -7,15 +5,22 @@ module DebugExtras
7
5
  end
8
6
 
9
7
  def call(env)
10
- env['puma.config'].options.user_options.delete(:app) if env.has_key?('puma.config')
8
+ better_errors_fix env
11
9
  @app.call env
12
10
  rescue StandardError => ex
13
- if [ex.class, ex.cause.class].map(&:to_s).include? 'DebugExtras::DebugData'
14
- error_page = ErrorPage.new(ex, Rails.env["PATH_INFO"])
15
- [200, { "Content-Type" => "text/html; charset=utf-8" }, [error_page.render]]
11
+ if [ex.class, ex.cause.class].map(&:to_s).include? "DebugExtras::DebugData"
12
+ debug_page = DebugPage.new(ex, env["PATH_INFO"])
13
+ [200, { "Content-Type" => "text/html; charset=utf-8" }, [debug_page.render]]
16
14
  else
17
15
  @app.call env
18
16
  end
19
17
  end
18
+
19
+ private
20
+
21
+ # based on https://github.com/charliesome/better_errors/issues/341
22
+ def better_errors_fix(env)
23
+ env["puma.config"].options.user_options.delete(:app) if env.has_key?("puma.config")
24
+ end
20
25
  end
21
26
  end
@@ -2,8 +2,34 @@ module DebugExtras
2
2
  module Settings
3
3
  class << self
4
4
  def ap_options
5
- { html: true, color: { array: :red } }
5
+ { html: true, color: { array: :yellowish } }
6
+ end
7
+
8
+ def ap_styles(tag)
9
+ {
10
+ pre: {
11
+ "background" => "#f5f8fa",
12
+ "border" => "1px solid #ccc",
13
+ "border-radius" => "0",
14
+ "color" => "#111",
15
+ "font-family" => "Menlo, Consolas, Ubuntu, monospace",
16
+ "font-weight" => "bold",
17
+ "font-size" => "12px",
18
+ "line-height" => "1.43",
19
+ "margin" => "0 0 10px",
20
+ "padding" => "10px",
21
+ "white-space" => "pre-wrap",
22
+ },
23
+ kbd: {
24
+ "background" => "none",
25
+ "box-shadow" => "none",
26
+ "font-family" => "Menlo, Consolas, Ubuntu, monospace",
27
+ "font-weight" => "bold",
28
+ "font-size" => "12px",
29
+ "padding" => "2px 4px"
30
+ }
31
+ }[tag]
6
32
  end
7
33
  end
8
34
  end
9
- end
35
+ end
@@ -11,23 +11,15 @@
11
11
  margin: 0;
12
12
  padding: 15px;
13
13
  color: #c52f24;
14
- font-weight: bold;
15
- font-size: 12px;
16
- font-family: Menlo, Consolas, Ubuntu, monospace;
17
14
  background: #f5f8fa;
18
15
  }
19
16
 
20
- .container {
21
- width: 100%;
22
- }
23
-
24
17
  pre {
25
- white-space: pre-wrap;
18
+ border: 0 !important;
26
19
  }
27
20
 
28
- kbd {
29
- background: none;
30
- shadow: none;
21
+ .container {
22
+ width: 100%;
31
23
  }
32
24
  </style>
33
25
  </head>
@@ -36,4 +28,4 @@
36
28
  <%= @exception.message %>
37
29
  </div>
38
30
  </body>
39
- </html>
31
+ </html>
@@ -1,7 +1,3 @@
1
- require_relative 'gem_version'
2
-
3
1
  module DebugExtras
4
- def self.version
5
- gem_version
6
- end
2
+ VERSION = "0.3.0"
7
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Avgustov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-05 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,15 +122,15 @@ files:
122
122
  - Rakefile
123
123
  - debug-extras.gemspec
124
124
  - lib/debug-extras.rb
125
- - lib/debug_extras/core_ext/object.rb
126
- - lib/debug_extras/error_page.rb
125
+ - lib/debug_extras/core_ext/kernel.rb
126
+ - lib/debug_extras/debug_page.rb
127
+ - lib/debug_extras/dumper.rb
127
128
  - lib/debug_extras/exceptions.rb
128
- - lib/debug_extras/gem_version.rb
129
129
  - lib/debug_extras/helpers/view_helpers.rb
130
130
  - lib/debug_extras/middleware.rb
131
131
  - lib/debug_extras/railtie.rb
132
132
  - lib/debug_extras/settings.rb
133
- - lib/debug_extras/templates/main.html.erb
133
+ - lib/debug_extras/templates/debug.html.erb
134
134
  - lib/debug_extras/version.rb
135
135
  homepage: https://github.com/vavgustov/debug-extras
136
136
  licenses:
@@ -1,11 +0,0 @@
1
- require 'debug_extras/exceptions'
2
-
3
- class Object
4
- def dd(message, settings = {})
5
- prefix = message.class.to_s
6
- prefix << "##{message.length}" if message.respond_to? :length
7
- settings.merge! DebugExtras::Settings.ap_options
8
- output = prefix + message.ai(settings)
9
- raise DebugExtras::DebugData.new(output)
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- module DebugExtras
2
- def self.gem_version
3
- Gem::Version.new VERSION::STRING
4
- end
5
-
6
- module VERSION
7
- MAJOR = 0
8
- MINOR = 2
9
- TINY = 0
10
-
11
- STRING = [MAJOR, MINOR, TINY].compact.join('.')
12
- end
13
- end