kreegerator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -7
- data/lib/kreegerator/cli.rb +2 -2
- data/lib/kreegerator/renderable.rb +26 -24
- data/lib/kreegerator/retina.rb +6 -2
- data/lib/kreegerator/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
# Kreegerator
|
2
2
|
|
3
|
-
A set of generators for various projects I work on.
|
3
|
+
A set of generators and batch processors for various projects I work on.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
Install it as a gem!
|
8
8
|
|
9
|
-
gem
|
9
|
+
gem install kreegerator
|
10
10
|
|
11
|
-
|
11
|
+
Then run the command to see which functions are available.
|
12
12
|
|
13
|
-
|
13
|
+
Tasks:
|
14
|
+
kreegerator help [TASK] # Describe available tasks or one specific task
|
15
|
+
kreegerator ios TEMPLATE CLASS_NAME # fire off an iOS generator
|
16
|
+
kreegerator retina ACTION GLOB # handles image adjustments for retina displays
|
14
17
|
|
15
|
-
|
18
|
+
To see subfunctions...
|
16
19
|
|
17
|
-
|
20
|
+
kreegerator [TASK] list
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
data/lib/kreegerator/cli.rb
CHANGED
@@ -22,8 +22,8 @@ class Kreegerator::CLI < Thor
|
|
22
22
|
end
|
23
23
|
|
24
24
|
desc 'retina ACTION GLOB', 'handles image adjustments for retina displays'
|
25
|
-
method_option :pngnq, desc: 'Runs the files through pngnq as well.'
|
26
|
-
def retina(method_name, glob)
|
25
|
+
method_option :pngnq, desc: 'Runs the files through pngnq as well.'
|
26
|
+
def retina(method_name, glob=nil)
|
27
27
|
if Kreegerator::Retina.respond_to?(method_name.to_sym)
|
28
28
|
if method_name == 'list'
|
29
29
|
Kreegerator::Retina.send(method_name.to_sym)
|
@@ -4,35 +4,37 @@ require 'erb'
|
|
4
4
|
# This module uses the amazing Tilt library to give the ability to render
|
5
5
|
# a template in the `lib/filemover/templates` directory to any including
|
6
6
|
# class.
|
7
|
-
module Kreegerator
|
7
|
+
module Kreegerator
|
8
|
+
module Renderable
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
# Accepts path to a template relative to `lib/filemover/templates` along
|
11
|
+
# with a hash and renders a template using the amazing and magical Tilt.
|
12
|
+
#
|
13
|
+
# @param [String] template the relative path to the template, from
|
14
|
+
# `lib/filemover/templates`.
|
15
|
+
# @param [Hash] data the hash of values to render. The keys will be sent
|
16
|
+
# to the template as instance variables `@like_this`.
|
17
|
+
def render(template, data)
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
# META! Assign instance variables to self using the hash passed in.
|
20
|
+
data.each { |key, value| instance_variable_set "@#{key}", value }
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
# Get the absolute template location relative to our template basepath.
|
23
|
+
template_location = File.join(template_path, template)
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
# Let Tilt do the rest. Also pass in `self` as that's the reference to
|
26
|
+
# the object that holds our new, metaprogrammed `@instance_variables`.
|
27
|
+
Tilt.new(template_location).render(self)
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
+
protected
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
# A helper that provides the absolute path to `Filemover`'s master template
|
33
|
+
# directory at `lib/filemover/templates`.
|
34
|
+
#
|
35
|
+
# @return [String] the absolute path of the `templates` directory.
|
36
|
+
def template_path
|
37
|
+
File.expand_path('../../../templates', __FILE__)
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
data/lib/kreegerator/retina.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'fileutils'
|
2
2
|
require 'mini_magick'
|
3
3
|
|
4
4
|
class Kreegerator::Retina
|
@@ -10,6 +10,10 @@ class Kreegerator::Retina
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def downscale(glob, opts)
|
13
|
+
if glob.nil?
|
14
|
+
puts "You must specify a file match glob (like 'tmp/*.png') or I won't know what to do!"
|
15
|
+
return
|
16
|
+
end
|
13
17
|
Dir[glob].select { |f| f =~ /\.png\Z/i }.each do |file|
|
14
18
|
puts "Downscaling #{file}."
|
15
19
|
scale_image file, 0.5, true
|
@@ -31,7 +35,7 @@ class Kreegerator::Retina
|
|
31
35
|
def crunch_image(file, colors)
|
32
36
|
puts "Crunching image #{file}."
|
33
37
|
cmd = "pngnq #{file} -f -s 1"
|
34
|
-
cmd << " -n #{colors}" unless colors.nil?
|
38
|
+
cmd << " -n #{colors.to_i}" unless colors.nil?
|
35
39
|
system cmd
|
36
40
|
end
|
37
41
|
|
data/lib/kreegerator/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kreegerator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
segments:
|
114
114
|
- 0
|
115
|
-
hash:
|
115
|
+
hash: -197103691425396573
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash:
|
124
|
+
hash: -197103691425396573
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
127
|
rubygems_version: 1.8.23
|