Class: ZendeskAppsSupport::Package
- Inherits:
-
Object
- Object
- ZendeskAppsSupport::Package
- Includes:
- BuildTranslation
- Defined in:
- lib/zendesk_apps_support/package.rb
Constant Summary collapse
- DEFAULT_LAYOUT =
Erubis::Eruby.new(File.read(File.('../assets/default_template.html.erb', __FILE__)))
- DEFAULT_SCSS =
File.read(File.('../assets/default_styles.scss', __FILE__))
- SRC_TEMPLATE =
Erubis::Eruby.new(File.read(File.('../assets/src.js.erb', __FILE__)))
Constants included from BuildTranslation
BuildTranslation::I18N_KEYS, BuildTranslation::I18N_TITLE_KEY, BuildTranslation::I18N_VALUE_KEY
Instance Attribute Summary collapse
-
#lib_root ⇒ Object
readonly
Returns the value of attribute lib_root.
-
#requirements_only ⇒ Object
Returns the value of attribute requirements_only.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #app_js ⇒ Object
- #app_translations ⇒ Object
- #commonjs_modules ⇒ Object
- #customer_css ⇒ Object
- #file_path(path) ⇒ Object
- #files ⇒ Object
- #has_banner? ⇒ Boolean
- #has_js? ⇒ Boolean
- #has_lib_js? ⇒ Boolean
- #has_location? ⇒ Boolean
- #has_manifest? ⇒ Boolean
- #has_requirements? ⇒ Boolean
-
#initialize(dir) ⇒ Package
constructor
A new instance of Package.
- #lib_files ⇒ Object
- #manifest_json ⇒ Object
- #readified_js(app_name, app_id, asset_url_prefix, settings = {}) ⇒ Object
- #requirements_json ⇒ Object
- #template_files ⇒ Object
- #translation_files ⇒ Object
- #translations ⇒ Object
- #validate ⇒ Object
Methods included from BuildTranslation
#remove_zendesk_keys, #to_flattened_namespaced_hash
Constructor Details
#initialize(dir) ⇒ Package
Returns a new instance of Package.
16 17 18 19 20 21 |
# File 'lib/zendesk_apps_support/package.rb', line 16 def initialize(dir) @root = Pathname.new(File.(dir)) @lib_root = Pathname.new(File.join(@root, 'lib')) @warnings = [] @requirements_only = false end |
Instance Attribute Details
#lib_root ⇒ Object (readonly)
Returns the value of attribute lib_root.
13 14 15 |
# File 'lib/zendesk_apps_support/package.rb', line 13 def lib_root @lib_root end |
#requirements_only ⇒ Object
Returns the value of attribute requirements_only.
14 15 16 |
# File 'lib/zendesk_apps_support/package.rb', line 14 def requirements_only @requirements_only end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
13 14 15 |
# File 'lib/zendesk_apps_support/package.rb', line 13 def root @root end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
13 14 15 |
# File 'lib/zendesk_apps_support/package.rb', line 13 def warnings @warnings end |
Instance Method Details
#app_js ⇒ Object
49 50 51 |
# File 'lib/zendesk_apps_support/package.rb', line 49 def app_js read_file('app.js') end |
#app_translations ⇒ Object
91 92 93 |
# File 'lib/zendesk_apps_support/package.rb', line 91 def app_translations remove_zendesk_keys(translations) end |
#commonjs_modules ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/zendesk_apps_support/package.rb', line 53 def commonjs_modules return unless has_lib_js? lib_files.each_with_object({}) do |file, modules| name = file.relative_path.gsub!(/^lib\//, '') content = file.read modules[name] = content end end |
#customer_css ⇒ Object
131 132 133 134 |
# File 'lib/zendesk_apps_support/package.rb', line 131 def customer_css css_file = file_path('app.css') File.exist?(css_file) ? File.read(css_file) : '' end |
#file_path(path) ⇒ Object
160 161 162 |
# File 'lib/zendesk_apps_support/package.rb', line 160 def file_path(path) File.join(root, path) end |
#files ⇒ Object
63 64 65 |
# File 'lib/zendesk_apps_support/package.rb', line 63 def files non_tmp_files end |
#has_banner? ⇒ Boolean
156 157 158 |
# File 'lib/zendesk_apps_support/package.rb', line 156 def file_exists?('assets/banner.png') end |
#has_js? ⇒ Boolean
136 137 138 |
# File 'lib/zendesk_apps_support/package.rb', line 136 def has_js? file_exists?('app.js') end |
#has_lib_js? ⇒ Boolean
140 141 142 |
# File 'lib/zendesk_apps_support/package.rb', line 140 def has_lib_js? lib_files.any? end |
#has_location? ⇒ Boolean
148 149 150 |
# File 'lib/zendesk_apps_support/package.rb', line 148 def has_location? manifest_json[:location] end |
#has_manifest? ⇒ Boolean
144 145 146 |
# File 'lib/zendesk_apps_support/package.rb', line 144 def has_manifest? file_exists?('manifest.json') end |
#has_requirements? ⇒ Boolean
152 153 154 |
# File 'lib/zendesk_apps_support/package.rb', line 152 def has_requirements? file_exists?('requirements.json') end |
#lib_files ⇒ Object
67 68 69 |
# File 'lib/zendesk_apps_support/package.rb', line 67 def lib_files @lib_files ||= files.select { |f| f =~ /^lib\/.*\.js$/ } end |
#manifest_json ⇒ Object
79 80 81 |
# File 'lib/zendesk_apps_support/package.rb', line 79 def manifest_json read_json('manifest.json') end |
#readified_js(app_name, app_id, asset_url_prefix, settings = {}) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/zendesk_apps_support/package.rb', line 95 def readified_js(app_name, app_id, asset_url_prefix, settings = {}) manifest = manifest_json source = app_js name = app_name || manifest[:name] || 'Local App' location = manifest[:location] app_class_name = "app-#{app_id}" = manifest[:author] framework_version = manifest[:frameworkVersion] single_install = manifest[:singleInstall] || false no_template = manifest[:noTemplate] templates = no_template ? {} : compiled_templates(app_id, asset_url_prefix) settings['title'] = name app_settings = { location: location, noTemplate: no_template, singleInstall: single_install }.select { |_k, v| !v.nil? } SRC_TEMPLATE.result( name: name, source: source, app_settings: app_settings, asset_url_prefix: asset_url_prefix, app_class_name: app_class_name, author: , translations: app_translations, framework_version: framework_version, templates: templates, settings: settings, app_id: app_id, modules: commonjs_modules ) end |
#requirements_json ⇒ Object
83 84 85 |
# File 'lib/zendesk_apps_support/package.rb', line 83 def requirements_json read_json('requirements.json') end |
#template_files ⇒ Object
71 72 73 |
# File 'lib/zendesk_apps_support/package.rb', line 71 def template_files files.select { |f| f =~ /^templates\/.*\.hdbs$/ } end |
#translation_files ⇒ Object
75 76 77 |
# File 'lib/zendesk_apps_support/package.rb', line 75 def translation_files files.select { |f| f =~ /^translations\// } end |
#translations ⇒ Object
87 88 89 |
# File 'lib/zendesk_apps_support/package.rb', line 87 def translations read_json('translations/en.json', false) end |
#validate ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zendesk_apps_support/package.rb', line 23 def validate [].tap do |errors| errors << Validations::Manifest.call(self) if has_manifest? errors << Validations::Source.call(self) errors << Validations::Translations.call(self) unless @requirements_only errors << Validations::Templates.call(self) errors << Validations::Stylesheets.call(self) end if has_requirements? errors << Validations::Requirements.call(self) end end if errors << Validations::Banner.call(self) end errors.flatten! end end |