HtmlInjector
A simple class that I'm going to use in other project to inject some custom html into a few already generated HTML files
Installation
Add this line to your application's Gemfile:
gem 'html_injector'
And then execute:
$ bundle
Or install it yourself as:
$ gem install html_injector
Usage
Simple usage:
require 'html_injector'
doc = HtmlInjector.new('<h1 class="test">This is a test</h1><h1>This is the end</h1>')
res = doc.inject_code({
tag: 'h1',
css_identifier: 'test',
node_to_inject: 'h2',
code_to_inject: 'injected'
})
p res
Will output:
"<h1 class=\"test\">This is a test</h1><h2>injected</h2><h1>This is the end</h1>"
You can also write the output directly to a file
require 'html_injector'
doc = HtmlInjector.new('<h1 class="test">This is a test</h1><h1>This is the end</h1>')
res = doc.inject_and_write_file({
tag: 'h1',
css_identifier: 'test',
node_to_inject: 'h2',
code_to_inject: 'injected'
}, './new_output.html')
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request