css_compare 0.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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +6 -0
- data/bin/css_compare +11 -0
- data/lib/css_compare.rb +6 -0
- data/lib/css_compare/constants.rb +5 -0
- data/lib/css_compare/css.rb +3 -0
- data/lib/css_compare/css/component.rb +45 -0
- data/lib/css_compare/css/component/base.rb +21 -0
- data/lib/css_compare/css/component/font_face.rb +190 -0
- data/lib/css_compare/css/component/keyframes.rb +123 -0
- data/lib/css_compare/css/component/keyframes_selector.rb +94 -0
- data/lib/css_compare/css/component/margin_box.rb +40 -0
- data/lib/css_compare/css/component/page_selector.rb +126 -0
- data/lib/css_compare/css/component/property.rb +155 -0
- data/lib/css_compare/css/component/selector.rb +118 -0
- data/lib/css_compare/css/component/supports.rb +136 -0
- data/lib/css_compare/css/component/value.rb +51 -0
- data/lib/css_compare/css/engine.rb +567 -0
- data/lib/css_compare/css/parser.rb +28 -0
- data/lib/css_compare/engine.rb +31 -0
- data/lib/css_compare/exec.rb +111 -0
- data/lib/css_compare/util.rb +13 -0
- metadata +112 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'sass'
|
2
|
+
|
3
|
+
module CssCompare
|
4
|
+
module CSS
|
5
|
+
class Parser
|
6
|
+
# @param [File]
|
7
|
+
def initialize(input)
|
8
|
+
@input = File.expand_path(input)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Parses a CSS project using the Sass parser
|
12
|
+
#
|
13
|
+
# @note The specified syntax is `:scss` because
|
14
|
+
# `:css` has been throwing syntax error on
|
15
|
+
# @charset directive.
|
16
|
+
#
|
17
|
+
# @return [::Sass::Tree::RootNode]
|
18
|
+
def parse
|
19
|
+
tree = ::Sass::Engine.new(
|
20
|
+
File.read(@input),
|
21
|
+
:syntax => :scss, :filename => File.expand_path(@input)
|
22
|
+
).to_tree
|
23
|
+
::Sass::Tree::Visitors::CheckNesting.visit(tree)
|
24
|
+
::Sass::Tree::Visitors::Perform.visit(tree)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'css_compare/css'
|
2
|
+
|
3
|
+
module CssCompare
|
4
|
+
# The engine responsible for the CSS comparison
|
5
|
+
class Engine
|
6
|
+
def initialize(options)
|
7
|
+
@options = options
|
8
|
+
@operands = []
|
9
|
+
end
|
10
|
+
|
11
|
+
# Parses and evaluates the input CSS stylesheets - the operands.
|
12
|
+
#
|
13
|
+
# @return [Engine] itself for method chaining purposes
|
14
|
+
def parse!
|
15
|
+
@options[:operands].each { |operand| @operands << CSS::Engine.new(operand).evaluate }
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
# Checks, whether the parsed CSS files are equal.
|
20
|
+
#
|
21
|
+
# The CSS files are equal, if they define the same
|
22
|
+
# components, that are also equal and at the same
|
23
|
+
# time, no component is missing from either of the
|
24
|
+
# files.
|
25
|
+
#
|
26
|
+
# @return [Boolean]
|
27
|
+
def equal?
|
28
|
+
@operands.first == @operands.last
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'css_compare/engine'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module CssCompare
|
5
|
+
class Comparison
|
6
|
+
def initialize(args)
|
7
|
+
@args = args
|
8
|
+
@options = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Parses the command-line arguments and runs the executable.
|
12
|
+
# Calls `Kernel#exit` at the end, so it never returns.
|
13
|
+
#
|
14
|
+
# @see #parse
|
15
|
+
def parse!
|
16
|
+
begin
|
17
|
+
parse
|
18
|
+
rescue StandardError => e
|
19
|
+
raise e if @options[:trace] || e.is_a?(SystemExit)
|
20
|
+
$stderr.puts "#{e.class}: " + e.message.to_s
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
exit 0
|
24
|
+
end
|
25
|
+
|
26
|
+
# Parses the command-line arguments and runs the executable.
|
27
|
+
def parse
|
28
|
+
@opts = OptionParser.new { |opts| process_opts(opts) }
|
29
|
+
@opts.parse!(@args)
|
30
|
+
|
31
|
+
process_args
|
32
|
+
|
33
|
+
@options
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
# Tells optparse how to parse the arguments.
|
39
|
+
#
|
40
|
+
# @param opts [OptionParser]
|
41
|
+
def process_opts(opts)
|
42
|
+
opts.banner = <<END
|
43
|
+
Usage: css_compare <CSS file> <CSS file>
|
44
|
+
Description:
|
45
|
+
Checks the equality of
|
46
|
+
END
|
47
|
+
|
48
|
+
common_options(opts)
|
49
|
+
input_and_output(opts)
|
50
|
+
end
|
51
|
+
|
52
|
+
def common_options(opts)
|
53
|
+
opts.on('-?', '-h', '--help', 'Show this help message.') do
|
54
|
+
puts opts
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
opts.on('-v', '--version', 'Print the css_compare version.') do
|
59
|
+
puts("v#{CssCompare::VERSION}")
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @todo: specify an option for outputting the diff, when feature is ready
|
65
|
+
def input_and_output(opts)
|
66
|
+
# opts.separator ''
|
67
|
+
# opts.separator 'Input and Output:'
|
68
|
+
end
|
69
|
+
|
70
|
+
def open_file(filename, flag = 'r')
|
71
|
+
return if filename.nil?
|
72
|
+
File.open(filename, flag)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Processes the options set by the command-line arguments -
|
76
|
+
# `@options[:input]` and `@options[:output]` are being set
|
77
|
+
# to appropriate IO streams.
|
78
|
+
#
|
79
|
+
# This method is being overridden by subclasses
|
80
|
+
# to run their respective programs.
|
81
|
+
def process_args
|
82
|
+
args = @args.dup
|
83
|
+
@options[:operands] = nil
|
84
|
+
unless args.length >= 2
|
85
|
+
puts @opts
|
86
|
+
exit 1
|
87
|
+
end
|
88
|
+
@options[:operands] = args.shift(2)
|
89
|
+
@options[:output_filename] = args.shift unless args.empty?
|
90
|
+
@options[:output] ||= @options[:output_filename] || $stdout
|
91
|
+
|
92
|
+
run
|
93
|
+
end
|
94
|
+
|
95
|
+
def write_output(text, destination)
|
96
|
+
if destination.is_a?(String)
|
97
|
+
open_file(destination, 'w') { |file| file.write(text) }
|
98
|
+
else
|
99
|
+
destination.write(text)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Runs the comparison.
|
104
|
+
def run
|
105
|
+
result = CssCompare::Engine.new(@options)
|
106
|
+
.parse!
|
107
|
+
.equal?
|
108
|
+
write_output(result.to_s + "\n", @options[:output])
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CssCompare
|
2
|
+
module Util
|
3
|
+
class << self
|
4
|
+
# Returns a file's path relative to the Less2Sass root directory.
|
5
|
+
#
|
6
|
+
# @param file [String] The filename relative to the Less2Sass root
|
7
|
+
# @return [String] The filename relative to the the working directory
|
8
|
+
def scope(file)
|
9
|
+
File.join(CssCompare::ROOT_DIR, file)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: css_compare
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Attila Večerek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sass
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
description: |2
|
56
|
+
Processes, evaluates and compares 2 different
|
57
|
+
CSS files based on their AST.
|
58
|
+
email:
|
59
|
+
- attila.vecerek@gmail.com
|
60
|
+
executables:
|
61
|
+
- css_compare
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/css_compare
|
69
|
+
- lib/css_compare.rb
|
70
|
+
- lib/css_compare/constants.rb
|
71
|
+
- lib/css_compare/css.rb
|
72
|
+
- lib/css_compare/css/component.rb
|
73
|
+
- lib/css_compare/css/component/base.rb
|
74
|
+
- lib/css_compare/css/component/font_face.rb
|
75
|
+
- lib/css_compare/css/component/keyframes.rb
|
76
|
+
- lib/css_compare/css/component/keyframes_selector.rb
|
77
|
+
- lib/css_compare/css/component/margin_box.rb
|
78
|
+
- lib/css_compare/css/component/page_selector.rb
|
79
|
+
- lib/css_compare/css/component/property.rb
|
80
|
+
- lib/css_compare/css/component/selector.rb
|
81
|
+
- lib/css_compare/css/component/supports.rb
|
82
|
+
- lib/css_compare/css/component/value.rb
|
83
|
+
- lib/css_compare/css/engine.rb
|
84
|
+
- lib/css_compare/css/parser.rb
|
85
|
+
- lib/css_compare/engine.rb
|
86
|
+
- lib/css_compare/exec.rb
|
87
|
+
- lib/css_compare/util.rb
|
88
|
+
homepage: https://github.com/vecerek/css-compare
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.6.3
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: AST-based CSS comparing tool.
|
112
|
+
test_files: []
|