icepick 0.1.0 → 0.2.0

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: 2e343f6537242c146ed5d951e057ae678f733db8
4
- data.tar.gz: 849eb3d592b8028f2490087604e7071c08530dd9
3
+ metadata.gz: ad1c12a8b27ae80252b65e9d40d4837475c46188
4
+ data.tar.gz: 9d881759f66b7e97e0242c34cf5c4e03ec56ba55
5
5
  SHA512:
6
- metadata.gz: ca20aa14b444682be29e63d21de405ffe105250038fd90e1fade279f1fab24f65f45ef7677900d145edbf1f0fcae21baba30fc738c89bfcea3ba8d42b9387bc3
7
- data.tar.gz: cc945c42d5513d87349d1cce5906e117967ba7351031041ed1714fd13271c260baeaf1621a24fc3cae6ac6804918addd0bf0d6a4aa4fe18ff9f60e7e1a0c2852
6
+ metadata.gz: 4720363a7892653fb14db609cf9d710b3333e28783d2d1ee86f374ab4d62caf486554c26bfc9dc51712cac3bf06fa9ad6d7f8667d92ae917adb77336947f3357
7
+ data.tar.gz: 18a2989fbd19a76611fa830c20d5d61bd4158febe8aa4c466e055c4b275447945e646423350f88b67942a16e7a5321c6d5e919cf3f6c6ae223520e448068d37b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
+ ## 0.2.0 (2014-01-01)
2
+
3
+ * Prompt layout now more configurable. Added a new dependency on [colorize][colorize].
4
+
1
5
  ## 0.1.0 (2013-12-31)
2
6
 
3
- * First and last release of the year. Bundle [pry]() with [pry-doc](), [pry-debugger](), [pry-stack_explorer](), and [pry-rails](). [Awesome print](awesome_print) for colorized and formatted output. Configured as Rails' console when applicable.
7
+ * First and last release of the year. Bundle [pry][pry] with [pry-doc][pry-doc], [pry-debugger][pry-debugger], [pry-stack_explorer][pry-stack_explorer], and [pry-rails][pry-rails]. [Awesome print][awesome_print] for colorized and formatted output. Configured as Rails' console when applicable.
4
8
 
5
9
  [pry]: http://pry.github.com
6
10
  [pry-doc]: https://github.com/pry/pry-doc
@@ -9,3 +13,4 @@
9
13
  [pry-byebug]: https://github.com/deivid-rodriguez/pry-byebug
10
14
  [pry-rails]: https://github.com/rweng/pry-rails
11
15
  [awesome_print]: https://github.com/michaeldv/awesome_print
16
+ [colorized]: https://github.com/fazibear/colorize
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- icepick (0.1.0)
4
+ icepick (0.2.0)
5
5
  awesome_print (~> 1.2)
6
+ colorize (~> 0.6.0)
6
7
  pry (~> 0.9.12)
7
8
  pry-debugger (~> 0.2.2)
8
9
  pry-doc (~> 0.4.6)
@@ -31,6 +32,7 @@ GEM
31
32
  debug_inspector (>= 0.0.1)
32
33
  builder (3.1.4)
33
34
  coderay (1.1.0)
35
+ colorize (0.6.0)
34
36
  columnize (0.3.6)
35
37
  debug_inspector (0.0.2)
36
38
  debugger (1.6.5)
data/README.md CHANGED
@@ -1,27 +1,72 @@
1
1
  Icepick
2
2
  =======
3
+ © {[doomspork](https://github.com/doomspork)} 2014
3
4
 
4
- __Icepick__ bundles Pry with a set of plugins and useful configuration:
5
+ Current version is `0.2.0` [Changelog][changelog].
5
6
 
6
- * [Pry](pry) is a better alternative to IRB
7
- * [Pry Doc](pry-doc) includes documentation and source for Code Ruby components
8
- * [Pry Debugger](pry-debugger) is a powerful debugger for Pry
9
- * [Pry Stack Explorer](pry-stack_explorer) includes support for call stack navigation
10
- * [Pry Rails](pry-rails) adds Rails helpers to Pry like `show-routes` and `show-models`
11
- * [Awesome Print](awesome_print) colorizes and formats output
7
+ __Icepick__ bundles a set of useful tools, plugins, and configurations together:
12
8
 
13
- ##Usage
9
+ * [Pry][pry] is a powerful alternative to IRB
10
+ * [Pry Doc][pry-doc] includes documentation and source for Core Ruby components
11
+ * [Pry Debugger][pry-debugger] brings the power of debugger to Pry
12
+ * [Pry Stack Explorer][pry-stack_explorer] adds support for call stack navigation
13
+ * [Pry Rails][pry-rails] adds Rails helpers to Pry like `show-routes` and `show-models`
14
+ * [Awesome Print][awesome_print] colorizes and formats output
14
15
 
15
- Ruby 1.9.2+ only, support for Rails 3 and Rails 4. Add the following to your project's Gemfile:
16
+ Ruby 1.9.2+ only. Support included for Rails 3 and Rails 4.
17
+
18
+ ## Usage
19
+
20
+ Install the gem and run `icepick` or `rails console` as you normally would.
21
+
22
+ ## Options
23
+
24
+ The following options can be changed with a Rails initializer. Example `config/initializers/icepick.rb`:
16
25
 
17
26
  ```ruby
18
- group :development, :test do
19
- gem 'icepick'
27
+ if defined?(Icepick)
28
+ # Change the name to something moar awesomer
29
+ Icepick::Prompt.config.name = 'Iceaxe'
30
+ # Make the layout look more like plain Pry
31
+ Icepick::Prompt.config.main_layout = '[{line_num}] {name}({context}) {separator} '
20
32
  end
21
33
  ```
34
+ ------
35
+ ### `name`
36
+
37
+ Configures the prompt name, defaults to `Icepick`
38
+
39
+ ### `separator`
40
+
41
+ Change the prompt separator to something other than the default: `>`
42
+
43
+ ### `formatted`
44
+
45
+ Color and format the prompt, defaults to `true`
46
+
47
+ ### `main_layout`
48
+
49
+ Allows you to configure the layout for the main Pry prompt, defaults to `'{line_num}. {name}@{context} {separator} '`. The following placeholders are available for use in the layout:
50
+
51
+ * `name` - The prompt name
52
+ * `line_num` - Current line number, the Pry input array size
53
+ * `context` - Path of the current context (eg. `cd Pry::CommandSet` #=> `/Pry/CommandSet`)
54
+ * `separator` - Prompt separator
55
+
56
+ ### `wait_layout`
57
+
58
+ Configuration for the Pry wait prompt, defaults to `'{spaces} {separator} '`. In addition to the above placeholders, there are a few available exclusively to the wait prompt:
59
+
60
+ * `spaces` - String of spaces equal to the length to the main prompt without the separator
61
+ * `dots` - Similar to the above but dots
62
+
63
+ ## Contributions
22
64
 
23
- Now you're ready! Just run `pry` or `rails console` as you normally would.
65
+ Feel free to open [Issues][issues] or submit [Pull Requests][pullrequest] for consideration.
24
66
 
67
+ [issues]: https://github.com/doomspork/icepick/issues
68
+ [pullrequest]: https://github.com/doomspork/icepick/pulls
69
+ [changelog]: https://github.com/doomspork/icepick/blob/master/CHANGELOG.md
25
70
  [pry]: http://pry.github.com
26
71
  [pry-doc]: https://github.com/pry/pry-doc
27
72
  [pry-stack_explorer]: https://github.com/pry/pry-stack_explorer
data/icepick.gemspec CHANGED
@@ -18,11 +18,12 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  # Dependencies
20
20
  gem.required_ruby_version = '>= 1.9.2'
21
- gem.add_runtime_dependency 'pry', '~> 0.9.12'
22
- gem.add_runtime_dependency 'pry-doc', '~> 0.4.6'
23
- gem.add_runtime_dependency 'pry-rails', '~> 0.3.2'
24
- gem.add_runtime_dependency 'pry-stack_explorer', '~> 0.4.9'
25
- gem.add_runtime_dependency 'pry-debugger', '~> 0.2.2'
26
- gem.add_runtime_dependency 'awesome_print', '~> 1.2'
27
- gem.add_runtime_dependency 'railties', '>= 3.0', '< 5.0'
21
+ gem.add_runtime_dependency 'pry', '~> 0.9.12'
22
+ gem.add_runtime_dependency 'pry-doc', '~> 0.4.6'
23
+ gem.add_runtime_dependency 'pry-rails', '~> 0.3.2'
24
+ gem.add_runtime_dependency 'pry-stack_explorer', '~> 0.4.9'
25
+ gem.add_runtime_dependency 'pry-debugger', '~> 0.2.2'
26
+ gem.add_runtime_dependency 'colorize', '~> 0.6.0'
27
+ gem.add_runtime_dependency 'awesome_print', '~> 1.2'
28
+ gem.add_runtime_dependency 'railties', '>= 3.0', '< 5.0'
28
29
  end
data/lib/icepick.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'icepick/version'
2
+ require 'icepick/config'
3
+ require 'icepick/prompt'
2
4
 
3
5
  require 'pry'
4
6
  require 'pry-doc'
@@ -28,10 +30,10 @@ module Icepick
28
30
  # * name: A name to use for the prompt
29
31
  #
30
32
  # Returns nothing
31
- def self.initialize!(options = {})
33
+ def self.initialize!(name = nil)
32
34
  silence_warnings do
33
35
  # Set the prompt name, for the Railtie this is the application name
34
- Pry.config.prompt_name = options[:name] || 'icepick'
36
+ Prompt.config.name = name if name
35
37
 
36
38
  # Use awesome_print for Pry output
37
39
  Pry.config.print = ->(output, value) do
@@ -39,7 +41,11 @@ module Icepick
39
41
  Pry::Helpers::BaseHelpers.stagger_output("=> #{pretty}", output)
40
42
  end
41
43
 
42
- if defined?(PryDebugger) || defined?(PryByebug)
44
+ # Use Icepick's Prompt for Pry
45
+ Pry.config.prompt = [Prompt.main_prompt, Prompt.wait_prompt]
46
+
47
+ # Debugger shortcuts
48
+ if defined?(PryDebugger)
43
49
  Pry.commands.alias_command 'c', 'continue'
44
50
  Pry.commands.alias_command 's', 'step'
45
51
  Pry.commands.alias_command 'n', 'next'
@@ -50,13 +56,15 @@ module Icepick
50
56
 
51
57
  private
52
58
 
59
+ # Internal: Suppress warnings and errors
60
+ #
61
+ # Returns nothing
53
62
  def self.silence_warnings
54
63
  old_verbose, $VERBOSE = $VERBOSE, nil
55
64
  yield
56
65
  ensure
57
66
  $VERBOSE = old_verbose
58
67
  end
59
-
60
68
  end
61
69
 
62
70
  if defined?(Rails)
@@ -0,0 +1,27 @@
1
+ module Icepick
2
+ class Config
3
+ # Separator for the prompt
4
+ attr_accessor :separator
5
+
6
+ # Whether or not to use colors and formatting
7
+ attr_accessor :formatted
8
+ alias :formatted? :formatted
9
+
10
+ # The mustache compatiable layouts for Pry prompts
11
+ attr_accessor :main_layout, :wait_layout
12
+
13
+ # The prompt name
14
+ attr_accessor :name
15
+
16
+ # Public: Create a new instance of the config with defaults
17
+ #
18
+ # Returns a new instance
19
+ def initialize
20
+ self.separator = '>'
21
+ self.formatted = true
22
+ self.main_layout = '{line_num}. {name}@{context} {separator} '
23
+ self.wait_layout = '{spaces} {separator} '
24
+ self.name = 'Icepick'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,124 @@
1
+ require 'colorize'
2
+
3
+ module Icepick
4
+ class Prompt
5
+
6
+ class << self
7
+ # Pry prompt's target object
8
+ attr_accessor :target
9
+
10
+ # The nesting level of the current Pry
11
+ attr_accessor :level
12
+
13
+ # An instance of the current Pry session
14
+ attr_accessor :pry
15
+
16
+ # Our configuration instance
17
+ attr_accessor :config
18
+ end
19
+
20
+ # Initialize the configuration object
21
+ self.config = Icepick::Config.new
22
+
23
+ # Public: Piece together the main prompt
24
+ #
25
+ # Returns a Proc
26
+ def self.main_prompt
27
+ prompt_proc(config.main_layout)
28
+ end
29
+
30
+ # Public: Build out the wait prompt
31
+ #
32
+ # Returns a Proc
33
+ def self.wait_prompt
34
+ prompt_proc(config.wait_layout)
35
+ end
36
+
37
+ protected
38
+
39
+ # Internal: Build a prompt proc for a given layout
40
+ #
41
+ # layout - The layout to use in the proc
42
+ #
43
+ # Returns a Proc
44
+ def self.prompt_proc(layout)
45
+ proc do |target, level, pry|
46
+ self.target, self.level, self.pry = target, level, pry
47
+ interpolate_prompt(layout)
48
+ end
49
+ end
50
+
51
+ # Internal: A helper to handle the layout's config
52
+ #
53
+ # layout - the layout String
54
+ #
55
+ # Returns a String with interoplated values
56
+ def self.interpolate_prompt(layout)
57
+ code = layout.gsub(/{/, '#{self.')
58
+ eval(%Q{"#{code}"})
59
+ end
60
+
61
+ # Internal: A helper to retrieve the expected separator with or without formatting
62
+ #
63
+ # Returns the separator as a String
64
+ def self.separator
65
+ separator = config.separator
66
+ config.formatted ? separator.bold : separator
67
+ end
68
+
69
+ # Internal: Return the name with appropriate formatting
70
+ #
71
+ # Returns a String
72
+ def self.name
73
+ config.formatted? ? config.name.underline : config.name
74
+ end
75
+
76
+ # Internal: Helper for line number
77
+ #
78
+ # Returns the line number as String
79
+ def self.line_num
80
+ line = self.pry.input_array.size.to_s
81
+ config.formatted? ? line.bold : line
82
+ end
83
+
84
+ # Internal: Get the name of Pry's current context or target
85
+ #
86
+ # Returns a String
87
+ def self.context
88
+ unless (context = Pry.view_clip(target)) == 'main'
89
+ str = "#{context.gsub(/::/, '/')}"
90
+ config.formatted? ? str.colorize(:blue) : str
91
+ else
92
+ ''
93
+ end
94
+ end
95
+
96
+ # Internal: Get a String of spaces matching the main prompt
97
+ # in length
98
+ #
99
+ # Returns a String of spaces
100
+ def self.spaces
101
+ ' ' * prompt_size
102
+ end
103
+
104
+ # Internal: Produces a String of dots the lenght of the main prompt
105
+ #
106
+ # Returns a String of spaces
107
+ def self.dots
108
+ '.' * prompt_size
109
+ end
110
+
111
+ # Intennal: Determines the length of the formatless main prompt
112
+ #
113
+ # Returns an Integer
114
+ def self.prompt_size
115
+ old_setting = config.formatted?
116
+ config.formatted = false
117
+ prompt = main_prompt.call(self.target, self.level, self.pry)
118
+ config.formatted = old_setting
119
+ index = prompt.index(config.separator) - 2
120
+ prompt[0..index].length
121
+ end
122
+
123
+ end
124
+ end
@@ -1,7 +1,7 @@
1
1
  module Icepick
2
2
  class Railtie < Rails::Railtie
3
3
  initializer 'icepick.initialize' do |app|
4
- Icepick.initialize!({name: app.class.parent_name.underscore})
4
+ Icepick.initialize!(app.class.parent_name.underscore)
5
5
 
6
6
  silence_warnings do
7
7
  # Use Pry instead of IRB
@@ -1,3 +1,3 @@
1
1
  module Icepick
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icepick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Callan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-01 00:00:00.000000000 Z
11
+ date: 2014-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.2.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: colorize
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.6.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.6.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: awesome_print
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -130,9 +144,10 @@ files:
130
144
  - README.md
131
145
  - Rakefile
132
146
  - bin/icepick
133
- - ext/mkrf_conf.rb
134
147
  - icepick.gemspec
135
148
  - lib/icepick.rb
149
+ - lib/icepick/config.rb
150
+ - lib/icepick/prompt.rb
136
151
  - lib/icepick/railtie.rb
137
152
  - lib/icepick/version.rb
138
153
  homepage: https://github.com/doomspork/icepick
data/ext/mkrf_conf.rb DELETED
@@ -1,17 +0,0 @@
1
- require 'rubygems/dependency_installer.rb'
2
-
3
- #Load up the rubygem's dependency installer to
4
- #installer the gems we want based on the version
5
- #of Ruby the user has installed
6
- installer = Gem::DependencyInstaller.new
7
- begin
8
- if RUBY_VERSION > '1.9'
9
- installer.install 'pry-byebug', '~> 1.2.1'
10
- else
11
- installer.install 'pry-debugger', '~> 0.2.2'
12
- end
13
-
14
- rescue
15
- #Exit with a non-zero value to let rubygems something went wrong
16
- exit(1)
17
- end