unindent-1.0/0000755000175000017500000000000012745112313012221 5ustar pravipraviunindent-1.0/README.md0000644000175000017500000000073112745112313013501 0ustar pravipravi### Summary Simple Ruby method, `String#unindent`, to unindent strings. Useful for multi-line strings embeded in already indented code. ### Examples ```ruby class Profile def default_text <<-STR Anonymous Coward - Community Guest STR end end puts Profile.new.default_text # Anonymous Coward # - Community Guest puts Profile.new.default_text.unindent #Anonymous Coward # - Community Guest ``` ### Install `gem install unindent` unindent-1.0/lib/0000755000175000017500000000000012745112313012767 5ustar pravipraviunindent-1.0/lib/unindent.rb0000644000175000017500000000037612745112313015146 0ustar pravipraviclass String def unindent indent = self.split("\n").select {|line| !line.strip.empty? }.map {|line| line.index(/[^\s]/) }.compact.min || 0 self.gsub(/^[[:blank:]]{#{indent}}/, '') end def unindent! self.replace(self.unindent) end end unindent-1.0/.gitignore0000644000175000017500000000000612745112313014205 0ustar pravipravi*.gem unindent-1.0/LICENSE0000644000175000017500000000205212745112313013225 0ustar pravipraviCopyright © 2009 Martin Aumont (mynyml) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. unindent-1.0/Manifest0000644000175000017500000000022312745112313013707 0ustar pravipravi.gitignore LICENSE Manifest README.md Rakefile examples.rb lib/unindent.rb specs.watchr test/test_helper.rb test/test_unindent.rb unindent.gemspec unindent-1.0/Rakefile0000644000175000017500000000200612745112313013664 0ustar pravipravidef gem_opt defined?(Gem) ? "-rubygems" : "" end # -------------------------------------------------- # Tests # -------------------------------------------------- task(:default => :'test:all') namespace(:test) do desc "Run tests" task(:all) do exit system("ruby #{gem_opt} -I.:lib test/test_unindent.rb") end desc "Run tests on multiple ruby versions (requires rvm)" task(:portability) do versions = %w( 1.8.6 1.8.7 1.9 1.9.2 ) versions.each do |version| system <<-BASH bash -c 'source ~/.rvm/scripts/rvm; rvm use #{version}; echo "--------- #{version} ----------"; rake -s test:all' BASH end end end # -------------------------------------------------- # Docs # -------------------------------------------------- desc "Generate YARD Documentation" task(:yardoc) do require 'yard' files = %w( lib/**/*.rb ) options = %w( -o doc/yard --readme README --files LICENSE ) YARD::CLI::Yardoc.run *(options + files) end unindent-1.0/unindent.gemspec0000644000175000017500000000120212745112313015405 0ustar pravipraviGem::Specification.new do |s| s.name = "unindent" s.version = "1.0" s.summary = "Ruby method to unindent strings." s.description = "Ruby method to unindent strings. Useful for multiline strings embeded in already indented code." s.author = "mynyml" s.email = "mynyml@gmail.com" s.homepage = "http://github.com/mynyml/unindent" s.rubyforge_project = "unindent" s.has_rdoc = false s.require_path = "lib" s.files = File.read("Manifest").strip.split("\n") s.add_development_dependency 'nanotest' end unindent-1.0/test/0000755000175000017500000000000012745112313013200 5ustar pravipraviunindent-1.0/test/test_unindent.rb0000644000175000017500000000137512745112313016416 0ustar pravipravirequire 'test/test_helper' ## simple indentation assert { "\s\sabc" .unindent == "abc" } # removes space indentation assert { "\tabc" .unindent == "abc" } # removes tab indentation assert { "\t\s\sabc".unindent == "abc" } # removes space/tab indentation assert { "" .unindent == "" } # handles empty strings ## multi-line indentation assert { "\tabc\n\tabc" .unindent == "abc\nabc" } # removes space/tab indentation assert { "\tabc\n\t\tabc" .unindent == "abc\n\tabc" } # keeps relative indentation assert { "\n\tabc\n\n\t\tabc\n".unindent == "\nabc\n\n\tabc\n" } # ignores blank lines for indent calculation ## unindent! # test: modifies string in place source = "\s\sabc" source.unindent! assert { source == "abc" } unindent-1.0/test/test_helper.rb0000644000175000017500000000044012745112313016041 0ustar pravipravirequire 'nanotest' begin require 'ruby-debug' require 'redgreen' # gem: mynyml-redgreen require 'nanotest/focus' # gem: nanotest_extensions require 'nanotest/stats' # gem: nanotest_extensions rescue LoadError, RuntimeError # pass end require 'unindent' include Nanotest unindent-1.0/examples.rb0000644000175000017500000000054112745112313014364 0ustar pravipravirequire 'pathname' require Pathname(__FILE__).dirname.parent + 'lib/unindent' class Profile def default_text <<-STR Anonymous Coward - Community Guest STR end end puts Profile.new.default_text # Anonymous Coward # - Community Guest puts Profile.new.default_text.unindent #Anonymous Coward # - Community Guest unindent-1.0/specs.watchr0000644000175000017500000000110712745112313014547 0ustar pravipravi# Run me with: # $ watchr specs.watchr # -------------------------------------------------- # Watchr Rules # -------------------------------------------------- watch( '^(lib|test)/.*\.rb' ) { rake } # -------------------------------------------------- # Signal Handling # -------------------------------------------------- Signal.trap('QUIT') { rake } # Ctrl-\ Signal.trap('INT' ) { abort("\n") } # Ctrl-C # -------------------------------------------------- # Helpers # -------------------------------------------------- def rake(task='') system "rake -s #{task}" end