indent 1.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.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/indent.gemspec +20 -0
  4. data/lib/indent.rb +30 -0
  5. data/license.txt +1 -0
  6. data/readme.md +46 -0
  7. metadata +49 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d055d2fab6e008e0177a915a66ab7ccec2c10c5d
4
+ data.tar.gz: da23bedadf78a94d444c61bdc7eb47b09baeaa3d
5
+ SHA512:
6
+ metadata.gz: 29a0f0ea878bd9573a60535af758aa7d02bc7ebb9394decaa131bd26a9a4fc5cc389a5032fc26076d8025e24a42b72156a55d9e2f91a149a2d0809491e63c022
7
+ data.tar.gz: 388d7429de2cd277ab5fa5cb74992f9fa0d932ddd74ccd1816b2f7b40e310e48353ef6ef789bd4ab06627644b0878cc604563a05f407581a17538fc39bac480a
@@ -0,0 +1,37 @@
1
+ # OSX
2
+ .DS_Store
3
+ .AppleDouble
4
+ .LSOverride
5
+ ._*
6
+ .tmp
7
+
8
+ # Linux
9
+ .directory
10
+ *~
11
+
12
+ # Windows
13
+ Thumbs.db
14
+ ehthumbs.db
15
+ Desktop.ini
16
+ $RECYCLE.BIN/
17
+ *.cab
18
+ *.msi
19
+ *.msm
20
+ *.msp
21
+
22
+ # Ruby
23
+ /tmp/
24
+ /spec/reports/
25
+ /spec/tmp/
26
+ /doc/
27
+ /rdoc/
28
+ /server/log/
29
+ Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+ .rspec
33
+ *.gem
34
+
35
+ # Sublime Text
36
+ *.sublime-workspace
37
+ *.sublime-project
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "indent"
3
+ s.version = "1.0"
4
+ s.date = "2014-05-10"
5
+ s.platform = Gem::Platform::RUBY
6
+ s.description = "A small library for all things indentation."
7
+ s.summary = s.description
8
+ s.homepage = "https://github.com/adammcarthur/indent"
9
+ s.license = "MIT"
10
+
11
+ s.authors = ["Adam McArthur"]
12
+ s.email = ["adam@adammcarthur.net"]
13
+
14
+ s.files = `git ls-files`.split($/)
15
+ s.require_paths = ["lib"]
16
+
17
+ s.required_ruby_version = ">= 1.0.0"
18
+
19
+ s.post_install_message = "[Indent] Confucius say: <%= yield.code_indent(4) %>"
20
+ end
@@ -0,0 +1,30 @@
1
+ class String
2
+ # Simply indents a string using normal spaces
3
+ def indent(spaces)
4
+ num = (" " * spaces)
5
+ gsub(/^/, num)
6
+ end
7
+
8
+ # Pushes each line of code out the requried number of spaces (excludes the first line)
9
+ def code_indent(spaces)
10
+ num = (" " * spaces)
11
+ if include? "\n"
12
+ first_line = split(/\r?\n/)[0]
13
+ no_first_line = split("\n")[1..-1].join("\n")
14
+ formatted = no_first_line.gsub(/^/, num)
15
+ [first_line.to_s, formatted.to_s].join("\n")
16
+ else
17
+ self
18
+ end
19
+ end
20
+
21
+ # Poor man's way to quickly add whitespace > 1 space in html (for those who can't be bothered with padding)
22
+ def html_indent(spaces)
23
+ space_string = String.new
24
+ spaces.times do
25
+ space_string += "&nbsp;"
26
+ end
27
+
28
+ return self.insert(0, space_string)
29
+ end
30
+ end
@@ -0,0 +1 @@
1
+ Please take it
@@ -0,0 +1,46 @@
1
+ # Indent [![Gem Version](https://badge.fury.io/rb/indent.svg)](https://rubygems.org/gems/indent)
2
+
3
+ ``` ruby
4
+ require "indent"
5
+ ```
6
+
7
+ **indent(spaces)**
8
+
9
+ ``` ruby
10
+ "Hello, world!".indent(5)
11
+
12
+ #=> " Hello, world!"
13
+ ```
14
+
15
+ **code_indent(spaces)**
16
+
17
+ ``` ruby
18
+ "<h1>Hey.</h1>\n<p>I'm Adam!</p>\n<a>Follow me...</a>".code_indent(4)
19
+
20
+ #=> "<h1>Hey.</h1>\n <p>I'm Adam!</p>\n <a>Follow me...</a>"
21
+ ```
22
+ ``` erb
23
+ <html>
24
+ <body>
25
+ <%= yield.code_indent(4) %>
26
+ </body>
27
+ </html>
28
+
29
+ ...
30
+
31
+ <html>
32
+ <body>
33
+ <h1>Hey.</h1>
34
+ <p>I'm Adam!</p>
35
+ <a>Follow me..</a>
36
+ </body>
37
+ </html>
38
+ ```
39
+
40
+ **html_indent(spaces)**
41
+
42
+ ``` ruby
43
+ "whitespace_to_my_left".html_indent(2)
44
+
45
+ #=> "&nbsp;&nbsp;whitespace_to_my_left"
46
+ ```
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: indent
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Adam McArthur
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A small library for all things indentation.
14
+ email:
15
+ - adam@adammcarthur.net
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - indent.gemspec
22
+ - lib/indent.rb
23
+ - license.txt
24
+ - readme.md
25
+ homepage: https://github.com/adammcarthur/indent
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message: "[Indent] Confucius say: <%= yield.code_indent(4) %>"
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.0
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.2.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: A small library for all things indentation.
49
+ test_files: []