Class: Confetti::Template::BlackberryWidgetsConfig

Inherits:
Base
  • Object
show all
Includes:
VersionHelper
Defined in:
lib/confetti/templates/blackberry_widgets_config.rb

Constant Summary collapse

ORIENTATIONS_MAP =
{
  :default => "auto",
  :landscape => "landscape",
  :portrait => "portrait"
}
@@legacy_template =
File.read(
  File.join(
    File.dirname(__FILE__),
    "blackberry_widgets_config_legacy.mustache"
))

Instance Method Summary collapse

Methods included from VersionHelper

#normalize_version

Constructor Details

#initialize(*args) ⇒ BlackberryWidgetsConfig

Returns a new instance of BlackberryWidgetsConfig.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 18

def initialize *args
  super *args

  return self unless @config

  # old = 0.x, 1.0, 1.1, or 1.2
  old = /^(0)|^(1[.][0-2])/

  if @config.phonegap_version and @config.phonegap_version.match(old)
    self.template = @@legacy_template
  end
end

Instance Method Details

#accessObject



106
107
108
109
110
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 106

def access
  @config.access_set.select { |a| valid_origin(a.origin) }.map do |a|
    { :subdomains => !!a.subdomains, :uri => a.origin }
  end
end

#app_orientationObject



91
92
93
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 91

def app_orientation
  ORIENTATIONS_MAP[@config.orientation]
end

#author_emailObject



51
52
53
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 51

def author_email
  @config.author.email
end

#author_hrefObject



47
48
49
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 47

def author_href
  @config.author.href
end

#author_nameObject



55
56
57
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 55

def author_name
  @config.author.name
end

#framework_namespaceObject



99
100
101
102
103
104
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 99

def framework_namespace
  # phonegap = 0.x, 1.0, 1.1, 1.2, 1.3, 1.4
  gap = @config.phonegap_version.match(/^(0)|^(1[.][0-4])/)

  gap ? 'com.phonegap' : 'org.apache.cordova'
end

#license_hrefObject



67
68
69
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 67

def license_href
  @config.license.href
end

#license_textObject



71
72
73
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 71

def license_text
  @config.license.text
end

#no_cursor?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 95

def no_cursor?
  @config.preference("disable-cursor") == :true
end

#output_filenameObject



87
88
89
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 87

def output_filename
  "config.xml"
end

#phonegap_versionObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 75

def phonegap_version
  # should be 1.0.0, unless below 1
  # @config.phonegap_version
  pg = @config.phonegap_version

  if pg.nil? or pg.empty? or pg.match(/^1/)
    "1.0.0"
  else
    pg
  end
end

#valid_origin(o) ⇒ Object



112
113
114
115
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 112

def valid_origin o
  # not nil and (wildcard or with scheme)
  !o.nil? && (o == '*' || o.match(/^\w+:\/\//))
end

#versionObject



39
40
41
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 39

def version
  normalize_version(@config.version_string)
end

#widget_descriptionObject



59
60
61
62
63
64
65
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 59

def widget_description
  if @config.description && @config.description.length >= 500
    "#{ @config.description[0..495] }..."
  else
    @config.description
  end
end

#widget_idObject



31
32
33
34
35
36
37
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 31

def widget_id
  if @config.package.nil? or @config.package.empty?
    "com.default.noname"
  else
    @config.package
  end
end

#widget_nameObject



43
44
45
# File 'lib/confetti/templates/blackberry_widgets_config.rb', line 43

def widget_name
  @config.name.name
end