ripl-auto_indent 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems' unless defined? Gem
3
+ require File.dirname(__FILE__) + "/lib/ripl/auto_indent"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ripl-auto_indent"
7
+ s.version = Ripl::AutoIndent::VERSION
8
+ s.authors = ["Jan Lelis"]
9
+ s.email = "mail@janlelis.de"
10
+ s.homepage = "http://github.com/janlelis/ripl-auto_indent"
11
+ s.summary = "A ripl plugin which indents your entered Ruby code."
12
+ s.description = "This ripl plugin indents your multi-line Ruby input using coderay."
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+ s.add_dependency 'ripl', '>= 0.2.5'
15
+ s.add_dependency 'ripl-multi_line', '>= 0.1.4'
16
+ s.add_dependency 'coderay', '~> 0.9'
17
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
18
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
19
+ s.license = 'MIT'
20
+ end
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ == 0.1.0
2
+ * Initial release.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT LICENSE
2
+
3
+ Copyright (c) 2010 Jan Lelis
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.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ == Description
2
+ A {ripl}[http://github.com/cldwalker/ripl] plugin that indents your entered Ruby code.
3
+
4
+ == Install
5
+ Install the gem with
6
+
7
+ gem install ripl-auto_indent
8
+
9
+ == Usage
10
+
11
+ Add the following line to your <tt>~/.riplrc</tt>
12
+
13
+ require 'ripl/auto_indent'
14
+
15
+ == Configuration options
16
+
17
+ The plugin rewrites the last line (if the there are closing elements). If this is too buggy for you or your terminal does not support it, you can deactivate it with <tt>Ripl.config[:auto_indent_rewrite] = false</tt>.
18
+ You can change the default two spaces used for indention (per level) with <tt>Ripl.config[:auto_indent_space]</tt>.
19
+
20
+ J-_-L
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'rake'
2
+ require 'fileutils'
3
+
4
+ def gemspec
5
+ @gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
6
+ end
7
+
8
+ desc "Build the gem"
9
+ task :gem=>:gemspec do
10
+ sh "gem build .gemspec"
11
+ FileUtils.mkdir_p 'pkg'
12
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
13
+ end
14
+
15
+ desc "Install the gem locally"
16
+ task :install => :gem do
17
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
18
+ end
19
+
20
+ desc "Generate the gemspec"
21
+ task :generate do
22
+ puts gemspec.to_ruby
23
+ end
24
+
25
+ desc "Validate the gemspec"
26
+ task :gemspec do
27
+ gemspec.validate
28
+ end
29
+
30
+ desc 'Run tests'
31
+ task :test do |t|
32
+ sh 'bacon -q -Ilib -I. test/*_test.rb'
33
+ end
34
+
35
+ task :default => :test
data/deps.rip ADDED
@@ -0,0 +1,3 @@
1
+ ripl >=0.2.5
2
+ ripl-multi_line >=0.1.4
3
+ coderay >=0.9.5
@@ -0,0 +1,73 @@
1
+ require 'ripl'
2
+ require 'ripl/multi_line'
3
+ require 'coderay'
4
+
5
+ module Ripl
6
+ module AutoIndent
7
+ VERSION = '0.1.0'
8
+ TPUT = {
9
+ :sc => `tput sc`, # save current cursor position
10
+ :cuu1 => `tput cuu1`, # move cursor upwards to the original input line
11
+ :cuf1 => `tput cuf1`, # move cursor rightwards to the original input offset
12
+ :rc => `tput rc`, # return to normal cursor position
13
+ }
14
+
15
+ def before_loop
16
+ super
17
+ @current_indent = 0
18
+ end
19
+
20
+ def get_indent(buffer)
21
+ indent = 0
22
+ opening_tokens = %w[begin case class def for if module unless until while do {]
23
+ closing_tokens = %w[end }]
24
+ # parse each token
25
+ buffer_tokens = CodeRay.scan(buffer, :ruby)
26
+ buffer_tokens.each{ |token, kind|
27
+ if kind == :reserved || kind == :operator
28
+ if opening_tokens.include? token
29
+ indent += 1
30
+ elsif closing_tokens.include? token
31
+ indent -= 1
32
+ end
33
+ end
34
+ }
35
+ # return a good value
36
+ indent < 0 ? 0 : indent
37
+ end
38
+
39
+ def prompt
40
+ @buffer ? config[:multi_line_prompt] + config[:auto_indent_space]*@current_indent : super
41
+ end
42
+
43
+ def rewrite_line(append_indents = 0)
44
+ print TPUT[:sc] +
45
+ TPUT[:cuu1] +
46
+ prompt +
47
+ @input +
48
+ config[:auto_indent_space]*append_indents +
49
+ TPUT[:rc]
50
+ end
51
+
52
+ def eval_input(input)
53
+ last_indent = @current_indent
54
+ @current_indent = get_indent(@buffer ? @buffer + input : input)
55
+
56
+ if config[:auto_indent_rewrite] && @current_indent < last_indent
57
+ rewrite_line last_indent - @current_indent
58
+ end
59
+
60
+ super # (@buffer ? @buffer + input : input)
61
+ end
62
+ end
63
+ end
64
+
65
+ Ripl::Shell.send :include, Ripl::AutoIndent
66
+
67
+ # default config
68
+ Ripl.config[:auto_indent_rewrite] = true
69
+ Ripl.config[:auto_indent_space] = ' '
70
+ Ripl.config[:multi_line_prompt] = '| ' if !Ripl.config[:multi_line_prompt] ||
71
+ Ripl.config[:multi_line_prompt] == '| '
72
+
73
+ # J-_-L
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ripl-auto_indent
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Jan Lelis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-30 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ripl
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 2
31
+ - 5
32
+ version: 0.2.5
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: ripl-multi_line
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 1
46
+ - 4
47
+ version: 0.1.4
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: coderay
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 9
61
+ version: "0.9"
62
+ type: :runtime
63
+ version_requirements: *id003
64
+ description: This ripl plugin indents your multi-line Ruby input using coderay.
65
+ email: mail@janlelis.de
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files:
71
+ - README.rdoc
72
+ - LICENSE.txt
73
+ files:
74
+ - lib/ripl/auto_indent.rb
75
+ - LICENSE.txt
76
+ - README.rdoc
77
+ - CHANGELOG.rdoc
78
+ - deps.rip
79
+ - Rakefile
80
+ - .gemspec
81
+ has_rdoc: true
82
+ homepage: http://github.com/janlelis/ripl-auto_indent
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 1
105
+ - 3
106
+ - 6
107
+ version: 1.3.6
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: A ripl plugin which indents your entered Ruby code.
115
+ test_files: []
116
+