squatch 0.0.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 sdomino
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ = Squatch
2
+
3
+ Squatch will take your sass/css files (or any file really) and 'squatch' them; meaning it will remove all extra linebreaks, and clean up whitespace, essentially making each css declaration a single line rather than multiple lines.
4
+
5
+ == Features
6
+
7
+ * Super pretty, super readable stylesheets
8
+ * Support for single or multiple file squatching
9
+ * Creates a backup of original file, incase you want to unsquatch your file
10
+ * Command Line Input (CLI)
11
+ * Rake tasks (coming soon)
12
+ * Thor tasks (coming soon)
13
+
14
+ == Install
15
+
16
+ === Rails (coming soon)
17
+
18
+ Add this line to your Gemfile:
19
+
20
+ gem 'squatch'
21
+
22
+ Then do a bundle install:
23
+
24
+ bundle install
25
+
26
+ ---
27
+
28
+ === Non Rails
29
+
30
+ gem install squatch
31
+
32
+ == Usage
33
+
34
+ Usage: squatch -command [FILE/DIR]
35
+
36
+ -h, --help Display this help
37
+ -v, --version Display current gem version
38
+ -f, --file FILE Squatch FILE in place
39
+ -F, --files DIR Squatch files from DIR in place
40
+
41
+ ---
42
+
43
+ == TODO
44
+
45
+ * Tests
46
+ * One final pass of cleanup and refactoring
47
+ * Cleanup the look of squatched files
48
+
49
+ == Copyright
50
+
51
+ Copyright (c) 2011 Steve Domino. See LICENSE.txt for further details
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'squatch'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'squatch'
8
+ end
9
+
10
+ Squatch.run(ARGV)
@@ -1,5 +1,50 @@
1
- require "squatch/version"
1
+ Dir["#{File.dirname(__FILE__)}/squatch/**/*"].each {|file| require(file)}
2
+
3
+ require 'optparse'
2
4
 
3
5
  module Squatch
4
- # Your code goes here...
6
+ class << self
7
+
8
+ def run(arguments)
9
+ unless arguments.empty? || !arguments[0].include?('-')
10
+ optparser = OptionParser.new do|opts|
11
+ opts.banner = "Usage: squatch -command [FILE/DIR]"
12
+
13
+ opts.on('-h', '--help', 'Display this help') do
14
+ puts optparser
15
+ exit
16
+ end
17
+ opts.on('-v', '--version', 'Display current gem version') do
18
+ puts "Squatch-#{VERSION}"
19
+ end
20
+ opts.on('-f', '--file FILE', 'Squatch FILE in place') do |file|
21
+ prepare(file)
22
+ end
23
+ opts.on('-F', '--folder DIR', 'Squatch files from DIR in place') do |dir|
24
+ prepare(dir)
25
+ end
26
+ end
27
+
28
+ begin optparser.parse!(arguments)
29
+ rescue OptionParser::ParseError => error
30
+ puts "#{error}"
31
+ puts optparser
32
+ exit
33
+ end
34
+ else
35
+ puts `squatch -h`
36
+ end
37
+ end
38
+
39
+ def prepare(data)
40
+ options = Hash[:data, data]
41
+
42
+ puts "Specify file type (ie css or js):"
43
+ options[:ext] = gets.strip
44
+
45
+ Squatch::Base.squatch(options)
46
+ end
47
+
48
+ end
5
49
  end
50
+
@@ -0,0 +1,81 @@
1
+ module Squatch
2
+ module Base
3
+ class << self
4
+
5
+ require 'fileutils'
6
+
7
+ def squatch(options)
8
+
9
+ destination_path = Dir.open(File.dirname(options[:data]))
10
+
11
+ case File.ftype(options[:data])
12
+ when 'file'
13
+ files_to_squatch = Array[options[:data]]
14
+ backup_dir = "#{File.dirname(options[:data])}/backup"
15
+ when 'directory'
16
+ files_to_squatch = Dir.glob("#{options[:data]}/**/*#{options[:ext]}")
17
+ backup_dir = "#{options[:data]}/backup"
18
+ else
19
+ puts "Oops!"
20
+ exit
21
+ end
22
+
23
+ Dir.exists?(backup_dir) ? true : Dir.mkdir(backup_dir)
24
+
25
+ # squatch each file in files_to_compress and save in place
26
+ begin
27
+ files_to_squatch.each do |path|
28
+ File.open("#{path}", 'r+') do |file|
29
+
30
+ FileUtils.copy_file(file, "#{backup_dir}/#{File.basename(file, File.extname(file))}.txt")
31
+ puts "Backup of #{File.basename(file)} created at #{backup_dir} named #{File.basename(file, File.extname(file))}.txt."
32
+
33
+ new_lines = ''
34
+
35
+ puts "Squatching: #{File.basename(file)}..."
36
+ file.each_line do |line|
37
+ new_lines.concat(line.strip)
38
+ end
39
+
40
+ new_lines.gsub!(';', '; ')
41
+ new_lines.gsub!('{', '{ ')
42
+ new_lines.gsub!('}', "}\n")
43
+ new_lines.gsub!('/*', "\n/*")
44
+ new_lines.gsub!('*/', "*/\n")
45
+
46
+ # new_lines.each_char do |char|
47
+ # case char
48
+ # when ';'
49
+ # puts "SEMI: #{char}, #{char.class}"
50
+ # char.replace('HELLO')
51
+ # else
52
+ # end
53
+ # end
54
+
55
+ file.rewind
56
+ file.print(new_lines)
57
+ file.truncate(file.pos)
58
+
59
+ end
60
+
61
+ puts "#{File.basename(path)} has been squatched"
62
+ end
63
+
64
+ # confirm squatching
65
+ puts "Complete! All #{options[:ext]} files have been squatched"
66
+ rescue => exception
67
+ puts "Oops! #{exception.message}"
68
+ exception.backtrace.each do |trace|
69
+ puts "#{trace} \n"
70
+ end
71
+ end
72
+ end
73
+
74
+ # this will save a version of their file somewhere incase they decide they don't want it squatched anymore. Much easier than actually trying to add all the whitespace back in.
75
+ def unsquatch(options)
76
+
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,3 @@
1
1
  module Squatch
2
- VERSION = "0.0.1"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-08 00:00:00.000000000Z
12
+ date: 2011-09-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70224877063820 !ruby/object:Gem::Requirement
16
+ requirement: &70182061025120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,18 +21,23 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70224877063820
24
+ version_requirements: *70182061025120
25
25
  description: It's going to relate to sass, and I think I know what I want it to do...
26
26
  email:
27
27
  - domino.steve@gmail.com
28
- executables: []
28
+ executables:
29
+ - squatch
29
30
  extensions: []
30
31
  extra_rdoc_files: []
31
32
  files:
32
33
  - .gitignore
33
34
  - Gemfile
35
+ - LICENSE.txt
36
+ - README.rdoc
34
37
  - Rakefile
38
+ - bin/squatch
35
39
  - lib/squatch.rb
40
+ - lib/squatch/base.rb
36
41
  - lib/squatch/version.rb
37
42
  - squatch.gemspec
38
43
  homepage: http://github.com/sdomino/squatch