Orgas: export common variables, functions and statement outside gen.sh
This commit is contained in:
		
							
								
								
									
										45
									
								
								orgas/commons.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								orgas/commons.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#
 | 
			
		||||
# COMMONS variables, functions and statements for differents graphs
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
# Built variables
 | 
			
		||||
outputfile="$1"
 | 
			
		||||
SRC_DIR="${RERO_DIR}/data/"
 | 
			
		||||
 | 
			
		||||
# Templates
 | 
			
		||||
tmpl_gizmo="templates/gizmo.tmpl" # A colored polygon. Represents an entity.
 | 
			
		||||
tmpl_link="templates/link.tmpl"   # A link between two entities.
 | 
			
		||||
tmpl_label="templates/label_default.tmpl" # Default label for entities.
 | 
			
		||||
 | 
			
		||||
# Graph info
 | 
			
		||||
rankdir="RL"
 | 
			
		||||
title=""
 | 
			
		||||
 | 
			
		||||
# TESTS
 | 
			
		||||
if [[ -z "${outputfile}" ]]; then
 | 
			
		||||
  echo "No output file given"
 | 
			
		||||
  exit 1
 | 
			
		||||
elif [[ -f "${outputfile}" ]]; then
 | 
			
		||||
  echo "File already exists!"
 | 
			
		||||
  exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# FUNCTIONS
 | 
			
		||||
# WRITE first argument in output file
 | 
			
		||||
send() {
 | 
			
		||||
  echo -e "$1" >> "$outputfile"
 | 
			
		||||
}
 | 
			
		||||
# render: SHOW template (given in $1) after variables REPLACEMENTS
 | 
			
		||||
render() {
 | 
			
		||||
  template="$(cat $1)"
 | 
			
		||||
  eval "echo -e \"${template}\""
 | 
			
		||||
}
 | 
			
		||||
# save: WRITE template (given in $1) in outputfile after variables REPLACEMENTS
 | 
			
		||||
save() {
 | 
			
		||||
  rendered_template="$(render $1)"
 | 
			
		||||
  send "${rendered_template}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Output file initialization
 | 
			
		||||
echo "" > "$outputfile" # flush output file
 | 
			
		||||
							
								
								
									
										39
									
								
								orgas/gen.sh
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								orgas/gen.sh
									
									
									
									
									
								
							@@ -25,40 +25,11 @@ LIB_COLOR="${COLOR2}"     # libraries
 | 
			
		||||
PT_COLOR="${COLOR3}"      # patron_types
 | 
			
		||||
USER_COLOR="${COLOR5}"    # users/patrons
 | 
			
		||||
 | 
			
		||||
# Built variables
 | 
			
		||||
outputfile="$1"
 | 
			
		||||
SRC_DIR="${RERO_DIR}/data/"
 | 
			
		||||
tmpl_gizmo="templates/gizmo.tmpl" # A colored polygon. Represents an entity.
 | 
			
		||||
tmpl_link="templates/link.tmpl"   # A link between two entities.
 | 
			
		||||
tmpl_label="templates/label_default.tmpl" # Default label for entities.
 | 
			
		||||
# Load commons variables, functions and statements
 | 
			
		||||
source commons.sh
 | 
			
		||||
 | 
			
		||||
# TESTS
 | 
			
		||||
if [[ -z "${outputfile}" ]]; then
 | 
			
		||||
  echo "No output file given"
 | 
			
		||||
  exit 1
 | 
			
		||||
elif [[ -f "${outputfile}" ]]; then
 | 
			
		||||
  echo "File already exists!"
 | 
			
		||||
  exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# FUNCTIONS
 | 
			
		||||
# WRITE first argument in output file
 | 
			
		||||
send() {
 | 
			
		||||
  echo -e "$1" >> "$outputfile"
 | 
			
		||||
}
 | 
			
		||||
# render: SHOW template (given in $1) after variables REPLACEMENTS
 | 
			
		||||
render() {
 | 
			
		||||
  template="$(cat $1)"
 | 
			
		||||
  eval "echo -e \"${template}\""
 | 
			
		||||
}
 | 
			
		||||
# save: WRITE template (given in $1) in outputfile after variables REPLACEMENTS
 | 
			
		||||
save() {
 | 
			
		||||
  rendered_template="$(render $1)"
 | 
			
		||||
  send "${rendered_template}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Output file initialization
 | 
			
		||||
echo "" > "$outputfile" # flush output file
 | 
			
		||||
# Graph header
 | 
			
		||||
title="Link between organisations, libraries and users."
 | 
			
		||||
save "templates/header.tmpl"
 | 
			
		||||
 | 
			
		||||
# ORGANISATIONS
 | 
			
		||||
@@ -188,7 +159,7 @@ do
 | 
			
		||||
  fi
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# end of file
 | 
			
		||||
# Graph footer
 | 
			
		||||
save "templates/footer.tmpl"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,3 @@
 | 
			
		||||
digraph {
 | 
			
		||||
rankdir = RL;
 | 
			
		||||
label = \"Link between organisations, libraries and users.\";
 | 
			
		||||
rankdir = ${rankdir};
 | 
			
		||||
label = \"${title}\";
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user