Class: DiffuxCIUtils
- Inherits:
-
Object
- Object
- DiffuxCIUtils
- Defined in:
- lib/diffux_ci_utils.rb
Class Method Summary collapse
- .config ⇒ Object
- .config_from_file ⇒ Object
- .construct_url(absolute_path, params = {}) ⇒ Object
- .current_snapshots ⇒ Object
- .normalize_description(description) ⇒ Object
- .path_to(description, viewport_name, file_name) ⇒ Object
Class Method Details
.config ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/diffux_ci_utils.rb', line 6 def self.config @@config ||= { 'snapshots_folder' => './snapshots', 'source_files' => [], 'stylesheets' => [], 'port' => 4567, 'driver' => :firefox, 'viewports' => { 'large' => { 'width' => 1024, 'height' => 768 }, 'medium' => { 'width' => 640, 'height' => 888 }, 'small' => { 'width' => 320, 'height' => 444 } } }.merge(config_from_file) end |
.config_from_file ⇒ Object
30 31 32 33 |
# File 'lib/diffux_ci_utils.rb', line 30 def self.config_from_file config_file_name = ENV['DIFFUX_CI_CONFIG_FILE'] || '.diffux_ci.yaml' YAML.load(ERB.new(File.read(config_file_name)).result) end |
.construct_url(absolute_path, params = {}) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/diffux_ci_utils.rb', line 48 def self.construct_url(absolute_path, params = {}) query = URI.encode_www_form(params) unless params.empty? URI::HTTP.build(host: 'localhost', port: config['port'], path: absolute_path, query: query).to_s end |
.current_snapshots ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/diffux_ci_utils.rb', line 57 def self.current_snapshots prepare_file = lambda do |file| = File.('..', file) description_dir = File.('..', ) { description: File.basename(description_dir), viewport: File.basename().sub('@', ''), file: file } end snapshots_folder = DiffuxCIUtils.config['snapshots_folder'] diff_files = Dir.glob("#{snapshots_folder}/**/diff.png") baselines = Dir.glob("#{snapshots_folder}/**/baseline.png") { diffs: diff_files.map(&prepare_file), baselines: baselines.map(&prepare_file) } end |
.normalize_description(description) ⇒ Object
35 36 37 |
# File 'lib/diffux_ci_utils.rb', line 35 def self.normalize_description(description) description.gsub(/[^a-zA-Z0-9\-_]/, '_') end |
.path_to(description, viewport_name, file_name) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/diffux_ci_utils.rb', line 39 def self.path_to(description, , file_name) File.join( config['snapshots_folder'], normalize_description(description), "@#{viewport_name}", file_name ) end |