Commits

Oben Sonne committed fa9d285

Terming: macro -> variable

Comments (0)

Files changed (1)

 # constants
 # -----------------------------------------------------------------------------
 
-MACRO_CONTENT = "__content__"
-MACRO_ENCODING = "__encoding__"
 MKD_PATT = r'\.(md|mkd|mdown|markdown)$'
 
 # -----------------------------------------------------------------------------
 PAGE_HTML = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 <head>
-    <meta http-equiv="Content-Type" content="text/html; charset={{ %s }}" />
+    <meta http-equiv="Content-Type" content="text/html; charset={{ __encoding__ }}" />
     <title>poole - {{ title }}</title>
     <meta name="description" content="{{ description }}" />
     <meta name="keywords" content="{{ keywords }}" />
          <h2>{{ title }}</h2>
     </div>
     <div id="menu">
-{%%
+{%
 mpages = [p for p in pages if "menu-position" in p]
 mpages.sort(key=lambda p: int(p["menu-position"]))
 
 for p in mpages:
     style = p["title"] == page["title"] and ' class="current"' or ''
-    link = '<a href="%%s">%%s</a>' %% (p["url"], p["title"])
-    print '<span%%s>%%s</span>' %% (style, link)
-%%}
+    link = '<a href="%s">%s</a>' % (p["url"], p["title"])
+    print '<span%s>%s</span>' % (style, link)
+%}
     </div>
-    <div id="content">{{ %s }}</div>
+    <div id="content">{{ __content__ }}</div>
     </div>
     <div id="footer">
         Built with <a href="http://bitbucket.org/obensonne/poole">Poole</a> &middot;
     </div>
 </body>
 </html>
-""" % (MACRO_ENCODING, MACRO_CONTENT)
+"""
 
 EXAMPLE_FILES =  {
 
 markdown than HTML.
 
 Poole sites by default have a navigation menu, like the one above. It contains
-all pages having the *menu-position* macro defined, for instance like this:
+all pages having the *menu-position* variable defined, for instance like this:
 
     menu-position: 1
     ---
     Here starts the normal content of the page, everything above `---` are
-    macro definitions.
+    variable definitions.
 
 This page's file name is `index` but the name shown above is **home**.
-That's because this page has the *title* macro defined to `home`.
+That's because this page has the *title* variable defined to `home`.
 
 [md]: http://daringfireball.net/projects/markdown/
 """,
 "blog.md" : """
 menu-position: 5
 ---
-Poole has basic support for blog posts. The macro `post-list` lists all blog
-posts in your site project. Blog posts are all pages whose file name has a
+
+Poole has basic support for blog posts. If a file name has a
 structure like `page-title.YYYY-MM-DD.post-title`, e.g.
-`blog.201010-02-27.read_this.md`. You don't have to put the
-date and post-title into the file name, you can also set them via macros in
-the page:
+`blog.201010-02-27.read_this.md`, it recognizes the date and post title.
+OTOH you don't have to put the date and post-title into the file name, you can
+also set them via variables in the page:
 
     post: Read this, my friend
     date: 2010-02-27
     ----
     ... blog post text ...
 
-Do whatever fit's best in your case.
-
----
-
-### Latest Blog Posts
-
-The following list of blog posts has been built by inline Python code in
-`input/blog.md`.
+Do whatever fit's best in your case. These variables can then be used to
+generate a list of blog posts:
 
 {%
 from datetime import datetime
     md += p["summary"] and '<br/>\\n    *%s*' % p["summary"] or ''
     print(md)
 %}
+
+This list has been generated by inline Python code in `input/blog.md`.
+
+*Yes, this is dirty and everything but MVC. Keep in mind that Poole focuses
+on small sites where we want to get things done fast and pragmatically.*
 """,
 
 "blog.2010-02-01.Doctors_in_my_penguin.md" : """
             self.raw = fp.readlines()
         
         # split raw content into macro definitions and real content
-        macro_defs = ""
+        vardefs = ""
         self.source = ""
         for line in self.raw:
-            if not macro_defs and re.match(self._re_eom, line):
-                macro_defs = self.source
+            if not vardefs and re.match(self._re_eom, line):
+                vardefs = self.source
                 self.source = "" # only macro defs until here, reset source
             else:
                 self.source += line
         tfname = ".page-macros.tmp"
         with codecs.open(tfname, "w", opts.input_enc) as tf:
             tf.write("[%s]\n" % self._sec_macros)
-            tf.write(macro_defs)
+            tf.write(vardefs)
         with codecs.open(tfname, "r", opts.input_enc) as tf:
             cp = SafeConfigParser()
             cp.readfp(tf)
 def build(project, opts):
     """Build a site project."""
     
-    RE_MACRO_ANY = r'(^|[^\\])({{.+?}})' # any macro
-    RE_MACRO_ONE = r'(^|[^\\]){{ *%s *}}' # specific macro
-    RE_MACRO_ONE_REPL = r'\g<1>%s'
+    RE_VAR_ANY = r'(^|[^\\])({{.+?}})' # any variable reference
+    RE_VAR_ONE = r'(^|[^\\]){{ *%s *}}' # specific variable reference
+    RE_VAR_ONE_REPL = r'\g<1>%s'# replacement for a specific variable reference
     
     RE_PYCODE = r'([^\\]|^)({%(?:.*?\n?)*%})' # any code block
     
-    RE_ESCAPED = r'\\({{|{%)'
-    RE_ESCAPED_REPL = r'\1'
+    RE_ESCAPED = r'\\({{|{%)' # escaped code block or variable reference
+    RE_ESCAPED_REPL = r'\1' # unescaped
     
     def repl_code(m):
         """Replacement callback for re.sub()."""
         code = m.group(2).strip("\n{%}")
-        dname = opj(opts.project, ".poole.tmp")
+        dname = opj(opts.project, ".build")
         shutil.rmtree(dname, ignore_errors=True)
         os.mkdir(dname)
         fname = opj(dname, "pycode.py")
         shutil.rmtree(dname)
         return "%s%s" % (m.group(1), repl)
     
-    def repl_macro(m):
+    def repl_var(m):
         """Replacement callback for re.sub()."""
         if m.group(1) == "\\":
             return m.group(2)
         name = m.group(2).strip(" {}")
         return "%s%s" % (m.group(1), page[name])
         
-    def repl_specific_macro(macro, value, source):
-        """Expand one specific macro in source to value."""
-        patt = RE_MACRO_ONE % macro
-        repl = RE_MACRO_ONE_REPL % value
+    def repl_specific_variable(name, value, source):
+        """Expand one specific variable in source to value."""
+        patt = RE_VAR_ONE % name
+        repl = RE_VAR_ONE_REPL % value
         return re.sub(patt, repl, source)
     
     dir_in = opj(project, "input")
         
         print("info: processing %s" % page.fname)
         
-        # replacements, phase 1 (macros and code blocks used in page source)
-        out = re.sub(RE_MACRO_ANY, repl_macro, page.source)
+        # replacements, phase 1 (variables and code blocks used in page source)
+        out = re.sub(RE_VAR_ANY, repl_var, page.source)
         out = re.sub(RE_PYCODE, repl_code, out, re.MULTILINE)
-        #out = expand_all_macros(out, page)
         
         # convert to HTML
         out = markdown.Markdown().convert(out)
         
-        # expand reserved macros
-        out = repl_specific_macro(MACRO_CONTENT, out, skeleton)
-        out = repl_specific_macro(MACRO_ENCODING, opts.output_enc, out)
+        # expand reserved variables
+        out = repl_specific_variable("__content__", out, skeleton)
+        out = repl_specific_variable("__encoding__", opts.output_enc, out)
         
-        # replacements, phase 2 (macros and code blocks used in page.html)
-        out = re.sub(RE_MACRO_ANY, repl_macro, out)
+        # replacements, phase 2 (variables and code blocks used in page.html)
+        out = re.sub(RE_VAR_ANY, repl_var, out)
         out = re.sub(RE_PYCODE, repl_code, out, re.MULTILINE)
         
         # un-escape escaped stuff
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.