-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
244 additions
and
26 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ group :development, :test do | |
end | ||
|
||
gem 'dry-cli', '~> 1.0' | ||
|
||
gem 'mocha', '~> 2.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'windclutter/util/config' | ||
|
||
module WindClutter | ||
# Analyser for windclutter | ||
class Analyser | ||
include WindClutter::Util | ||
|
||
def self.init(content) | ||
active_project = Config.read('active_project') | ||
|
||
class_key = Config.read_project(active_project, 'class_key') | ||
class_start = Config.read_project(active_project, 'class_start') | ||
class_end = Config.read_project(active_project, 'class_end') | ||
|
||
regex = /#{class_key}=#{class_start}(?:(?!windclutter:)[^#{class_end}])*#{class_end}/ | ||
occurrence_regex = /#{class_key}=#{class_start}([^#{class_end}]*)#{class_end}/ | ||
|
||
collections = {} | ||
content.scan(regex).each do |occurrence| | ||
cls = occurrence.to_s.match(occurrence_regex)[1].split(' ') | ||
|
||
cls.each do |c| | ||
total = collections[c].nil? ? 0 : collections[c] | ||
collections[c] = total + 1 | ||
end | ||
end | ||
collections.sort_by { |_, v| -v }.to_h | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'dry/cli' | ||
require 'windclutter/analyser' | ||
require 'windclutter/util/file_handler' | ||
require 'windclutter/cli/commands/project' | ||
require 'windclutter/cli/commands/generate' | ||
|
||
module WindClutter | ||
module CLI | ||
module Commands | ||
module Analysis | ||
# Initiate setup for specified project | ||
class FilePath < Dry::CLI::Command | ||
include WindClutter::Util | ||
|
||
desc 'Perform CSS analysis of the path' | ||
argument :path, aliases: ['-p'], required: true, desc: 'Path of your CSS file to be dump.' | ||
|
||
def call(path:, **) | ||
puts "Analysing #{path}...".green | ||
|
||
file = File.open(FileHandler.scan_one(path)) | ||
puts 'Done!'.green | ||
puts WindClutter::Analyser.init(file.read) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
def config_fixture | ||
{ 'projects' => { 'test_project' => { 'class_key' => 'class', 'class_start' => '"', 'class_end' => '"' } } } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'minitest/autorun' | ||
require 'minitest/mock' | ||
require 'mocha/minitest' | ||
|
||
Dir['test/fixtures/**/*.rb'].sort.each { |f| require f.split('/')[1..].join('/') } | ||
Dir['test/windclutter/**/*.rb'].sort.each { |f| require f.split('/')[1..].join('/') } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'windclutter/analyser' | ||
require 'windclutter/util/config' | ||
|
||
class WindClutterAnalyserTest < Minitest::Test | ||
include WindClutter | ||
include WindClutter::Util | ||
def test_able_to_analyse_content | ||
Config.expects(:read).returns('test_project') | ||
File.stubs(:file?).with('/tmp/windclutter/config.yml').returns(true) | ||
Config.any_instance.stubs(:exists?).returns(true) | ||
YAML.stubs(:load_file).with('/tmp/windclutter/config.yml').returns(config_fixture) | ||
|
||
# Config.expects(:read_project).with('test_project', 'class_key').returns('class') | ||
assert_equal Analyser.init(dummy_content), expected_output | ||
end | ||
|
||
private | ||
|
||
def dummy_content | ||
<<~CONTENT | ||
<div class="flex flex-col items-center gap-6 px-10 py-40 overflow-y-scroll"> | ||
</div> | ||
CONTENT | ||
end | ||
|
||
def expected_output | ||
{ 'flex' => 1, 'flex-col' => 1, 'items-center' => 1, 'gap-6' => 1, 'px-10' => 1, 'py-40' => 1, | ||
'overflow-y-scroll' => 1 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.