Class: WidgetBundle
- Inherits:
-
Object
- Object
- WidgetBundle
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/app/models/widget_bundle.rb
Instance Attribute Summary collapse
-
#haml ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png.
-
#images ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png.
-
#javascripts ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png.
-
#stylesheets ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png.
-
#thumbnail ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ WidgetBundle
constructor
A new instance of WidgetBundle.
-
#package(display_name, bundle_identifier, bundle_name, root_path = Dir.tmpdir) ⇒ Object
Package the widget contents into a folder for download root_path: specify path to use, default is Rails app tmpdir.
Constructor Details
#initialize(attributes = {}) ⇒ WidgetBundle
Returns a new instance of WidgetBundle.
23 24 25 26 27 |
# File 'lib/app/models/widget_bundle.rb', line 23 def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end end |
Instance Attribute Details
#haml ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png
20 21 22 |
# File 'lib/app/models/widget_bundle.rb', line 20 def haml @haml end |
#images ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png
20 21 22 |
# File 'lib/app/models/widget_bundle.rb', line 20 def images @images end |
#javascripts ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png
20 21 22 |
# File 'lib/app/models/widget_bundle.rb', line 20 def javascripts @javascripts end |
#stylesheets ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png
20 21 22 |
# File 'lib/app/models/widget_bundle.rb', line 20 def stylesheets @stylesheets end |
#thumbnail ⇒ Object
images, stylesheets and javascripts as file path arrays haml file as string, fullpath to main.haml thumbnail as fullpath to image, will be renamed to default.png
20 21 22 |
# File 'lib/app/models/widget_bundle.rb', line 20 def thumbnail @thumbnail end |
Instance Method Details
#package(display_name, bundle_identifier, bundle_name, root_path = Dir.tmpdir) ⇒ Object
Package the widget contents into a folder for download root_path: specify path to use, default is Rails app tmpdir. Implemented this for testing.
31 32 33 34 35 36 37 38 39 40 41 42 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 70 71 |
# File 'lib/app/models/widget_bundle.rb', line 31 def package(display_name, bundle_identifier, bundle_name, root_path = Dir.tmpdir) return false unless valid? path = File. "#{root_path}/#{Time.now.to_i}#{rand(1000)}.wdgt/" FileUtils.mkdir_p path # make requred directories images_dir = path css_js_dir = FileUtils.mkdir("#{path}/assets/")[0] # copy images # TODO: tried doing this all with FileUtils.cp_r but couldn't get it to work properly, had to use this block instead if images images.each do |i| file = "#{Rails.root}/public#{i}".split("?")[0] dir = "#{images_dir}/#{File.dirname(i)}".gsub('//', '/') FileUtils.mkdir_p dir FileUtils.cp file, dir end end # minify stylesheets minify_stylesheets(stylesheets, css_js_dir) # minify javascripts minify_javascripts(javascripts, css_js_dir) # create Info.plist File.open("#{path}/Info.plist", "w") { |file| file.write(plist_content(display_name, bundle_identifier, bundle_name)) } # create main.html # compiled_haml = `haml #{haml}` File.open("#{path}/main.html", "w") { |file| file.write( haml ) } # copy thumbnail to ./default.png FileUtils.cp("#{Rails.root}/public#{thumbnail.split('?')[0]}", "#{path}/default.png") if thumbnail # compress the *.wdgt folder and return the full path to the zip archive compress(path) end |