make_index Namespace Reference

Functions

def get_key_and_link (entry)
 
def print_key (doc_root_directory, key, level, anchor)
 
def nested_output (doc_root_directory, index, level=0, anchor="")
 
def make_index (filename, doc_root_directory)
 

Variables

int div_counter = 0
 
 narg = len(sys.argv)
 

Function Documentation

◆ get_key_and_link()

def make_index.get_key_and_link (   entry)
14 def get_key_and_link(entry):
15  #Initialise strings to be empty
16  key=''
17  link=''
18  synonym=''
19  n = len(entry)
20  #If there is only one entry, we only have a key
21  if n==1:
22  key = entry[0]
23  #Otherwise we could have a link or cross reference as well
24  elif n > 1:
25  key = entry[0]
26  #If the entry starts with a % it's a link, find the relative link name
27  if entry[1][0]=='%':
28  link = entry[1].lstrip('%')
29  #If it starts with a ^ it's a cross-ref
30  #Determine the relative hyperlink and
31  #also provide the synonym to which we are referring in synonym
32  elif entry[1][0]=='^':
33  anchor = entry[1].lstrip('^').strip().replace(' ','')
34  synonym = "see entry on " + entry[1].lstrip('^').strip().replace('.',':')
35  link = "index/html/index.html#" + anchor[0].upper() + '.' + anchor
36  return (key,link,synonym)
37 
38 #Output the key and link or cross-reference in pretty format
def get_key_and_link(entry)
Definition: make_index.py:14

Referenced by nested_output().

◆ make_index()

def make_index.make_index (   filename,
  doc_root_directory 
)
177 def make_index(filename,doc_root_directory):
178 
179  main_index = []
180  index_file=open(filename)
181  entire_file = index_file.read().split("@end")
182 
183  #Loop over lines in file split by @end
184  for line in entire_file:
185  #Split into tags
186  entry = line.split('@')
187  # Remove trailing whitespace
188  out = [field.strip() for field in entry]
189  #Add stripped entries to the main list, if they have
190  #Non-null first entry
191  if len(out[0]) > 1:
192  main_index.append(out)
193 
194  #Sort the list
195 # main_index.sort()
196 
197  #Dump the output to a sorted file
198  #sorted_index=open("sorted.idx",'w')
199  #for entry in main_index:
200  # n = len(entry)
201  # for index,field in enumerate(entry):
202  # #If we have a link write a newline first
203  # if field[0]=='^' or field[0]=='%':
204  # sorted_index.write("\n")
205  # #Write the entry
206  # sorted_index.write(field)
207  # #Write the separator
208  # if index!=n-1:
209  # sorted_index.write(" @ ")
210  # else:
211  # sorted_index.write(" @end \n\n")
212  #sorted_index.close()
213 
214  #Add first letters of each key as the first entry in the list
215  for line in main_index:
216  capital = line[0].upper()
217  line.insert(0,capital[0])
218 
219  #Output Quick links to the Alphabet
220  import string
221  first_letters = "<h1>"
222  for char in string.ascii_uppercase:
223  first_letters += "<a href=" + doc_root_directory + \
224  "/index/html/index.html#" + char + ">" + char + "</a>"
225  first_letters += "</h1>"
226  print("\htmlonly")
227  print(first_letters)
228 
229  #Output the list
230  nested_output(doc_root_directory,main_index)
231  print("\endhtmlonly")
232 
233 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet print(const Packet &a)
Definition: GenericPacketMath.h:1166
def nested_output(doc_root_directory, index, level=0, anchor="")
Definition: make_index.py:104
def make_index(filename, doc_root_directory)
Definition: make_index.py:177
void split(const DoubleVector &in_vector, Vector< DoubleVector * > &out_vector_pt)
Definition: double_vector.cc:1413

References nested_output(), Eigen::internal.print(), and oomph::DoubleVectorHelpers.split().

◆ nested_output()

def make_index.nested_output (   doc_root_directory,
  index,
  level = 0,
  anchor = "" 
)
104 def nested_output(doc_root_directory,index,level=0,anchor=""):
105  level += 1
106  #Return when we have no subindex
107  if index == []:
108  return
109  if level>2 :
110  print("<ul>")
111 
112  #The key is the first entry in the first list
113  key = get_key_and_link(index[0])
114  #Initialise subindex
115  subindex=[]
116  #Loop over entries in index
117  for entry in index:
118  #If the key has changed
119  if entry[0] != key[0]:
120  #Make unique anchor from the fields
121  if level == 1:
122  anchor_stem = key[0]
123  anchor = key[0]
124  else:
125  anchor_stem = anchor
126  anchor += "." + key[0]
127 
128  #Output the list we have so far
129  print_key(doc_root_directory,key,level,anchor)
130  nested_output(doc_root_directory,subindex,level,anchor)
131  #Restore to the previous stem anchor
132  anchor = anchor_stem
133 
134  #If there is no key the entry is not a link, so we end the text div
135  if key[1]=='':
136  print("</div>")
137  #Get the new key
138  key = get_key_and_link(entry)
139  #There will only be a subindex entry if we have no link
140  if key[1]=='' and len(entry) > 1:
141  subindex = [entry[1:len(entry)]]
142  else:
143  subindex = []
144  #Othewise the key is the same so add to the subindex list
145  else:
146  if len(entry) > 1:
147  if entry[1][0]=='%':
148  if entry[1].lstrip('%') != key[1]:
149  print("Multiple links for the same key", key[1], "\n")
150  assert 0
151  elif entry[1][0]=='^':
152  #Error trapping here will be a pain, but should be done
153  x=1
154  #Otherwise not a link so add to the subindex
155  else:
156  subindex.append(entry[1:len(entry)])
157 
158  #Output final entry
159  #Make unique anchor from the fields
160  if level == 1:
161  anchor_stem = key[0]
162  anchor = key[0]
163  else:
164  anchor_stem = anchor
165  anchor += "." + key[0]
166  print_key(doc_root_directory,key,level,anchor)
167  nested_output(doc_root_directory,subindex,level,anchor)
168  #Restore to the prevous stem
169  anchor = anchor_stem
170 
171  if key[1]=='':
172  print("</div>")
173  if level>2 :
174  print("</ul>")
175 
176 
def print_key(doc_root_directory, key, level, anchor)
Definition: make_index.py:39

References get_key_and_link(), Eigen::internal.print(), and print_key().

Referenced by make_index().

◆ print_key()

def make_index.print_key (   doc_root_directory,
  key,
  level,
  anchor 
)
39 def print_key(doc_root_directory,key,level,anchor):
40  #Increment the global counter to give unique text block IDs
41  global div_counter
42  div_counter += 1
43  style=""
44  #Set the html styles for the different levels
45  if level == 1:
46  begin_tag = "<h2>"
47  end_tag = "</h2>"
48  elif level == 2:
49  begin_tag = "<h3>"
50  end_tag = "</h3>"
51  #Uncomment to collapse anything below level 1 tags by default
52  # style = " style=\"display:none\""
53  else:
54  begin_tag = "<li>"
55  end_tag = "</li>"
56  #Uncomment to collapse anything below level 1 tags by default
57  # style = " style=\"display:none\""
58 
59  #Create unique tags for html anchors based on the tags in the file
60  #with spaces removed and '.' instead of '@'
61  new_anchor = anchor.replace(' ','')
62  anchor = new_anchor
63  anchor_string = "<a class=\"anchor\" id=\"" \
64  + anchor + "\"></a>"
65  anchor_tag = "<a href=\"#" + anchor + "\">"
66 
67  #If we don't have a link then it's a submenu heading, which we allow to
68  #collapse and uncollapse by the following html magic
69  #The link is to its own anchor so it shouldn't move much, but has the
70  #same look as real links (In the end I found this confusing, so have removed
71  #it)
72  if key[1]=='':
73  print(begin_tag, anchor_string) #, \
74  #Uncomment for self anchor-tag
75  #"\htmlonly",\
76  #anchor_tag, key[0], "</a>"
77  print(key[0])
78  #Uncomment for the collapsing section stuff
79  #print "<a onclick=\"index_toggle(\'div_id",div_counter,"\',\'im_id",\
80  #div_counter,"\')\">", \
81  #"<img src=\"../collapse.png\" id=\"im_id",div_counter,"\">", "</a>",
82  #print "\endhtmlonly"
83  print(end_tag, \
84  "<div id=\"div_id",div_counter,"\"",style,">")
85 
86  #Otherwise just print the link and key
87  else:
88  link_target = doc_root_directory + "/" + key[1]
89  if key[2]=='':
90  output_key = key[0]
91  print(begin_tag, \
92  anchor_string, \
93  "<a href=\"",link_target,"\">",output_key,"</a>",end_tag)
94  else:
95  output_key = key[2]
96  print(begin_tag, \
97  anchor_string, \
98  key[0], "<br> &nbsp; &nbsp; &nbsp; <a href=\"", link_target,"\">",output_key,"</a>",end_tag)
99 
100 #The main nested output function. The idea is to loop through the list
101 #Output the keys and subkeys and keep going until we hit a link
102 #or cross-reference. The index must be sorted before first call of
103 #this function

References Eigen::internal.print().

Referenced by nested_output().

Variable Documentation

◆ div_counter

int make_index.div_counter = 0

◆ narg

make_index.narg = len(sys.argv)