-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
159 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env ruby | ||
require 'mixer' | ||
require 'optparse' | ||
|
||
|
||
options = {} | ||
optparse = OptionParser.new do|opts| | ||
opts.banner = "Usage: mixit [-o outputfile -i inputfile -t templatefile]" | ||
opts.on( '-i', '--input FILE', 'json Inputfile' ) do|p| | ||
options[:inputfile] = p | ||
end | ||
|
||
opts.on( '-o', '--output FILE', 'mixed outputfile' ) do|p| | ||
options[:outputfile] = p | ||
end | ||
|
||
|
||
opts.on( '-t', '--template directory', 'place where the templates are' ) do|p| | ||
options[:templateDir] = p | ||
end | ||
|
||
end.parse! | ||
|
||
|
||
mixer = MIX::Mixer.new | ||
|
||
input_string = IO.read(options["inputfile"]) | ||
outputfile = File.new(options["outputfile"]) | ||
inputdata = JSON.pars(input_string) | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Gem::Specification.new do |s| | ||
s.name = 'mixItRuby' | ||
s.version = '0.0.0' | ||
s.date = '2014-05-29' | ||
s.summary = "MitItRuby!" | ||
s.description = "A gem for mixing a nested json structure in erb files" | ||
s.authors = ["Erhard Karger"] | ||
s.email = '[email protected]' | ||
s.files = ["lib/mixer.rb"] | ||
s.homepage = "www.kargers.org" | ||
'http://rubygems.org/gems/mixItRuby' | ||
s.license = 'MIT' | ||
git_files = `git ls-files`.split("\n") rescue '' | ||
s.files = git_files | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = %w(mixit) | ||
s.require_paths = ["lib"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,52 +9,78 @@ Example Use Case | |
---------------- | ||
You have to print bills for a list of items/products. | ||
What you do : | ||
Transform the data to a hash which lasts a specific form | ||
Transform the data to a hash which lasts a specific form | ||
Run mix with a erb template. Viola the output is (depending on the template) | ||
ready to be formatted in latex of whatever. | ||
ready to be formatted in latex of whatever. | ||
|
||
But whatever...... | ||
But whatever...... | ||
|
||
|
||
|
||
Install | ||
------- | ||
gem mix | ||
Install | ||
------- | ||
gem mix | ||
|
||
run (form commandline) | ||
----------------------- | ||
mix inputfile template outputfile | ||
----------------------- | ||
mix inputfile template outputfile | ||
|
||
|
||
run withing a programm | ||
---------------------- | ||
run withing a programm | ||
---------------------- | ||
|
||
|
||
current project status | ||
---------------------- | ||
Work in progress just started | ||
current project status | ||
---------------------- | ||
Work in progress just started | ||
|
||
|
||
You want to contributes ? | ||
========================== | ||
Contact [email protected] | ||
You want to contributes ? | ||
========================== | ||
Contact [email protected] | ||
|
||
|
||
|
||
|
||
Structure of the data | ||
===================== | ||
Structure of the data | ||
===================== | ||
|
||
json Format recursive, selfcontained. | ||
json Format recursive, selfcontained. | ||
|
||
recursive : substructures possible (nodes) | ||
selfcontained : The name of the erb (id, for DB or File or whatever) is within the data | ||
selfcontained : The name of the erb (id, for DB or File or whatever) is within the data | ||
|
||
Here an example: | ||
|
||
{"id":"adress.erb","name":"Bond","prename":"James", | ||
"items": | ||
[ | ||
{"id":"item.erb","product":"car1","prize":"10"}, | ||
{"id":"item.erb","product":"car2","prize":"11"} | ||
] | ||
} | ||
|
||
A building block consists of an id and other key value pair. | ||
|
||
id: is a must. It represents the Identifier under which the template is accesible. | ||
At the moment it is a filename. The other attributes on the same level, which are no array or hash are | ||
the key value pais which fill the erb. | ||
The adress.erb looks like this | ||
<%=name%>, <%=prename%> | ||
Then an array follow. An Array must be build of hashes, which can have subarrays or like in the example building blocks again. | ||
|
||
|
||
What is mixItRuby needed for ? | ||
============================== | ||
With that little gem you can build up personalized letters or emails or html pages. | ||
Just imagine the erb file are tex files or xmlfo or html files or they are files with are ruby file again, which produce some output. | ||
There are a lot of posibilities. | ||
|
||
|
||
|
||
|
||
Licence: | ||
MIT | ||
|
||
Author: | ||
Erhard Karger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"id":"adress.erb","name":"Bond","prename":"James","items":[{"id":"item.erb","product":"car1","prize":"10"},{"id":"item.erb","product":"car2","prize":"11"}]} |