Sean Lou

专注前端开发

  • Web开发中初学者容易混淆的9个命名约定

    Posted in • javascript at 2012-03-15 by lxj
    Tags:
    http://dayanjia.com/2010/10/9-confusing-naming-conventions-for-beginners-in-web-programming.html

    当人们一开始接触各种Web开发语言时,总会发现彻底搞懂不同语言的命名约定是一件很要命的事情。而且当开发者在争论什么才是最佳实践时,事情会变得更加让人困惑。为了让初学者更容易地在不同语言中过渡,这篇文章列出了一些常见的约定。

    1. 类属性名前加下划线

    如果你看到一个变量或者方法是以_开头的,其实这并不代表其幕后有什么猫腻。这仅仅是为了提醒开发者这个变量/属性/方法是私有的(private)或是受保护的(protected),它们不能从类的外部访问到。

    PHP方式

    1 class MyClass {
    2    // 这个实例变量在类外部无法访问
    3    private $_someVariable;
    4 
    5    // 这个方法仅在类内部或者其它继承它的类中可用
    6    protected function __behindTheScenesMethod() {}
    7 }

    Read on →

  • Node.js使用 Mustache.js做模板

    Posted in • javascript at 2012-03-12 by lxj

    From:http://www.oschina.net/question/12_21806

    为了让 Node.js 输出更多的 HTML 元素,我们可以借助一些 html 模板引擎,例如 Mustache。

    首先在 Node.js 中安装 Mustache:

    npm install mustache

    这会创建一个目录:node_modules\mustache

    然后我们可以编写代码:

        var mustache = require('./node_modules/mustache/mustache');
         
        function helloworld(response)
        {
          console.log('request recieved at ' + (new Date()).getTime());
          response.writeHead(200, {'Content-Type': 'text/html'});
          var template = '<h1>Test</h1><p></p>';
          var model = {helloworld:'Hello World'};
          response.end(mustache.to_html(template,model));
        }
         
        exports.helloworld = helloworld;

    Read on →

  • Jekyll Pagination

    Posted in • plugins at 2012-03-09 by lxj

    From:https://github.com/mojombo/jekyll/wiki/Usage

    Note: Pagination does not work with markdown files, it only works with html file extensions.

    Just follow these steps to add pagination to your blog:

    _config.yml

    add the pagination setting: yaml markdown: rdiscount pygments: true lsi: true exclude: ['README.markdown', 'README_FOR_COLLABORATORS.markdown', 'Gemfile.lock', 'Gemfile'] production: false //add this line to add pagination paginate: 3 //the number of post per page

    Read on →

  • Jekyll Usage

    Posted in • other at 2012-03-08 by lxj
    Tags:Jekyll,data,

    From:https://github.com/mojombo/jekyll/wiki/Usage

    Creating a Jekyll site usually involves the following, [[once jekyll is installed.|Install]]

    1. Set up the basic structure of the site
    2. Create some posts, or [[import them from your previous platform|Blog migrations]]
    3. Run your site locally to see how it looks
    4. Deploy your site

    Basic Structure

    Jekyll at its core is a text transformation engine. The concept behind the system is this: you give it text written in your favorite markup language, be that Markdown, Textile, or just plain HTML, and it churns that through a layout or series of layout files. Throughout that process you can tweak how you want the site URLs to look, what data gets displayed on the layout and more. This is all done through strictly editing files, and the web interface is the final product.

    A basic Jekyll site usually looks something like this:

    Read on →

  • Jekyll Template data

    Posted in • other at 2012-03-08 by lxj
    Tags:Jekyll,data,

    From:https://github.com/mojombo/jekyll/wiki/Template-Data

    Jekyll traverses your site looking for files to process. Any files with [[YAML Front Matter]] are subject to processing. For each of these files, Jekyll makes a variety of data available to the pages via the Liquid templating system. The following is a reference of the available data.

    Global

    Variable Description
    site Sitewide information + Configuration settings from _config.yml
    page This is just the [[YAML Front Matter]] with 2 additions: url and content.
    content In layout files, this contains the content of the subview(s). This is the variable used to insert the rendered content into the layout. This is not used in post files or page files.
    paginator When the paginate configuration option is set, this variable becomes available for use.

    Read on →

© 2012