Class: Readiness::Repos::Themes
- Defined in:
- lib/support_readiness/repos/themes.rb
Overview
Defines the class Themes within the module Readiness::Repos.
Class Method Summary collapse
-
.convert_file(file) ⇒ Object
Converts the contents of a file for a theme.
-
.convert_only(destination, fields, forms) ⇒ Object
Runs the conversion for a theme.
-
.create_copy(source = 'data/theme', target = 'data/modified_theme') ⇒ Object
Copies from source to target.
-
.create_modified(source, target, fields, forms) ⇒ Object
Creates a modified theme.
-
.files_to_convert ⇒ Array
Generates an array of files to use.
-
.item_from_match(match) ⇒ String
Determine the title/name of the form/field in a match.
-
.replace_fields(contents, match) ⇒ String
Replaces field placeholders with their matching ID value.
-
.replace_forms(contents, match) ⇒ String
Replaces form placeholders with their matching ID value.
-
.scan_and_replace(contents) ⇒ String
Scans and replaces items for themes.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Class Method Details
.convert_file(file) ⇒ Object
Converts the contents of a file for a theme
71 72 73 74 75 76 77 |
# File 'lib/support_readiness/repos/themes.rb', line 71 def self.convert_file(file) contents = File.read(file) if contents =~ /\[\[form/ || contents =~ /\[\[field/ contents = scan_and_replace(contents) end File.write(file, contents) end |
.convert_only(destination, fields, forms) ⇒ Object
Runs the conversion for a theme
35 36 37 38 39 40 41 42 |
# File 'lib/support_readiness/repos/themes.rb', line 35 def self.convert_only(destination, fields, forms) @destination = destination @fields = fields @forms = forms files_to_convert.each do |file| convert_file(file) end end |
.create_copy(source = 'data/theme', target = 'data/modified_theme') ⇒ Object
Copies from source to target
51 52 53 |
# File 'lib/support_readiness/repos/themes.rb', line 51 def self.create_copy(source = 'data/theme', target = 'data/modified_theme') FileUtils.copy_entry source, target end |
.create_modified(source, target, fields, forms) ⇒ Object
Creates a modified theme
22 23 24 25 |
# File 'lib/support_readiness/repos/themes.rb', line 22 def self.create_modified(source, target, fields, forms) create_copy(source, target) convert_only(target, fields, forms) end |
.files_to_convert ⇒ Array
Generates an array of files to use
61 62 63 |
# File 'lib/support_readiness/repos/themes.rb', line 61 def self.files_to_convert Dir["#{@destination}/templates/*.hbs"] + ["#{@destination}/script.js"] end |
.item_from_match(match) ⇒ String
Determine the title/name of the form/field in a match
133 134 135 |
# File 'lib/support_readiness/repos/themes.rb', line 133 def self.item_from_match(match) match.split(':').last.split(']').first.strip.gsub(/^['"]/, '').gsub(/['"]$/, '') end |
.replace_fields(contents, match) ⇒ String
Replaces field placeholders with their matching ID value
117 118 119 120 121 122 123 124 |
# File 'lib/support_readiness/repos/themes.rb', line 117 def self.replace_fields(contents, match) name = item_from_match(match) field = @fields.detect { |f| f.title == name } puts "Bad field in code: #{name}" if field.nil? exit 1 if field.nil? contents.gsub(match, field.id.to_s) end |
.replace_forms(contents, match) ⇒ String
Replaces form placeholders with their matching ID value
100 101 102 103 104 105 106 107 |
# File 'lib/support_readiness/repos/themes.rb', line 100 def self.replace_forms(contents, match) name = item_from_match(match) form = @forms.detect { |f| f.name == name } puts "Bad form in code: #{name}" if form.nil? exit 1 if form.nil? contents.gsub(match, form.id.to_s) end |
.scan_and_replace(contents) ⇒ String
Scans and replaces items for themes
86 87 88 89 90 |
# File 'lib/support_readiness/repos/themes.rb', line 86 def self.scan_and_replace(contents) contents.scan(/\[\[form:\ ?['"]?[^\]]+['"]?\]\]/).each { |m| contents = replace_forms(contents, m) } contents.scan(/\[\[field:\ ?['"]?[^\]]+['"]?\]\]/).each { |m| contents = replace_fields(contents, m) } contents end |