Class: HtmlMockup::Release
- Inherits:
-
Object
- Object
- HtmlMockup::Release
- Defined in:
- lib/html_mockup/release.rb
Defined Under Namespace
Modules: Finalizers, Processors, Scm Classes: Cleaner, Injector
Instance Attribute Summary collapse
-
#cleanups ⇒ Object
readonly
Returns the value of attribute cleanups.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#finalizers ⇒ Object
readonly
Returns the value of attribute finalizers.
-
#injections ⇒ Object
readonly
Returns the value of attribute injections.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Class Method Summary collapse
-
.camel_case(string) ⇒ Object
Nothing genius adjusted from: stackoverflow.com/questions/9524457/converting-string-from-snake-case-to-camel-case-in-ruby.
- .default_finalizers ⇒ Object
- .default_stack ⇒ Object
-
.get_callable(callable, scope) ⇒ Object
Makes callable into a object that responds to call.
Instance Method Summary collapse
-
#banner(options = {}, &block) ⇒ Object
Generates a banner if a block is given, or returns the currently set banner.
-
#build_path ⇒ Object
Accessor for build_path The build_path is a temporary directory where the release will be built.
-
#cleanup(pattern) ⇒ Object
Files to clean up in the build directory just before finalization happens.
- #debug(part, msg, &block) ⇒ Object
-
#extract(options = {}) ⇒ Object
deprecated
Deprecated.
Don’t use the extractor anymore, use release.use(:mockup, options) processor
-
#finalize(finalizer, options = {}) ⇒ Object
Write out the whole release into a directory, zip file or anything you can imagine #finalize can be called multiple times, it just will run all of them.
- #get_files(globs, excludes = []) ⇒ Object
-
#initialize(project, config = {}) ⇒ Release
constructor
A new instance of Release.
-
#inject(variables, options) ⇒ Object
Inject variables into files with an optional filter.
-
#log(part, msg, verbose = false, &block) ⇒ Object
Write out a log message.
-
#run! ⇒ Object
Actually perform the release.
-
#scm(force = false) ⇒ Object
Get the current SCM object.
-
#source_path ⇒ Object
Accessor for source_path The source path is the root of the mockup.
-
#target_path ⇒ Object
Accessor for target_path The target_path is the path where the finalizers will put the release.
-
#use(processor, options = {}) ⇒ Object
Use a certain pre-processor.
-
#warn(part, msg) ⇒ Object
Write out a warning message.
Constructor Details
#initialize(project, config = {}) ⇒ Release
Returns a new instance of Release.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/html_mockup/release.rb', line 60 def initialize(project, config = {}) defaults = { :scm => :git, :source_path => Pathname.new(Dir.pwd) + "html", :target_path => Pathname.new(Dir.pwd) + "releases", :build_path => Pathname.new(Dir.pwd) + "build", :cleanup_build => true } @config = {}.update(defaults).update(config) @project = project @stack = [] @finalizers = [] end |
Instance Attribute Details
#cleanups ⇒ Object (readonly)
Returns the value of attribute cleanups.
8 9 10 |
# File 'lib/html_mockup/release.rb', line 8 def cleanups @cleanups end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/html_mockup/release.rb', line 6 def config @config end |
#finalizers ⇒ Object (readonly)
Returns the value of attribute finalizers.
8 9 10 |
# File 'lib/html_mockup/release.rb', line 8 def finalizers @finalizers end |
#injections ⇒ Object (readonly)
Returns the value of attribute injections.
8 9 10 |
# File 'lib/html_mockup/release.rb', line 8 def injections @injections end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
6 7 8 |
# File 'lib/html_mockup/release.rb', line 6 def project @project end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
8 9 10 |
# File 'lib/html_mockup/release.rb', line 8 def stack @stack end |
Class Method Details
.camel_case(string) ⇒ Object
Nothing genius adjusted from: stackoverflow.com/questions/9524457/converting-string-from-snake-case-to-camel-case-in-ruby
49 50 51 52 |
# File 'lib/html_mockup/release.rb', line 49 def camel_case(string) return string if string !~ /_/ && string =~ /[A-Z]+.*/ string.split('_').map{|e| e.capitalize}.join end |
.default_finalizers ⇒ Object
16 17 18 |
# File 'lib/html_mockup/release.rb', line 16 def default_finalizers [[self.get_callable(:dir, HtmlMockup::Release::Finalizers), {}]] end |
.default_stack ⇒ Object
12 13 14 |
# File 'lib/html_mockup/release.rb', line 12 def default_stack [] end |
.get_callable(callable, scope) ⇒ Object
Makes callable into a object that responds to call.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/html_mockup/release.rb', line 24 def get_callable(callable, scope) return callable if callable.respond_to?(:call) if callable.kind_of?(Symbol) callable = camel_case(callable.to_s).to_sym if scope.constants.include?(callable) c = scope.const_get(callable) callable = c if c.is_a?(Class) end end if callable.kind_of?(Class) callable = callable.new end if callable.respond_to?(:call) callable else raise ArgumentError, "Could not resolve #{callable.inspect}. Callable must be an object that responds to #call or a symbol that resolve to such an object or a class with a #call instance method." end end |
Instance Method Details
#banner(options = {}, &block) ⇒ Object
Generates a banner if a block is given, or returns the currently set banner. It automatically takes care of adding comment marks around the banner.
The default banner looks like this:
Version : v1.0.0 =
Date : 2012-06-20 =
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/html_mockup/release.rb', line 163 def ( = {}, &block) = { :comment => :js }.update() if block_given? @_banner = yield.to_s elsif !@_banner = [] << "Version : #{self.scm.version}" << "Date : #{self.scm.date.strftime("%Y-%m-%d")}" size = .inject(0){|mem,b| b.size > mem ? b.size : mem } .map!{|b| "= #{b.ljust(size)} =" } div = "=" * .first.size .unshift(div) << div @_banner = .join("\n") end if [:comment] self.comment(@_banner, :style => [:comment]) else @_banner end end |
#build_path ⇒ Object
Accessor for build_path The build_path is a temporary directory where the release will be built
87 88 89 |
# File 'lib/html_mockup/release.rb', line 87 def build_path Pathname.new(self.config[:build_path]) end |
#cleanup(pattern) ⇒ Object
Files to clean up in the build directory just before finalization happens
147 148 149 |
# File 'lib/html_mockup/release.rb', line 147 def cleanup(pattern) @stack << Cleaner.new(pattern) end |
#debug(part, msg, &block) ⇒ Object
237 238 239 |
# File 'lib/html_mockup/release.rb', line 237 def debug(part, msg, &block) self.log(part, msg, true, &block) end |
#extract(options = {}) ⇒ Object
Don’t use the extractor anymore, use release.use(:mockup, options) processor
Extract the mockup, this will happen anyway, and will always happen first This method gives you a way to pass options to the extractor.
196 197 198 199 |
# File 'lib/html_mockup/release.rb', line 196 def extract( = {}) self.warn(self, "Don't use the extractor anymore, use release.use(:mockup, options) and release.use(:url_relativizer, options) processors") @extractor_options = end |
#finalize(finalizer, options = {}) ⇒ Object
Write out the whole release into a directory, zip file or anything you can imagine #finalize can be called multiple times, it just will run all of them.
The default finalizer is :dir
137 138 139 |
# File 'lib/html_mockup/release.rb', line 137 def finalize(finalizer, = {}) @finalizers << [self.class.get_callable(finalizer, HtmlMockup::Release::Finalizers), ] end |
#get_files(globs, excludes = []) ⇒ Object
249 250 251 252 253 254 255 256 |
# File 'lib/html_mockup/release.rb', line 249 def get_files(globs, excludes = []) files = globs.map{|g| Dir.glob(self.build_path + g) }.flatten if excludes.any? files.reject{|c| excludes.detect{|e| e.match(c) } } else files end end |
#inject(variables, options) ⇒ Object
Inject variables into files with an optional filter
116 117 118 |
# File 'lib/html_mockup/release.rb', line 116 def inject(variables, ) @stack << Injector.new(variables, ) end |
#log(part, msg, verbose = false, &block) ⇒ Object
Write out a log message
223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/html_mockup/release.rb', line 223 def log(part, msg, verbose = false, &block) if !verbose || verbose && self.project.[:verbose] self.project.shell.say "\033[37m#{part.class.to_s}\033[0m" + " : " + msg.to_s, nil, true end if block_given? begin self.project.shell.padding = self.project.shell.padding + 1 yield ensure self.project.shell.padding = self.project.shell.padding - 1 end end end |
#run! ⇒ Object
Actually perform the release
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/html_mockup/release.rb', line 202 def run! # Validate paths validate_paths! # Extract mockup copy_source_path_to_build_path! validate_stack! # Run stack run_stack! # Run finalizers run_finalizers! # Cleanup cleanup! if self.config[:cleanup_build] end |
#scm(force = false) ⇒ Object
Get the current SCM object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/html_mockup/release.rb', line 100 def scm(force = false) return @_scm if @_scm && !force case self.config[:scm] when :git @_scm = Release::Scm::Git.new(:path => self.source_path) else raise "Unknown SCM #{[:scm].inspect}" end end |
#source_path ⇒ Object
Accessor for source_path The source path is the root of the mockup
95 96 97 |
# File 'lib/html_mockup/release.rb', line 95 def source_path Pathname.new(self.config[:source_path]) end |
#target_path ⇒ Object
Accessor for target_path The target_path is the path where the finalizers will put the release
79 80 81 |
# File 'lib/html_mockup/release.rb', line 79 def target_path Pathname.new(self.config[:target_path]) end |
#use(processor, options = {}) ⇒ Object
Use a certain pre-processor
124 125 126 |
# File 'lib/html_mockup/release.rb', line 124 def use(processor, = {}) @stack << [self.class.get_callable(processor, HtmlMockup::Release::Processors), ] end |
#warn(part, msg) ⇒ Object
Write out a warning message
242 243 244 |
# File 'lib/html_mockup/release.rb', line 242 def warn(part, msg) self.project.shell.say "\033[37m#{part.class.to_s}\033[0m" + " : " + "\033[31m#{msg.to_s}\033[0m", nil, true end |