0.0
No commit activity in last 3 years
No release in over 3 years
Simple gem to inject html blocks into already existent html files
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 1.6.0
 Project Readme

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request