sass-align 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ /doc/roff
3
+ /doc/man
4
+ /tmp
5
+
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ task :default => "man:all"
2
+
3
+ directory "tmp"
4
+
5
+ task :gem => "tmp" do
6
+ sh "gem build sass-align.gemspec"
7
+ sh "mv sass-align-*.gem tmp"
8
+ end
9
+
10
+ begin
11
+ require "ronn"
12
+
13
+ namespace :man do
14
+ basename = "README"
15
+ ronn = "doc/ronn/#{basename}.ronn"
16
+ roff = "doc/roff/#{basename}"
17
+ man = "doc/man/#{basename}.txt"
18
+
19
+ directory "doc/roff"
20
+ directory "doc/man"
21
+
22
+ file roff => [ronn, "doc/roff"] do
23
+ sh "ronn --roff --pipe #{ronn} > #{roff}"
24
+ end
25
+
26
+ file man => [roff, "doc/man"] do
27
+ sh "groff -Wall -mandoc -Tascii #{roff} > #{man}"
28
+ end
29
+
30
+ task :all => [man]
31
+ end
32
+ rescue LoadError
33
+ $stderr.puts "Install ronn to build man page"
34
+ end
35
+
data/bin/sass-align ADDED
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'stringio'
5
+
6
+ read_from_stdin = false
7
+ edit_in_place = false
8
+ recursive = false
9
+
10
+ options = {
11
+ :offset => 30
12
+ }
13
+
14
+ opts = OptionParser.new do |opts|
15
+ opts.banner = <<EOB
16
+ Usage: sass-align [options] [FILES...]
17
+
18
+ Run 'sass-align --help' for more information.
19
+
20
+ EOB
21
+
22
+ opts.on '-s', '--stdin', 'Read input from standard input instead of an input file' do |v|
23
+ read_from_stdin = true
24
+ end
25
+
26
+ opts.on '-e', '--edit-in-place', "Edit files in place. Make sure you've backed them up (preferably using version control)." do |v|
27
+ edit_in_place = true
28
+ end
29
+
30
+ opts.on '-R', '--recursive', "Format all the files in a directory. Implies the `-e' flag." do |v|
31
+ recursive = true
32
+ end
33
+
34
+ opts.on '-o N', '--offset N', Integer, "Specify left character offset for property values (default 30)" do |v|
35
+ options[:offset] = v
36
+ end
37
+
38
+ opts.on '-h', '--help', 'Display man page' do
39
+ system "less", File.expand_path('../../doc/man/README.txt', __FILE__)
40
+ exit
41
+ end
42
+ end
43
+
44
+ begin
45
+ opts.parse!
46
+ rescue OptionParser::ParseError => e
47
+ $stderr.puts e
48
+ $stderr.puts
49
+ $stderr.puts opts
50
+ exit -1
51
+ end
52
+
53
+ if read_from_stdin and (edit_in_place or recursive)
54
+ $stderr.puts "`--stdin' cannot be combined with `--edit-in-place' or `--recursive'."
55
+ exit -1
56
+ end
57
+
58
+ def format(input, output, options)
59
+ input = File.open(input) if input.is_a?(String)
60
+ output = File.open(output, 'w') if output.is_a?(String)
61
+
62
+ while line = input.gets
63
+ if match = line.match(/^(\s*)(@extend|:[a-z\-]+|[a-z\-]+:)(\s+)(?=\S)(.+?)(\s*)$/)
64
+ offset = options[:offset]
65
+ offset -= 1 if ['-', '.'].include?(match[4][0..0])
66
+
67
+ left = (match[1] + match[2]).ljust(offset-1)
68
+ right = match[4]
69
+
70
+ output.puts(left + " " + right)
71
+ else
72
+ output.puts(line)
73
+ end
74
+ end
75
+ rescue
76
+ input.close_read if input.respond_to?(:close_read)
77
+ output.close_write if output.respond_to?(:close_write)
78
+ raise
79
+ end
80
+
81
+ def format_in_place(path, options)
82
+ output = StringIO.new
83
+ format(path, output, options)
84
+ File.open(path, 'w') { |f| f.write(output.string) }
85
+ end
86
+
87
+ if recursive
88
+ dir = ARGV.shift
89
+
90
+ unless File.directory?(dir)
91
+ $stderr.puts "Not a directory: #{dir}"
92
+ exit -1
93
+ end
94
+
95
+ Dir.glob(File.join(dir, "**/*.sass")).each do |path|
96
+ format_in_place(path, options)
97
+ $stderr.puts "formatted #{path}"
98
+ end
99
+ elsif edit_in_place
100
+ ARGV.each do |path|
101
+ format_in_place(path, options)
102
+ end
103
+ else
104
+ input = if read_from_stdin
105
+ STDIN
106
+ elsif ARGV.any?
107
+ ARGV.shift
108
+ else
109
+ $stderr.puts opts
110
+ exit -1
111
+ end
112
+
113
+ output = if ARGV.any?
114
+ ARGV.shift
115
+ else
116
+ STDOUT
117
+ end
118
+
119
+ format(input, output, options)
120
+ end
121
+
@@ -0,0 +1,52 @@
1
+ SASS-ALIGN(1) SASS-ALIGN(1)
2
+
3
+
4
+
5
+ NNAAMMEE
6
+ ssaassss--aalliiggnn - nicely align property values in .sass files
7
+
8
+ SSyynnooppssiiss
9
+ ssaassss--aalliiggnn _f_i_l_e _f_i_l_e
10
+ ssaassss--aalliiggnn --ss|----ssttddiinn [_f_i_l_e]
11
+ ssaassss--aalliiggnn --ee|----eeddiitt--iinn--ppllaaccee _f_i_l_e...
12
+ ssaassss--aalliiggnn --RR|----rreeccuurrssiivvee _d_i_r_e_c_t_o_r_y
13
+
14
+ DDeessccrriippttiioonn
15
+ sass-align is a command-line tool to format .sass files in the mildly
16
+ idiosyncratic style used at Unspace _h_t_t_p_:_/_/_u_n_s_p_a_c_e_._c_a. That means:
17
+
18
+ 1. All property values and arguments to @@eexxtteenndd calls are placed at an
19
+ (at least) 30-character left offset.
20
+
21
+ 2. Unless they start with a -- (e.g. lleefftt:: --3300ppxx) or a .. (e.g. @@eexxtteenndd
22
+ ..bbuuttttoonn), in which case they're shifted left 1 character.
23
+
24
+
25
+
26
+ FFoorrmmaatt eexxaammppllee
27
+ #wrapper
28
+ .sidebar
29
+ :border-top 8px solid black
30
+ :margin-right -100px
31
+ .content
32
+ :width 500px
33
+ @extend .helvetica
34
+
35
+ OOppttiioonnss
36
+ --ss, ----ssttddiinn
37
+ Read input from standard input instead of an input file.
38
+
39
+ --ee, ----eeddiitt--iinn--ppllaaccee
40
+ Edit files in place. Make sure you've backed them up (preferably
41
+ using version control).
42
+
43
+ --RR, ----rreeccuurrssiivvee
44
+ Format all the files in a directory. Implies the `-e' flag.
45
+
46
+ --oo NN, ----ooffffsseett NN
47
+ Specify left character offset for property values (default 30).
48
+
49
+
50
+
51
+
52
+ September 2011 SASS-ALIGN(1)
@@ -0,0 +1,41 @@
1
+ sass-align(1) -- nicely align property values in .sass files
2
+ =============================================================
3
+
4
+ ## Synopsis
5
+
6
+ `sass-align` <file> <file><br>
7
+ `sass-align` `-s`|`--stdin` [<file>]<br>
8
+ `sass-align` `-e`|`--edit-in-place` <file>...<br>
9
+ `sass-align` `-R`|`--recursive` <directory>
10
+
11
+ ## Description
12
+
13
+ sass-align is a command-line tool to format .sass files in the mildly idiosyncratic style used at [Unspace](http://unspace.ca). That means:
14
+
15
+ 1. All property values and arguments to `@extend` calls are placed at an (at least) 30-character left offset.
16
+ 2. Unless they start with a `-` (e.g. `left: -30px`) or a `.` (e.g. `@extend .button`), in which case they're shifted left 1 character.
17
+
18
+ ## Format example
19
+
20
+ #wrapper
21
+ .sidebar
22
+ :border-top 8px solid black
23
+ :margin-right -100px
24
+ .content
25
+ :width 500px
26
+ @extend .helvetica
27
+
28
+ ## Options
29
+
30
+ * `-s`, `--stdin`:
31
+ Read input from standard input instead of an input file.
32
+
33
+ * `-e`, `--edit-in-place`:
34
+ Edit files in place. Make sure you've backed them up (preferably using version control).
35
+
36
+ * `-R`, `--recursive`:
37
+ Format all the files in a directory. Implies the `-e' flag.
38
+
39
+ * `-o N`, `--offset N`:
40
+ Specify left character offset for property values (default 30).
41
+
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "sass-align"
3
+ s.version = "0.1.0"
4
+ s.authors = ["Aanand Prasad"]
5
+ s.email = "aanand.prasad@gmail.com"
6
+ s.homepage = "https://github.com/aanand/sass-align"
7
+ s.summary = "Command-line tool to align property values nicely in .sass files"
8
+
9
+ man_files = Dir.glob("doc/man/*")
10
+
11
+ s.files = `git ls-files`.split("\n") + man_files
12
+ s.executables = ["sass-align"]
13
+ end
14
+
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sass-align
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aanand Prasad
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-14 00:00:00.000000000Z
13
+ dependencies: []
14
+ description:
15
+ email: aanand.prasad@gmail.com
16
+ executables:
17
+ - sass-align
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Rakefile
23
+ - bin/sass-align
24
+ - doc/ronn/README.ronn
25
+ - sass-align.gemspec
26
+ - doc/man/README.txt
27
+ homepage: https://github.com/aanand/sass-align
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.10
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: Command-line tool to align property values nicely in .sass files
51
+ test_files: []