Class: ZendeskAppsSupport::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/zendesk_apps_support/package.rb

Constant Summary collapse

DEFAULT_LAYOUT =
Erubis::Eruby.new( File.read(File.expand_path('../assets/default_template.html.erb', __FILE__)) )
DEFAULT_SCSS =
File.read(File.expand_path('../assets/default_styles.scss', __FILE__))
SRC_TEMPLATE =
Erubis::Eruby.new( File.read(File.expand_path('../assets/src.js.erb', __FILE__)) )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Package

Returns a new instance of Package.



14
15
16
17
# File 'lib/zendesk_apps_support/package.rb', line 14

def initialize(dir)
  @root = Pathname.new(File.expand_path(dir))
  @warnings = []
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



12
13
14
# File 'lib/zendesk_apps_support/package.rb', line 12

def root
  @root
end

#warningsObject (readonly)

Returns the value of attribute warnings.



12
13
14
# File 'lib/zendesk_apps_support/package.rb', line 12

def warnings
  @warnings
end

Instance Method Details

#customer_cssObject



71
72
73
74
# File 'lib/zendesk_apps_support/package.rb', line 71

def customer_css
  css_file = File.join(root, 'app.css')
  customer_css = File.exist?(css_file) ? File.read(css_file) : ""
end

#filesObject



27
28
29
# File 'lib/zendesk_apps_support/package.rb', line 27

def files
  non_tmp_files
end

#manifest_jsonObject



39
40
41
# File 'lib/zendesk_apps_support/package.rb', line 39

def manifest_json
  JSON.parse(File.read(File.join(root, "manifest.json")), :symbolize_names => true)
end

#readified_js(app_name, app_id, asset_url_prefix, settings = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/zendesk_apps_support/package.rb', line 43

def readified_js(app_name, app_id, asset_url_prefix, settings={})
  manifest = manifest_json
  source = File.read(File.join(root, "app.js"))
  name = app_name || manifest[:name] || 'Local App'
  location = manifest[:location]
  app_class_name = "app-#{app_id}"
  author = manifest[:author]
  translations = JSON.parse(File.read(File.join(root, "translations/en.json")))
  framework_version = manifest[:frameworkVersion]
  templates = manifest[:noTemplate] ? {} : compiled_templates(app_id, asset_url_prefix)

  settings["title"] = name

  SRC_TEMPLATE.result(
      :name => name,
      :source => source,
      :location => location,
      :asset_url_prefix => asset_url_prefix,
      :app_class_name => app_class_name,
      :author => author,
      :translations => translations,
      :framework_version => framework_version,
      :templates => templates,
      :settings => settings,
      :app_id => app_id
  )
end

#template_filesObject



31
32
33
# File 'lib/zendesk_apps_support/package.rb', line 31

def template_files
  files.select { |f| f =~ /^templates\/.*\.hdbs$/ }
end

#translation_filesObject



35
36
37
# File 'lib/zendesk_apps_support/package.rb', line 35

def translation_files
  files.select { |f| f =~ /^translations\// }
end

#validateObject



19
20
21
22
23
24
25
# File 'lib/zendesk_apps_support/package.rb', line 19

def validate
  Validations::Manifest.call(self) +
    Validations::Source.call(self) +
    Validations::Templates.call(self) +
    Validations::Translations.call(self) +
    Validations::Stylesheets.call(self)
end