Anonymous avatar Anonymous committed 782dbb0

clean code &

Comments (0)

Files changed (8)

friendpaste/__init__.py

 from snippets.views import Snippet, Copy
 
 render = web.template.render(config.TEMPLATES_DIR)
+web.template.Template.globals['DEBUG'] = config.DEBUG
 
 urls = (
         '/(?P<snippetid>\d*)', 'Snippet',

friendpaste/code.py

-# -*- coding: utf-8 -*-
-
-_snippet_tpl = """
-title = %(title)s
-content = %(content)s
-"""
-
-def save_snippet(args):
-    snippet = _snippet_tpl % { 
-            'title': args['title'].value,
-            'content': args['content'].value
-    )
-
-    print snippet
-

friendpaste/config.py

 # -*- coding: utf-8 -*-
-import os.path
+import os.path, platform
 PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
 
+NODE_BENOITC = (platform.node() == 'marduk.metavers.net')
+
+DEBUG=False
+if NODE_BENOITC:
+    DEBUG=True
+
+
 DB_URI="mysql://work:test@localhost/friendpaste"
 
 middleware=[]
 
-MEDIA_URL = "/media"
+STATIC_URL = "/static"
 
-MEDIA_PATH=PROJECT_PATH + "/media"
-
-TEMPLATES_DIR = PROJECT_PATH + "/templates"
+TEMPLATES_DIR = "templates/"

friendpaste/snippets/__init__.py

+# -*- coding: utf-8 -*-
+from pygments.lexers import get_all_lexers
+
+# some lexers we would like to present first
+main_lexers = (
+        ('bash','Bash'),
+        ('c','C/C++'),
+        ('css','CSS'),
+        ('diff','Diff'),
+        ('html','HTML'),
+        ('java','Java'),
+        ('js','JavaScript'),
+        ('lua','Lua'),
+        ('perl','Perl'),
+        ('php', 'PHP'),
+        ('python','Python'),
+        ('rb','Ruby'),
+)
+
+def _get_lexers():
+    lexers = get_all_lexers()
+    ret = [] 
+    for l in lexers:
+        ret.append((l[1][0],l[0]))
+    ret.sort()
+    return ret
+
+LEXERS_CHOICE = _get_lexers()
+ALL_LEXERS=get_all_lexers()

friendpaste/snippets/code.py

 # -*- coding: utf-8 -*-
 from pygments.lexers import get_all_lexers
 
-
-# some lexers we would like to present first
-main_lexers = (
-        ('text', 'None'),
-        ('bash','Bash'),
-        ('c','C/C++'),
-        ('css','CSS'),
-        ('diff','Diff'),
-        ('html','HTML'),
-        ('java','Java'),
-        ('js','JavaScript'),
-        ('lua','Lua'),
-        ('perl','Perl'),
-        ('php', 'PHP'),
-        ('python','Python'),
-        ('rb','Ruby'),
-
-)
+import friendpaste
 
 _snippet_tpl = """
 title = %(title)s
 %(content)s
 """
 
-def get_lexers():
-    lexers = get_all_lexers()
-    ret = [] 
-    for l in lexers:
-        ret.append((l[1][0],l[0]))
-        
-    return ret
-
-
 def save_snippet(args):
     snippet = _snippet_tpl % { 
             'title': args['title'].value,

friendpaste/snippets/views.py

 
 import friendpaste
 
-from code import save_snippet, get_lexers, main_lexers
+from friendpaste.snippets import LEXERS_CHOICE, main_lexers
+
+from code import save_snippet
 
 snippet_form = form.Form(
         form.Textbox("title"),
         form.Textarea("content"),
-        form.Dropdown("language", get_lexers()),
+        form.Dropdown("language", LEXERS_CHOICE, value='text'),
         )
 
 class Snippet:
             print "Snippet %s" % (snippetid)
         else:
             form = snippet_form()
-            print friendpaste.render.snippet_form(form, main_lexers)
+            print friendpaste.render.base(friendpaste.render.snippet_form(form, main_lexers, LEXERS_CHOICE))
 
     def POST(self, snippetid):
         form = snippet_form()

friendpaste/templates/snippet_form.html

-$def with (form, main_lexers)
-
-<form name="main" method="post" action="."> 
-    $if not form.valid: <p class="error">Try again :</p>
-    <ul>
-    $for l in main_lexers:
-        <li>$l[0]</li>
-    </ul>
-
-    <div class="form-row"><label for="language">Syntax hilighting</label>$:form['language'].render()</div>
-    <p>To highlight particular lines, prefix each line with @@</p>
-    <div class="form-row">$:form['content'].render()</div>
-    <div class="form-row"><label for="title">Title/ Name</label>$:form['title'].render()</div>
-    <input type="submit" />    
-</form>

templates/snippet_form.html

+$def with (form, main_lexers, LEXERS_CHOICE)
+
+<form name="main" method="post" action="."> 
+    $if not form.valid: <p class="error">Try again :</p>
+  <!--  <ul>
+        $for l in main_lexers:
+            <li>$l[0]</li>
+        <li>All lexers
+            <ul>
+            $for l in LEXERS_CHOICE:
+                <li>$l[0]</li>
+            </ul>
+        </li>
+
+
+    </ul>-->
+
+    <div class="form-row"><label for="language">Syntax hilighting</label>$:form['language'].render()</div>
+    <p>To highlight particular lines, prefix each line with @@</p>
+    <div class="form-row">$:form['content'].render()</div>
+    <div class="form-row"><label for="title">Title/ Name</label>$:form['title'].render()</div>
+    <input type="submit" />    
+</form>
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.