{"dist":{"shasum":"6d1227eb01294c1c7c6595195b4726786cbdcb9b","tarball":"https://registry.npmjs.org/walrus/-/walrus-0.10.1.tgz","integrity":"sha512-qdt+RfWCTWqyi1gYtgkQrbrlU3lqWtr0dhWEdDz25MDewJQpGn4mdSmnkSBBqdnq4vm0LHPpvicstoZ1MGYnaA==","signatures":[{"sig":"MEUCIE4wGKx5vhcUzg1Asr9NGmfgdb+fZ7QRkUQ6/Ypo4iU5AiEAqFWasLKZLR2oDrw/v7r+xIHFRY2cjZq5BzBv6DnoZ+w=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./bin/walrus","name":"walrus","author":{"name":"Jeremy Ruppel"},"readme":"# Walrus\n\nA bolder kind of mustache.\n\n[![Build Status](https://secure.travis-ci.org/jeremyruppel/walrus.png)](http://travis-ci.org/jeremyruppel/walrus)\n\nView this readme on [documentup](http://documentup.com/jeremyruppel/walrus).\n\n## About\n\n**Walrus** is a templating library inspired by [mustache][mustache], [handlebars][handlebars], [ejs][ejs] and friends,\nbut with a couple of important differences in philosophy and style:\n\n- **View logic is different than business logic (and that's okay!).**\n\tIn modern web apps, there's often a good amount of presentation logic involved. This logic doesn't belong\n\tin your application code, your backbone models, or anywhere else but the presentation layer. The templating\n\tlanguage is a good place to put this.\n\n- **Reusable view helpers are super fun and helpful.**\n\tRails had the right idea by shipping a bunch of view helpers with ActionView. Having commonly used view helpers\n\tcome bundled with the framework keeps developers from spending time writing them (and testing them, or even worse,\n\t_not testing them_) again and again.\n\n- **Keep the core library light.**\n\tWhile **walrus** ships with a bunch of filters and helpers you can use out-of-the-box, only the essentials\n\tare included in the core. This keeps client-side code as small as it can be, letting you opt-in to extras\n\tonly as often as you need them. To extend **walrus** with new filters and helpers, just include the\n\tjavascript you want and you're done, son.\n\n- **Stop hashing and slashing.**\n\tMaybe it's just me, but opening and closing blocks with \"hash-something\" \"slash-something\" feels super redundant.\n\tWalrus uses do/end for its blocks, which should look a lot more familiar to ruby types.\n\nThe **walrus** parser is written in [jison][jison] and the rest in [coffeescript][coffeescript], and everything\nis tested with [mocha][mocha]. **Walrus has no runtime dependencies.**\n\nSince **walrus** is still pretty young, expect changes in the API, especially for filters and helpers.\n\nThe `/test/examples` directory is filled with plenty of self-documenting examples that comprise over half of\nthe test suite, so give those a once-over if you have a question that isn't answered in the readme.\n\n## Core\n\nThe **walrus** core contains the walrus parser/compiler, several common helpers and filters, and a few internal utility methods.\n\n### Usage in JavaScript\n\nLike other [jison][jison]-based parsers, templating with **walrus** is a two-step process.\n\nFirst, grab your template and parse it:\n\n``` js\nvar template = Walrus.Parser.parse( $( '#my-template' ).html( ) );\n```\n\n`template` is a JavaScript object ready to accept a view object and kick out some text.\n\n``` js\nvar htmlGoodness = template.compile( { data : 'foo bar baz' } );\n```\n\n### Paths\n\nLike some of the other templating solutions out there, Walrus will let you reference members using object paths.\n\nIf your view object is:\n\n``` json\n{\n\t\"hello\" :\n\t{\n\t\t\"walrus\" : \"sweeet.\"\n\t}\n}\n```\n\nThen `{{hello.walrus}}` will resolve to `sweeet.`.\n\n### Root References (all day erryday)\n\nWith Walrus, you can always reference the root view object as a path context by using the `@` symbol before your path.\nUse this even if you're dereferenced, iterating, or even within the arguments to a method.\n\nSo if you've got a view object like:\n\n``` json\n{\n\t\"team\" : \"Detroit Red Wings\",\n\t\"players\" :\n\t[\n\t\t{\n\t\t\t\"name\" : \"Pavel Datsyuk\"\n\t\t},\n\t\t{\n\t\t\t\"name\" : \"Nicklas Lidström\"\n\t\t},\n\t\t{\n\t\t\t\"name\" : \"Darren Helm\"\n\t\t}\n\t]\n}\n```\n\nYou can create your badass hockey roster like:\n\n``` html\n<ul>\n\t{{:each players do}}\n\t<li>{{name}} plays for the {{@team}}</li>\n\t{{end}}\n</ul>\n```\n\n### (Un-)Escaping\n\nLike many other mustache-like languages, **walrus** escapes string members by default in an attempt\nto get rid of HTML-unsafe characters.\n\nIf you want these characters included, use an equals sign before your expression, like: `{{=html}}`.\n\n### Methods\n\nOne of the main focuses of Walrus is to treat methods on your view object like first-class citizens. You can\ncall your methods with any number of arguments from the view object or (most) javascript literals.\n\nWith a view object like:\n\n``` js\n{\n\t\"captitalize\" : function( str ){ return str.charAt( 0 ).toUpperCase( ) + str.slice( 1 ); },\n\t\"city\" : \"detroit\"\n}\n```\n\nIt's as easy as `{{capitalize( city )}}`.\n\n> Note that since both of these members are at the root of the view object, you could also reference them like\n> `{{@capitalize( @city )}}`, or any combination of local or root references.\n\n## Core Blocks/Helpers\n\nIn Walrus, blocks don't look like the `#member`/`/member` hash/slash pairs we've seen elsewhere. Walrus looks\na lot more like ruby and uses a simpler `do`/`end` idiom.\n\nEach block has a helper, preceded by `:`, that tells you what the block does. Walrus ships with a basic set of\nthese built in.\n\n### :if and :unless\n\nConditionals can be represented by `:if` and `:unless` blocks. Both of these test the expression for truthiness\nor falsiness respectively.\n\n``` html\n{{:if @loggedIn do}}\n<p>Welcome back, {{@username}}!</p>\n{{end}}\n\n{{:unless @loggedIn do}}\n<p>I don't believe we've met!</p>\n{{end}}\n```\n\n### :each\n\n`:each` can be used to iterate over a collection.\n\n``` html\n{{:each @player do}}\n<li>{{name}}</li>\n{{end}}\n```\n\n> While in an `:each` block, you can use the following special variables:\n>\n> **$index** provides the index of the current item in the collection\n>\n> **$length** provides the length of the collection\n>\n>\t**$parent** provides access to the parent object of the collection\n>\n> Like several other templating solutions, you can implicitly iterate over a collection of values, like strings, and template in the current value with `{{.}}`.\n\n### :with\n\n`:with` can be used to force a change in context if you don't want to use tons of object paths.\n\n``` html\n{{:with @team.captain do}}\n<p>Captain: {{name}}</p>\n{{end}}\n```\n\n> While in a `:with` block, you can use the following special variables:\n>\n> **$parent** provides access to the parent object of the context\n\n## Core Filters\n\nWalrus also supports the concept of filters, which look a lot like filters you might have used in [liquid][liquid] or [ejs][ejs] templates.\n\nFilters also are preceded by `:`, but come after the main expression separated by a pipe, like `{{name | :upcase}}`.\n\nFilters can be chained together, separated by whitespace. Filters can be used with block helpers or in a standalone expression.\n\n### :equals\n\n`:equals` tests the expression for strict equality. This is most useful with the conditional block helpers.\n\n``` html\n{{:if status | :equals( 'pending' ) do}}\n<p>We're still working on it.</p>\n{{end}}\n```\n\n### :if\n\nReturns the expression if _condition_ is truthy, or nothing if _condition_ is falsy.\n\nParameters:\n\n\tcondition - the condition to test against\n\nUsage:\n\n\t{{ 'active' | :if( true ) }} <!-- \"active\" -->\n\n### :unless\n\nReturns the expression if _condition_ is falsy, or nothing if _condition_ is truthy.\n\nParameters:\n\n\tcondition - the condition to test against\n\nUsage:\n\n\t{{ 'active' | :unless( true ) }} <!-- \"\" -->\n\n### :or\n\n`:or` can be used to provide a default or fallback value if a member doesn't exist on your view object.\n\n``` html\n<h2>{{price | :or( 'N/A' )}}</h2>\n```\n\n### :log\n\n`:log` is a helper method for developers that simply passes its argument to the console.\n\n``` html\nYou can log a {{@member | :log}} of the view object,\nwhile {{. | :log}} will log the whole thing,\nand {{\"arbitrary literals\" | :log}} can be logged, too!\n```\n\n### :as\n\nDecorates a view object or collection of view objects with custom domain methods.\n\nParameters:\n\n\tname - The key for the object on `Walrus.Domain` to decorate with\n\nUsage:\n\nFirst, define some custom domain methods:\n\n``` js\nWalrus.Domain.person = { fullName : function( ){ return this.firstName + ' ' + this.lastName; } };\n```\n\nThen, selectively apply those to your view object at template-time:\n\n``` html\n<ul>\n\t{{:each employee | :as( 'person' ) do}}\n\t<li>{{fullName}}</li>\n\t{{do}}\n</ul>\n```\n\n## Walrus.Collections\n\n`walrus.collections` contains helpers and filters that are useful when working with arrays.\n\n### :first\n\nSelects the first _count_ items of the array. Defaults to only the first item.\n\nParameters:\n\n\tcount - Optional: how many items to include\n\nUsage:\n\n``` html\n{{ :each numbers | :first do }}\n\t<!-- 1 -->\n{{ end }}\n\n{{ :each numbers | :first( 5 ) do }}\n\t<!-- 1 2 3 4 5 -->\n{{ end }}\n```\n\n### :last\n\nSelects the last _count_ items of the array. Defaults to only the last item.\n\nParameters:\n\n\tcount - Optional: how many items to include\n\nUsage:\n\n``` html\n{{ :each numbers | :last do }}\n\t<!-- 10 -->\n{{ end }}\n\n{{ :each numbers | :last( 5 ) do }}\n\t<!-- 6 7 8 9 10 -->\n{{ end }}\n```\n\n### :after\n\nSelects all of the items in the array except for the first _count_.\n\nParameters:\n\n\tcount - how many items to omit from the beginning\n\nUsage:\n\n``` html\n{{ :each numbers | :after( 3 ) do }}\n\t<!-- 4 5 6 7 8 9 10 -->\n{{ end }}\n```\n\n### :before\n\nSelects all of the items in the array except for the last _count_.\n\nParameters:\n\n\tcount - how many items to omit from the end\n\nUsage:\n\n``` html\n{{ :each numbers | :before( 3 ) do }}\n\t<!-- 1 2 3 4 5 6 7 -->\n{{ end }}\n```\n\n### :count\n\nReturns the length of the given array.\n\nParameters: none\n\nUsage:\n\n``` html\nvar numbers = [ 1, 2, 3, 4, 5 ];\n\n{{ numbers | :count }} <!-- 5 -->\n```\n\n### :any\n\nReturns true if the array is not empty. Opposite of `:empty`.\n\nParameters: none\n\nUsage:\n\n``` html\nvar numbers = [ 1, 2, 3, 4, 5 ];\n\n{{ numbers | :any }} <!-- true -->\n```\n\n### :empty\n\nReturns true of the array is empty. Opposite of `:any`.\n\nParameters: none\n\nUsage:\n\n``` html\nvar numbers = [ 1, 2, 3, 4, 5 ];\n\n{{ numbers | :empty }} <!-- false -->\n```\n\n### :in_groups_of\n\nSplits the given array into sub-arrays with at most `count` items apiece\n\nParameters:\n\n  count - the number of items to be placed in each group\n\nUsage:\n\n``` html\nvar numbers = [ 1, 2, 3, 4, 5 ];\n\n{{ :each numbers | :in_groups_of( 3 ) }}  <!-- [ [ 1, 2, 3 ], [ 4, 5 ] ] -->\n```\n\n## Walrus.Currencies\n\n`walrus.currencies` contains helpers and filters that are useful when working with dolla bills.\n\n### :currency\n\nReturns a string formatted in the current locale's format.\nDelegates to [accounting.js](http://josscrowcroft.github.com/accounting.js/) if present.\n\nParameters:\n  symbol - (Optional) the currency symbol to use\n\tprecision - (Optional) the decimal place level to show cents\n\tdecimal - (Optional) the character used to delimit decimals\n\tthousand - (Optional) the character used to delimit thousands\n\nUsage:\n\n\t{{ 36000 | :currency }} // => $36,000.00\n\t{{ 36000 | :currency( '$', 0 ) }} // => $36,000\n\n## Walrus.Dates\n\n`walrus.dates` contains helpers and filters that are useful when working with dates or timestamps.\n\n### :strftime\n\nFormats a date into the string given by `format`. Accepts any value that can be passed to `new Date( )`.\n\nParameters:\n\n\tformat - The format string, according to these tokens, taken directly from `man 3 strftime` (with some omissions):\n\n\t%A\t\tis replaced by national representation of the full weekday name.\n\n\t%a\t\tis replaced by national representation of the abbreviated weekday name.\n\n\t%B\t\tis replaced by national representation of the full month name.\n\n\t%b\t\tis replaced by national representation of the abbreviated month name.\n\n\t%D\t\tis equivalent to ``%m/%d/%y''.\n\n\t%d\t\tis replaced by the day of the month as a decimal number (01-31).\n\n\t%e\t\tis replaced by the day of month as a decimal number (1-31); single digits are\n\t\t\t\tpreceded by a blank.\n\n\t%F\t\tis equivalent to ``%Y-%m-%d''.\n\n\t%H\t\tis replaced by the hour (24-hour clock) as a decimal number (00-23).\n\n\t%I\t\tis replaced by the hour (12-hour clock) as a decimal number (01-12).\n\n\t%k\t\tis replaced by the hour (24-hour clock) as a decimal number (0-23); single dig-\n\t\t\t\tits are preceded by a blank.\n\n\t%l\t\tis replaced by the hour (12-hour clock) as a decimal number (1-12); single dig-\n\t\t\t\tits are preceded by a blank.\n\n\t%M\t\tis replaced by the minute as a decimal number (00-59).\n\n\t%m\t\tis replaced by the month as a decimal number (01-12).\n\n\t%n\t\tis replaced by a newline.\n\n\t%p\t\tis replaced by national representation of either \"ante meridiem\" or \"post meri-\n\t\t\t\tdiem\" as appropriate.\n\n\t%R\t\tis equivalent to ``%H:%M''.\n\n\t%r\t\tis equivalent to ``%I:%M:%S %p''.\n\n\t%S\t\tis replaced by the second as a decimal number (00-60).\n\n\t%T\t\tis equivalent to ``%H:%M:%S''.\n\n\t%t\t\tis replaced by a tab.\n\n\t%U\t\tis replaced by the week number of the year (Sunday as the first day of the\n\t\t\t\tweek) as a decimal number (00-53).\n\n\t%u\t\tis replaced by the weekday (Monday as the first day of the week) as a decimal\n\t\t\t\tnumber (1-7).\n\n\t%v\t\tis equivalent to ``%e-%b-%Y''.\n\n\t%w\t\tis replaced by the weekday (Sunday as the first day of the week) as a decimal\n\n\t%X\t\tis replaced by national representation of the time.\n\n\t%x\t\tis replaced by national representation of the date.\n\n\t%Y\t\tis replaced by the year with century as a decimal number.\n\n\t%y\t\tis replaced by the year without century as a decimal number (00-99).\n\n\t%Z\t\tis replaced by the time zone name.\n\nUsage:\n\n\t{{created_at | :strftime( '%F' )}} <!-- 2012-02-10 -->\n\n### :time_ago_in_words\n\nReturns a human-readable relative time phrase from the given date.\nHeavily adapted from the [ActionPack][actionpack] method of the same name.\n\nParameters:\n\n\tincludeSeconds - (Optional) whether or not to include results for less than one minute\n\nUsage:\n\n\t{{ created_at | :time_ago_in_words( true ) }} <!-- less than a minute -->\n\n## Walrus.Inflections\n\n`walrus.inflections` contains helpers and filters to help work with human-friendly text.\n\n### :pluralize\n\nPluralizes the given word, optionally based on a _count_, and also optionally including the count in the result.\nHeavily adapted from the [ActiveSupport][activesupport] method of the same name.\n\nParameters:\n\n\tword - the word to be pluralized\n\tcount - Optional: count to base pluralization on\n\tincludeCount - Optional: whether or not to include the count in the result\n\nUsage:\n\n\t{{ \"book\" | :pluralize }} <!-- books -->\n\n\t{{ \"book\" | :pluralize( 1 ) }} <!-- book -->\n\n\t{{ \"book\" | :pluralize( 5, true ) }} <!-- 5 books -->\n\n### :singularize\n\nSingularizes the given word. You're probably looking for `pluralize`.\nHeavily adapted from the [ActiveSupport][activesupport] method of the same name.\n\nParameters: none\n\nUsage:\n\n\t{{ \"books\" | :singularize }} <!-- book -->\n\n### :ordinalize\n\nTurns a number into an ordinal string, like 1st, 2nd, 3rd, etc...\nHeavily adapted from the [ActiveSupport][activesupport] method of the same name.\n\nParameters: none\n\nUsage:\n\n\t{{ 5 | :ordinalize }} <!-- 5th -->\n\n## Walrus.Math\n\n`walrus.math` contains helpers and filters to help work with numbers.\n\n### :plus\n\nReturns the sum of two numbers.\n\nParameters:\n\n\tnumber - the number to add to the expression\n\nUsage:\n\n\t{{ 15 | :plus( 6 ) }} <!-- 21 -->\n\n### :minus\n\nReturns the difference of two numbers.\n\nParameters:\n\n\tnumber - the number to subtract from the expression\n\nUsage:\n\n\t{{ 15 | :minus( 6 ) }} <!-- 9 -->\n\n### :gt\n\nReturns whether `value` is greater than the given number.\n\nParameters:\n\n\tnumber - the number to compare against\n\nUsage:\n\n\t{{ 15 | :gt( 5 ) }} <!-- true -->\n\n### :gte\n\nReturns whether `value` is greater than or equal to the given number.\n\nParameters:\n\n\tnumber - the number to compare against\n\nUsage:\n\n\t{{ 15 | :gte( 5 ) }} <!-- true -->\n\n### :lt\n\nReturns whether `value` is less than the given number.\n\nParameters:\n\n\tnumber - the number to compare against\n\nUsage:\n\n\t{{ 15 | :lt( 5 ) }} <!-- false -->\n\n### :lte\n\nReturns whether `value` is less than or equal to the given number.\n\nParameters:\n\n\tnumber - the number to compare against\n\nUsage:\n\n\t{{ 15 | :lte( 5 ) }} <!-- false -->\n\n### :floor\n\nReturns the given number rounded down to the nearest integer.\n\nParameters: none\n\nUsage:\n\n\t{{ 5.6 | :floor }} <!-- 5 -->\n\n### :ceil\n\nReturns the given number rounded up to the nearest integer.\n\nParameters: none\n\nUsage:\n\n\t{{ 5.6 | :ceil }} <!-- 6 -->\n\n### :round\n\nReturns the given number rounded to the nearest integer.\n\nParameters: none\n\nUsage:\n\n\t{{ 5.6 | :round }} <!-- 6 -->\n\n## Walrus.Strings\n\n`walrus.strings` contains helpers and filters to help work with strings.\n\n### :reverse\n\nReverses a string.\n\nParameters: none\n\nUsage:\n\n\t{{ \"hello\" | :reverse }} <!-- olleh -->\n\n### :downcase\n\nConverts a string to lowercase characters. Opposite of `:upcase`.\n\nParameters: none\n\nUsage:\n\n\t{{ \"HelLO!\" | :downcase }} <!-- hello! -->\n\n### :upcase\n\nConverts a string to uppercase characters. Opposite of `:downcase`.\n\nParameters: none\n\nUsage:\n\n\t{{ \"HelLO!\" | :upcase }} <!-- HELLO! -->\n\n### :squish\n\nRemoves all leading and trailing whitespace, then condenses any internal whitespace\ngroups to a single space each.\nHeavily adapted from the [ActiveSupport][activesupport] method of the same name.\n\nParameters: none\n\nUsage:\n\n\t{{ \" foo\t\tbar \\n baz\"\t | :squish }} <!-- foo bar baz -->\n\n### :truncate\n\nTruncates a string to the specified `length`, optionally breaking at a separator or\nproviding a custom string to denote an omission.\nHeavily adapted from the [ActiveSupport][activesupport] method of the same name.\n\nParameters:\n\n\tlength (int) - the number of characters to keep, at most\n\tseparator (string) - Optional: a specified string to break on\n\tomission (string) - Optional: a string to denote an omission\n\nUsage:\n\n\t{{ \"Once upon a time in a world far far away\" | :truncate( 27, ' ' ) }} <!-- Once upon a time in a... -->\n\n### :titleize\n\nCapitalizes all words within a string\n\nParameters: none\n\nUsage:\n\n\t{ \"man from the boondocks\" | :titleize }   // => \"Man From The Boondocks\"\n\t{ \"x-men: the last stand\" | :titleize }    // => \"X Men: The Last Stand\"\n\t{ \"TheManWithoutAPast\" | :titleize }       // => \"The Man Without A Past\"\n\t{ \"raiders_of_the_lost_ark\" | :titleize }  // => \"Raiders Of The Lost Ark\"\n\n## Mad Props\n\nIf Walrus isn't quite your style, one of these other fine looks might suit you:\n\n- [mustache][mustache]\n- [handlebars][handlebars]\n- [ejs][ejs]\n- [liquid][liquid]\n\nIn any case, walrus borrows ideas from each of them, so they're all worth checking out!\n\nMany of the filters in walrus are inspired or borrowed from [ActiveSupport][activesupport]. If walrus can\nbe half as helpful to developers as ActiveSupport has been, it'll be a great success.\n\n## Contributors\n\n- [Eddie Leffler](https://github.com/hershmire)\n- [Curtis Steckel](https://github.com/steckel)\n- [Grant Klinsing](https://github.com/kagd)\n\n## License\n\nWalrus is released under the MIT license.\n\n[handlebars]: https://github.com/wycats/handlebars.js\n[mustache]: https://github.com/janl/mustache.js\n[ejs]: https://github.com/visionmedia/ejs\n[liquid]: http://liquidmarkup.org/\n[jison]: http://zaach.github.com/jison/\n[coffeescript]: http://coffeescript.org/\n[mocha]: http://visionmedia.github.com/mocha/\n[activesupport]: http://as.rubyonrails.org/\n[actionpack]: https://github.com/rails/rails/tree/master/actionpack\n","engines":{"node":">= 0.6"},"license":"MIT","scripts":{"test":"mocha"},"_npmUser":{"name":"jeremyruppel","email":"jeremy.ruppel@gmail.com"},"keywords":["template","templating","mustache","handlebars","client side","action view"],"repository":{"url":"https://github.com/jeremyruppel/walrus"},"_npmVersion":"1.1.59","description":"A bolder kind of mustache.","maintainers":[{"name":"jeremyruppel","email":"jeremy.ruppel@gmail.com"}],"contributors":[{"name":"Eddie Leffler"},{"name":"Curtis Steckel"},{"name":"Grant Klinsing"}],"dependencies":{},"devDependencies":{"chai":"1.1.1","jison":"0.3.2","mocha":"0.14.1","frosting":"0.3.7"},"_id":"walrus@0.10.1","version":"0.10.1"}