widget_bundler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/app/models/widget_bundle.rb +97 -0
- data/lib/widget_bundler.rb +1 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzYxZjljYWMyNzc0Njk2MjMyNmI0ODNiZDhkODk0MWQxMTMzNjM3Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGY1MWY4NmUyOWEwMzY3Mzg5ZGQ0N2YxODg3MzY5OTExMmY3MTcwZg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmVkNzQ4MDVjZGU1M2NjNzA1ZDIzNmVhMjMzNzAxMmVjMTg4ZGNhZTIzNjI4
|
10
|
+
MDZiMTkyZWM3ZWY3YjcxODgxOGMwODg5NjA5Mzk5NTQ1NmNjMzE5NDAxZDc3
|
11
|
+
YjUwZWM0ZDdhYWVhYTc2M2UyZDY2YTdiNzYxMTYwYWQ1YjU4YjI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MWRkZjJkNWNkZGFiMDE5ZDE5NWVmYzcxMDkwZTY4OGI3NTFkNzRkMjJmYTlj
|
14
|
+
YTM3YTQzYzhmZThmMzVlZjM0Mzk2OWM5NjBhZTA1ZTNhMWVlMWYzNzYzOTg5
|
15
|
+
ODM3YjA2MjhlNWI4ZTU0NGU5MjI0MDE3NDYwOTRjZGFlMzc2YTY=
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#
|
2
|
+
# Class for packaging set of html, javascript, image and stylesheet files into a widget for an iBook
|
3
|
+
# => accepts an array of images, stylesheets and javascripts as full paths
|
4
|
+
# => acceps main haml file as string (fullpath)
|
5
|
+
#
|
6
|
+
require 'active_model'
|
7
|
+
require 'plist'
|
8
|
+
|
9
|
+
class WidgetBundle
|
10
|
+
|
11
|
+
# Rails mixins
|
12
|
+
include ActiveModel::Validations
|
13
|
+
|
14
|
+
# images, stylesheets and javascripts as file paths
|
15
|
+
# haml file as string, fullpath to main.haml
|
16
|
+
attr_accessor :images, :stylesheets, :javascripts, :haml
|
17
|
+
validates :haml, presence: true
|
18
|
+
|
19
|
+
def initialize(attributes = {})
|
20
|
+
attributes.each do |name, value|
|
21
|
+
send("#{name}=", value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Package the widget contents into a folder for download
|
26
|
+
# root_path: specify path to use, default is Rails app tmpdir. Implemented this for testing.
|
27
|
+
def package(display_name, bundle_identifier, bundle_name, root_path = Dir.tmpdir)
|
28
|
+
|
29
|
+
return false unless valid?
|
30
|
+
|
31
|
+
path = File.expand_path "#{root_path}/#{Time.now.to_i}#{rand(1000)}.wdgt/"
|
32
|
+
FileUtils.mkdir_p path
|
33
|
+
|
34
|
+
# make requred directories
|
35
|
+
images_dir = FileUtils.mkdir "#{path}/images/"
|
36
|
+
stylesheets_dir = FileUtils.mkdir "#{path}/stylesheets/"
|
37
|
+
javascripts_dir = FileUtils.mkdir "#{path}/javascripts/"
|
38
|
+
|
39
|
+
# copy images
|
40
|
+
FileUtils.cp images, images_dir if images
|
41
|
+
|
42
|
+
# copy stylesheets
|
43
|
+
FileUtils.cp stylesheets, stylesheets_dir if stylesheets
|
44
|
+
|
45
|
+
# copy javascripts
|
46
|
+
FileUtils.cp javascripts, javascripts_dir if javascripts
|
47
|
+
|
48
|
+
# create Info.plist
|
49
|
+
File.open("#{path}/Info.plist", "w") { |file| file.write(plist_content(display_name, bundle_identifier, bundle_name)) }
|
50
|
+
|
51
|
+
# create main.html
|
52
|
+
compiled_haml = `haml #{haml}`
|
53
|
+
File.open("#{path}/main.html", "w") { |file| file.write( compiled_haml ) }
|
54
|
+
|
55
|
+
# compress the *.wdgt folder and return the full path to the zip archive
|
56
|
+
compress(path)
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
# Compresses the widget folder to a zip for downloading. Zip file will be created within the *.wdgt folder.
|
62
|
+
# path: full path to *.wdgt folder
|
63
|
+
def compress(path)
|
64
|
+
gem 'rubyzip'
|
65
|
+
require 'zip/zip'
|
66
|
+
require 'zip/zipfilesystem'
|
67
|
+
|
68
|
+
path.sub!(%r[/$],'')
|
69
|
+
archive = File.join(path,File.basename(path))+'.zip'
|
70
|
+
FileUtils.rm archive, :force=>true
|
71
|
+
|
72
|
+
Zip::ZipFile.open(archive, 'w') do |zipfile|
|
73
|
+
Dir["#{path}/**/**"].reject{|f|f==archive}.each do |file|
|
74
|
+
zipfile.add(file.sub(path+'/',''),file)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
archive
|
78
|
+
end
|
79
|
+
|
80
|
+
# Generate plist for widget
|
81
|
+
# TODO: will need to pass in parameters to set some of the variables in here (i.e. bundle name, bundle identifier, etc)
|
82
|
+
def plist_content(display_name, bundle_identifier, bundle_name)
|
83
|
+
plist = {
|
84
|
+
CFBundleDevelopmentRegion: 'English',
|
85
|
+
CFBundleDisplayName: display_name,
|
86
|
+
CFBundleIdentifier: bundle_identifier,
|
87
|
+
CFBundleName: bundle_name,
|
88
|
+
CFBundleShortVersionString: '1.0',
|
89
|
+
CFBundleVersion: '1.0',
|
90
|
+
CloseBoxInsetX: 15,
|
91
|
+
CloseBoxInsetY: 15,
|
92
|
+
Height: 768,
|
93
|
+
MainHTML: 'main.html',
|
94
|
+
Width: 1024
|
95
|
+
}.to_plist
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'app/models/widget_bundle'
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: widget_bundler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Franken
|
8
|
+
- Brandon Fulk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: haml
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 4.0.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 4.0.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rubyzip
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: plist
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: Creates widget for iBook using html, javascript, stylesheet and images
|
85
|
+
files
|
86
|
+
email:
|
87
|
+
- nf@the42.com
|
88
|
+
- bf@the42.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- lib/widget_bundler.rb
|
94
|
+
- lib/app/models/widget_bundle.rb
|
95
|
+
homepage:
|
96
|
+
licenses: []
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.0.3
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Packages files into widget for iBook
|
118
|
+
test_files: []
|