Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 19 additions and 7 deletions.
  1. +6 −0 README
  2. +6 −0 css2less.bash
  3. +7 −7 css2less.rb
View
6 README
@@ -0,0 +1,6 @@
+Run css2less.bash in your project directory.
+
+e.g. cd /project/folder
+ /path/to/css2less.bash
+
+A ".less" file will be generated beside each ".css" file found inside the current directory and all subdirectories.
View
6 css2less.bash
@@ -0,0 +1,6 @@
+#!/bin/bash
+rbscript=`dirname $0`/`basename $0 | sed 's/\.bash$/.rb/'`
+find . -iname '*.css' | while read cssfile
+do
+ test -f $cssfile && echo $rbscript `echo $cssfile | sed 's/\.css$/.{css,less}/'` && echo echo $cssfile
+done | bash
View
14 css2less.rb
@@ -12,21 +12,21 @@ def add_rule(tree, selectors, style)
end
end
-def print_css(tree, indent=0)
+def print_css(output, tree, indent=0)
tree.each do |element, children|
- puts ' ' * indent + element + " {\n"
+ output.write ' ' * indent + element + " {\n"
style = children.delete(:style)
if style
- puts style.split(';').map { |s| s.strip }.reject { |s| s.empty? }.map { |s| ' ' * (indent+2) + s + ';' }.join("\n")
+ output.write style.split(';').map { |s| s.strip }.reject { |s| s.empty? }.map { |s| ' ' * (indent+2) + s + ';' }.join("\n"); output.write "\n"
end
- print_css(children, indent + 2)
- puts ' ' * indent + "}\n"
+ print_css(output, children, indent + 2)
+ output.write ' ' * indent + "}\n"
end
end
tree = {}
css = File.read(ARGV[0])
-
+output = ARGV[1] ? open(ARGV[1], 'w') : $stdout
css.split("\n").map { |l| l.strip }.join.gsub(/\/\*+[^\*]*\*+\//, '').split(/[\{\}]/).each_slice(2) do |style|
rules = style[0].strip
if rules.include?(',') # leave multiple rules alone
@@ -36,4 +36,4 @@ def print_css(tree, indent=0)
end
end
-print_css(tree)
+print_css(output, tree)

No commit comments for this range

Something went wrong with that request. Please try again.