Class: HtmlMockup::Release::Injector
- Inherits:
-
Object
- Object
- HtmlMockup::Release::Injector
- Defined in:
- lib/html_mockup/release/injector.rb
Overview
Inject CHANGELOG r.inject(=> {:file => “”, :filter => BlueCloth}, :into => %w_doc/changelog_doc/changelog.html)
Instance Method Summary collapse
- #call(release, options = {}) ⇒ Object
- #get_complex_injection(injection, release) ⇒ Object
- #get_content(injection, release) ⇒ Object
-
#initialize(variables, options) ⇒ Injector
constructor
Processors are based on Tilt (github.com/rtomayko/tilt).
Constructor Details
#initialize(variables, options) ⇒ Injector
Processors are based on Tilt (github.com/rtomayko/tilt). Currently supported/tested processors are:
-
‘md’ for Markdown (bluecloth)
Injection files are relative to the :source_path
38 39 40 41 |
# File 'lib/html_mockup/release/injector.rb', line 38 def initialize(variables, ) @variables = variables @options = end |
Instance Method Details
#call(release, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/html_mockup/release/injector.rb', line 43 def call(release, = {}) @options.update() files = release.get_files(@options[:into]) files.each do |f| c = File.read(f) injected_vars = [] @variables.each do |variable, injection| if c.gsub!(variable, get_content(injection, release)) injected_vars << variable end end release.log(self, "Injected variables #{injected_vars.inspect} into #{f}") if injected_vars.size > 0 File.open(f,"w") { |fh| fh.write c } end end |
#get_complex_injection(injection, release) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/html_mockup/release/injector.rb', line 76 def get_complex_injection(injection, release) if injection[:file] content = File.read(release.source_path + injection[:file]) else content = injection[:content] end raise ArgumentError, "No :content or :file specified" if !content if injection[:processor] if tmpl = Tilt[injection[:processor]] (tmpl.new{ content }).render else raise ArgumentError, "Unknown processor #{injection[:processor]}" end else content end end |
#get_content(injection, release) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/html_mockup/release/injector.rb', line 61 def get_content(injection, release) case injection when String injection when Hash get_complex_injection(injection, release) else if injection.respond_to?(:to_s) injection.to_s else raise ArgumentError, "Woah, what's this? #{injection.inspect}" end end end |