Blogtext
This Ruby gem converts a text file with specific format into HTML code.
Installation
Add this line to your application's Gemfile:
gem 'blogtext'
And then execute:
$ bundle
Or install it yourself as:
$ gem install blogtext
Usage
There are two main static methods:
Blogtext::convert(<path_to_file>)
, used to get the HTML for a certain file.Blogtext::cli_convert
, used to get a file (at the same directory as the original text file) with the HTML content corresponding to the original text file. This method receives no parameters, because it use ARGV[0] as file name, i.e., the first parameter after the program name at command line.
In order to help command line usage, an executable named blogtext
was added. It invokes Blogtext::cli_convert
and generates the corresponding HTML file for the text file given. To convert a text file, just type at command line:
$ blogtext <path/to/file/filename.txt>
The path may be absolute or relative. The HTML file will be created at the same directory of the original file.
The text file format
- First line is always the article title and it is enclosed with
<h1></h1>
in the final result. - Second like is always the article subtitle and it is enclosed with
<h3></h3>
in the final result. - A line may start with
[image]
followed by a valid link to an image file. - A line may start with
[video]
followed by a valid pure Youtube link to a video. - A line may start with
[quote]
followed by a quote string. - If none of these things happen, the line is enclosed with
<p></p>
.
The 'pure' means we can't have, by now, any other URI parameters, then
- https://www.youtube.com/watch?v=T2T5_seDNZE is 'pure'; but,
- https://www.youtube.com/watch?v=FgeKokAh9Ns&t=520s is not 'pure', because we have the '&t=520s' part.
TODO
- Support non-'pure' Youtube URLs;
- Support other video providers;
- Support links in the middle of paragraphs.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/EdDeAlmeidaJr/blogtext.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Blogtext project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.