widget_bundler 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/app/models/widget_bundle.rb +32 -7
  3. metadata +29 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MThiMmU0NjUwODIxNjY1MmMyMzNmZDhkYjM1NzU5OTQ4MjExY2YyZQ==
4
+ OWIxYmZkNDAwOTUyYjViNjJhODI0ZDY2Yjk1YzUyZTE3MDRhZDAwMg==
5
5
  data.tar.gz: !binary |-
6
- YmQ4MDc2YTc3ODU2ODRiMTExMGQ3YjNiNTk2M2YzZWMzMWNjYmE3YQ==
6
+ MzEyN2VjZWQ1MTNjMzc3YWJiNGNiZDViYzRiNWNkNWY3NWVlNGRiYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDhjYjc4YzUwMjM4MmUxZWNkYTc3YTk3ZmRiYTg4YzYxYzI4N2I3MzQwNzI5
10
- ZjFkODhkNjZiNTQ0ZDNmYzI4ZmU2ZDgyYTc3ZTMxZWI3YzJkMjU0Mzg3Y2Uy
11
- NDIyYzQyN2NlMjJjOTFhZGRiOTlkZGI2YTdhNTc2MDk0YjM2ZDY=
9
+ Y2FjY2I2OTY3MTY4NDdmYWQxZDYwZjYzMDZiMjZiZGJjYWVmY2Q2NWRiZDI0
10
+ ZTZiZWNhNjA2NTRjM2VhMWQ1M2UyYjZjNDBjZGUzNzQ3ZmYzZGFmODVlYjMy
11
+ ZDlmYjI0ZTMxM2E1ZjdhOTYzMjE0MzdjZjVjMmRlMzE5MzQ5YzM=
12
12
  data.tar.gz: !binary |-
13
- ZWRjMmM3ZGM5ZTlkODA1OWYxNWYxYzAzOTE0NDg4ODUxYzNkMTdlZmUzZDNj
14
- Y2IzMjQ3YTQ3MThiNTk3OGFhODI3ZGFkMTg0OGViMGMyMzc3ZDRjZTgzZWYw
15
- MGJlMjEwNTgzYjFlYTY5NzgwZmI1YmRhZTg4OWFiOWJkNjRkOWE=
13
+ ODdjYmUwZmU4M2I4OTQ1OWFmZTRlMTQ3M2M3N2ViMzRiZTc2ZDI3YjZjNmQy
14
+ NGIzZWI4ODZhOWFmNWQ0YTNkMWI3ZmIxMjk2ZmFjNDMxYTY1MWUzYjFjY2Rl
15
+ NDA0NWFmODdkNzRlNTkwOGEyNDMxZGUzMDZlMGUyMWQzZDY3NDY=
@@ -1,11 +1,13 @@
1
1
  #
2
2
  # Class for packaging set of html, javascript, image and stylesheet files into a widget for an iBook
3
3
  # => accepts an array of images, stylesheets and javascripts as full paths
4
- # => images should be paperclip .url method path
4
+ # => images should be paperclip .url method path (gem assumes "#{Rails.root}/public" path for images)
5
5
  # => acceps main haml file as string (fullpath)
6
6
  #
7
7
  require 'active_model'
8
8
  require 'plist'
9
+ require 'uglifier'
10
+ require 'sass'
9
11
 
10
12
  class WidgetBundle
11
13
 
@@ -33,7 +35,6 @@ class WidgetBundle
33
35
  FileUtils.mkdir_p path
34
36
 
35
37
  # make requred directories
36
- # images_dir = FileUtils.mkdir("#{path}/")[0]
37
38
  images_dir = path
38
39
  css_js_dir = FileUtils.mkdir("#{path}/assets/")[0]
39
40
 
@@ -48,11 +49,11 @@ class WidgetBundle
48
49
  end
49
50
  end
50
51
 
51
- # copy stylesheets
52
- FileUtils.cp stylesheets, css_js_dir if stylesheets
52
+ # minify stylesheets
53
+ minify_stylesheets(stylesheets, css_js_dir)
53
54
 
54
- # copy javascripts
55
- FileUtils.cp javascripts, css_js_dir if javascripts
55
+ # minify javascripts
56
+ minify_javascripts(javascripts, css_js_dir)
56
57
 
57
58
  # create Info.plist
58
59
  File.open("#{path}/Info.plist", "w") { |file| file.write(plist_content(display_name, bundle_identifier, bundle_name)) }
@@ -67,6 +68,30 @@ class WidgetBundle
67
68
 
68
69
  protected
69
70
 
71
+ # Minify stylesheets into one file
72
+ #
73
+ def minify_stylesheets(stylesheets, path)
74
+ out = ''
75
+ stylesheets.each do |css|
76
+ out << Sass::Engine.new(File.open(css).read, syntax: :scss, style: :compressed).render
77
+ end
78
+
79
+ # write the main.css file
80
+ File.open("#{path}/main.css", 'w'){|file| file.write(out) }
81
+ end
82
+
83
+ # Minify javascripts into one file
84
+ #
85
+ def minify_javascripts(javascripts, path)
86
+ out = ''
87
+ javascripts.each do |js|
88
+ out << Uglifier.compile(File.read(js))
89
+ end
90
+
91
+ # write the main.js file
92
+ File.open("#{path}/main.js", 'w'){|file| file.write(out) }
93
+ end
94
+
70
95
  # Compresses the widget folder to a zip for downloading. Zip file will be created within the *.wdgt folder.
71
96
  # path: full path to *.wdgt folder
72
97
  def compress(path)
@@ -87,7 +112,7 @@ class WidgetBundle
87
112
  end
88
113
 
89
114
  # Generate plist for widget
90
- # TODO: will need to pass in parameters to set some of the variables in here (i.e. bundle name, bundle identifier, etc)
115
+ #
91
116
  def plist_content(display_name, bundle_identifier, bundle_name)
92
117
  plist = {
93
118
  CFBundleDevelopmentRegion: 'English',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widget_bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Franken
@@ -53,6 +53,34 @@ dependencies:
53
53
  - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: uglifier
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
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: sass-rails
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
56
84
  - !ruby/object:Gem::Dependency
57
85
  name: rake
58
86
  requirement: !ruby/object:Gem::Requirement