Greg Slepak avatar Greg Slepak committed cd9821d Merge

Comments (0)

Files changed (3)

example-site/dragonfly-framework/config.lsp

 
 ; if you set to nil then make sure to comment out the line in .htaccess
 (constant 'ENABLE_STATIC_TEMPLATES true)
-; file extensions that triggers the handler (update .htaccess to match this!)
-(constant 'STATIC_EXTENSIONS '(".html"))
-; alternatively the static handler can be used to load index files given
-; a URL pointing to a directory. This variable customizes the extension
-; of the index file that the handler will check to see if it handles the request
-; ex: mysite.com/myproduct/support => mysite.com/myproduct/support/index.html
-(constant 'STATIC_INDEX_EXTENSION ".html")
+; File extensions that trigger the handler immediately.
+; This list can be large with no real performance penalty.
+; Make *sure* to update .htaccess to match this! (see comment there.)
+(constant 'STATIC_TRIGGER_EXTENSIONS '(".html"))
+; If STATIC_PATH_PREFIX is non-nil, then the static handler will check to
+; see if the given URL exists when prepended with the prefix, relative
+; to the DOCUMENT_ROOT. It can be used in conjunction with the
+; STATIC_TEST_EXTENSIONS to create pretty URLs.
+(constant 'STATIC_PATH_PREFIX "pages/")
+; You can use the static handler to create pretty URLs using the
+; STATIC_TEST_EXTENSIONS constant. It is used to check for index files in
+; directories and in conjunction with STATIC_PATH_PREFIX.
+; Here are some examples:
+; (=> means "loads file")
+; example-site.com/foo => example-site.com/foo/index.html
+; example-site.com/about => example-site.com/pages/about.html
+; Do not make this a very long list, otherwise the page will load slowly.
+(constant 'STATIC_TEST_EXTENSIONS '(".html"))
 
 ;===============================================================================
 ; Views
 ; set to nil to disable views handling
 (constant 'ENABLE_VIEW_HANDLER true)
 ; location of views
-(constant 'VIEWS_PATH (string DOCUMENT_ROOT "/views"))
+(constant 'PAGES_PATH (string DOCUMENT_ROOT "/views"))
 ; location of partials
 (constant 'PARTIALS_PATH (string DOCUMENT_ROOT "/views/partials"))
 ; setting a default view

example-site/dragonfly-framework/dragonfly.lsp

 )
 
 (define (view-path view-name)
-	(string VIEWS_PATH "/" view-name (if VIEW_EXTENSION VIEW_EXTENSION ""))
+	(string PAGES_PATH "/" view-name (if VIEW_EXTENSION VIEW_EXTENSION ""))
 )
 
 (define (partial-path partial-name)
 
 ; Route.Static handles "normal" URLs, i.e. the URL represents the actual
 ; location of the file. Two scenarios are handled:
-; 1) URL refers to real file ending in one of the STATIC_EXTENSIONS
-; 2) URL refers to real directory and has an index file ending in STATIC_INDEX_EXTENSION
+; 1) URL refers to real file ending in one of the STATIC_TRIGGER_EXTENSIONS
+; 2) URL refers to real directory and has an index file ending in STATIC_TEST_EXTENSIONS
 (define-subclass (Route.Static Route)
 	((matches?)
 		(set 'chunks (parse QUERY_STRING "?"))
 			(set 'file (first chunks))
 			; check if 'file' has one of the static extensions. If not, it could
 			; be a directory with an index file inside of it, so check that.
-			(unless (set 'ext (exists (curry ends-with file) DF:STATIC_EXTENSIONS))
-				(set 'ext DF:STATIC_INDEX_EXTENSION)
+			(unless (set 'ext (exists (curry ends-with file) DF:STATIC_TRIGGER_EXTENSIONS))
+				(set 'ext DF:STATIC_TEST_EXTENSIONS)
 				(set 'file (string DOCUMENT_ROOT "/" file "/index" ext))
 			)
 			; finally, we match only if the file actually exists

example-site/views/dragonfly_routes

 		<p class="config"><b>Configuration</b><br/>You may change the constant STATIC_EXTENSION in config.lsp to whatever You want. Default is set to ".html".</p>
 
 		<h3 class="code">1b. example-site.com/foo/</h3>
-		<p>If "foo" is a folder, then it will be searched for an index file by default. In the config.lsp, the STATIC_INDEX_EXTENSION is set to ".html". So it will search for an "index.html" inside of the foo folder. If it exists it will pass it through the template evaluator and displays it.
+		<p>If "foo" is a folder, then it will be searched for an index file by default. In the config.lsp, the STATIC_TEST_EXTENSIONS is set to ".html". So it will search for an "index.html" inside of the foo folder. If it exists it will pass it through the template evaluator and displays it.
 		</p>
-		<p class="config"><b>Configuration</b><br/>You may change the constant STATIC_INDEX_EXTENSION in config.lsp to whatever You want. Default is set to ".html".</p>
+		<p class="config"><b>Configuration</b><br/>You may change the constant STATIC_TEST_EXTENSIONS in config.lsp to whatever You want. Default is set to ".html".</p>
 		
 		
 		<h2>RESTful Routes</h2>
 		<pre class="code">Hello World</pre>
 		<p>Save the file as "hello" into Your views directory. Now open Your browser and navigate to <a href="http://www.example-site.com/hello">example-site.com/hello</a>. That's it!</p>
 		<p class="info"><b>Information</b><br/>You can put nearly everything into views: (X)HTML, Javascript, newLISP code.</p>
-		<p class="config"><b>Configuration</b><br/>If VIEW_EXTENSION is ".html" for example, then when example-site.com/hello is called Dragonfly will search for a "hello.html" file in the VIEWS_PATH. It also applies to the partials, too.</p>
+		<p class="config"><b>Configuration</b><br/>If VIEW_EXTENSION is ".html" for example, then when example-site.com/hello is called Dragonfly will search for a "hello.html" file in the PAGES_PATH. It also applies to the partials, too.</p>
 
 		<h3 class="code">How to call functions inside a view</h3>
 		<pre class="code">&lt;% (benchmark-result) %&gt;</pre>
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.