Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "template" to options #982

Closed
wants to merge 2 commits into from
Closed

Added "template" to options #982

wants to merge 2 commits into from

Conversation

Earl-Brown
Copy link

Now "directory.html" can be copied and modified without making changes to the distribution code.

Now "directory.html" can be copied and modified without making changes to the distribution code.
@ghost ghost assigned dougwilson Dec 27, 2013
@dougwilson
Copy link
Contributor

Seems reasonable, but the setting of exports.template needs to be outside the main function and you need to use exports.template instead of this.template inside exports.html (as this should be a function that can be executed with a global context).

@Earl-Brown
Copy link
Author

Thanks for the tip - now that I'm a bit more familiar with what's happening, I'm thinking something like "Theme" might be more applicable.

I'll wait to submit that as an alternative to this suggestion until I'm more clear on how to approach it.

@gottaloveit
Copy link
Contributor

can't wait for this one thank you

@dougwilson
Copy link
Contributor

@Earl-Brown template is fine with me. Let me know when you update the pull request with the necessary changes.

Changed this.template to exports.template
@Earl-Brown
Copy link
Author

@dougwilson: I didn't understand what you meatn by "inside exports.html", but I made the change in "directory.js".

@Earl-Brown
Copy link
Author

@gottaloveit: If I'm going to put "theme" support in, I'll be looking at very long-term goals...here are the notes I've made from the header comment.

In my "personal" branch of the code, I've made an "exports.utilities" for all of the "support" functions:

return {
fileSort: fileSort,
htmlPath: htmlPath,
iconStyle: iconStyle,
html: html,
load: load,
removeHidden: removeHidden,
statFiles: statFiles
}

/**

  • Directory:
    *
  • Serve directory listings with the given root path.
    *
  • Options:
    *
    • hidden display hidden (dot) files. Defaults to false.
    • icons display icons. Defaults to false.
    • filter Apply this filter function to files. Defaults to false.
    • 'theme' to allow output customization - an object containing:
    • 'folder' [__dirname + "/../public"] (
      string or function that returns a folder to use as the base folder for theme content
  • )
    • 'html' ["directory.html"] (string or function that returns a string;
      if not a filename, is actual html content
  •  these placeholders will be honored in the final string:
      {directory} (directory name)
      {style} (css)
      {linked-path} (directory broken into links)
      {files} (pre-rendered list of files)
    
  •  )
    
    • 'css' ["style.css"](string or function that returns a string; if not a filename, is actual css content)
    • 'icons' [
      '.js': 'page_white_code_red.png'
      , '.c': 'page_white_c.png'
      , '.h': 'page_white_h.png'
      , '.cc': 'page_white_cplusplus.png'
      , '.php': 'page_white_php.png'
      , '.rb': 'page_white_ruby.png'
      , '.cpp': 'page_white_cplusplus.png'
      , '.swf': 'page_white_flash.png'
      , '.pdf': 'page_white_acrobat.png'
      , 'folder': 'folder.png'
      , 'default': 'page_white.png'
      ](hashtable or function that returns an hashtable)
    • "title" [null] (
      string or function returning a string;
      if not a file, is HTML to be placed at the top of the output;
      if is a file, content will be included as a string
      if full html, ONLY content between and will be used
      these placeholders will be honored in the final string:
      {directory}
      {linked-path}
      {filecount}
      {filesize}
  •  )
    
    • "header" [null] (
      string or function returning a string;
      if not a file, is HTML to be placed at the top of the output;
      if is a file, content will be included as a string
      if full html, ONLY content between and will be used
      these placeholders will be honored in the final string:
      {directory}
      {linked-path}
      {filecount}
      {filesize}
  •  )
    
    • "directories" [null] (
      string or function returning a string
      HTML template for rendering directories
      all properties of fs.Stats will be honored as placeholders in the final string,
      using .Replace(/{prop}/gi, stat.prop) (or an equivalent)
  •  )
    
    • "files" [null] (
      string or function returning a string
      HTML template for rendering files
      all properties of fs.Stats will be honored as placeholders in the final string,
      using .Replace(/{prop}/gi, stat.prop) (or an equivalent)
  •  )
    
    • "footer" [null] (
      string or function returning a string;
      if not a file, is HTML to be placed at the top of the output;
      if is a file, content will be included as a string
      if full html, ONLY content between and will be used
      these placeholders will be honored in the final string:
      {directory}
      {linked-path}
      {filecount}
      {filesize}
  •  )
    
  • @param {String} root
  • @param {Object} options
  • @return {Function}
  • @api public
    */

All who are watching please provide feedback.

...and is there a better place for this discussion?

@gottaloveit
Copy link
Contributor

that looks awesome too, but i am just as excited to see the template option being added

@dougwilson
Copy link
Contributor

@Earl-Brown "exports.html" is the name of the function in directory.js (i.e. the exports.html = function ...). It is not referring to a file.

@@ -73,6 +72,9 @@ exports = module.exports = function directory(root, options){
, view = options.view || 'tiles'
, filter = options.filter
, root = normalize(root + sep);

exports.template = options.template || __dirname + '/../public/directory.html';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment needs to be outside the function.

@gottaloveit
Copy link
Contributor

how is that gonna work when the options variable are inside the function?

@dougwilson
Copy link
Contributor

@gottaloveit it already does not work property, since the options is setting a global. This example shows how the current PR is broken:

var connect = require('connect');
var app = connect();

app.use('/pub', connect.directory('./public/pub', {'template': './my/template.html'}));
app.use('/dev', connect.directory('./public/dev'));

Now both are served up with the default template, since the second invocation overrode the setting from the first (since the setting is being set as a global). This PR should not accept a template option to the direction middleware and instead set exports.template to the default template so people can set a new global template with connect.directory.template = './my/template.html';

@gottaloveit
Copy link
Contributor

I just submitted a pull request with a suggested fix

#990

@Earl-Brown
Copy link
Author

Isn't that the "constructor" function?

I'll be honest, this is my first brush with the "exports" construct - I'm researching up on it right now. What I do know is that it works in the code - I'm using it that way right now.

...so when I assign "template" to "exports", it becomes a member of a singleton object, and is the only template to be used? I was shooting for making the template be per-directory.

@dougwilson
Copy link
Contributor

@Earl-Brown if you are trying to make it per-directory, then you need to incorporate the changes @gottaloveit suggested. Also, you need to add the template option to the documentation in directory.js. This PR also is lacking tests to test this new functionality.

@Earl-Brown
Copy link
Author

@dougwilson - I'm sorry to say, but I don't know GitHub or the test platforms well enough to add tests.
@gottaloveit - would you do the favor of implementing your changes instead of mine? It looks like they do more of what I was looking for.

@Earl-Brown Earl-Brown closed this Jan 2, 2014
@Earl-Brown Earl-Brown deleted the patch-1 branch January 2, 2014 22:03
dougwilson pushed a commit that referenced this pull request Jan 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants