pax_global_header00006660000000000000000000000064124741460220014514gustar00rootroot0000000000000052 comment=7f30493f602bf8b97332c3faf94e824eb1c4ea2f say-1.3-1/000077500000000000000000000000001247414602200123115ustar00rootroot00000000000000say-1.3-1/.gitignore000066400000000000000000000000061247414602200142750ustar00rootroot00000000000000*.swp say-1.3-1/.travis.yml000066400000000000000000000013451247414602200144250ustar00rootroot00000000000000language: erlang env: - LUA="" - LUA="luajit" branches: only: - master install: - sudo apt-get install luajit - sudo apt-get install luarocks - sudo luarocks install luafilesystem - git clone git://github.com/Olivine-Labs/say.git - cd say - sudo luarocks make - cd ../ - git clone git://github.com/Olivine-Labs/luassert.git - cd luassert - sudo luarocks make - cd ../ - git clone git://github.com/Olivine-Labs/busted.git - cd busted - sudo luarocks make busted-scm-0.rockspec - cd ../ script: "busted spec" notifications: webhooks: - http://hollow-mountain-1250.herokuapp.com/hubot/travis recipients: - engineers@olivinelabs.com email: on_success: always on_failure: always say-1.3-1/CONTRIBUTING.md000066400000000000000000000030711247414602200145430ustar00rootroot00000000000000Contributing to Say =================== So you want to contribute to luassert? Fantastic! Here's a brief overview on how best to do so. ## What to change Here's some examples of things you might want to make a pull request for: * New features * Bugfixes * Inefficient blocks of code If you have a more deeply-rooted problem with how the program is built or some of the stylistic decisions made in the code, it's best to [create an issue](https://github.com/Olivine-Labs/say/issues) before putting the effort into a pull request. The same goes for new features - it might be best to check the project's direction, existing pull requests, and currently open and closed issues first. ## Style * Two spaces, not tabs * Variables have_underscores, classes are Uppercase * Wrap everything in `local`, expose blocks of code using the module pattern Look at existing code to get a good feel for the patterns we use. ## Using Git appropriately 1. [Fork the repository](https://github.com/Olivine-Labs/say/fork_select) to your Github account. 2. Create a *topical branch* - a branch whose name is succint but explains what you're doing, such as "klingon-translations" 3. Make your changes, committing at logical breaks. 4. Push your branch to your personal account 5. [Create a pull request](https://help.github.com/articles/using-pull-requests) 6. Watch for comments or acceptance Please note - if you want to change multiple things that don't depend on each other, make sure you check the master branch back out before making more changes - that way we can take in each change seperately. say-1.3-1/LICENSE000066400000000000000000000021271247414602200133200ustar00rootroot00000000000000MIT License Terms ================= Copyright (c) 2012 Olivine Labs, LLC. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. say-1.3-1/README.md000066400000000000000000000012551247414602200135730ustar00rootroot00000000000000Say ==== [![travis-ci status](https://secure.travis-ci.org/Olivine-Labs/say.png)](http://travis-ci.org/#!/Olivine-Labs/say/builds) say is a simple string key/value store for i18n or ay other case where you want namespaced strings. Check out [busted](http://www.olivinelabs.com/busted) for extended examples. ```lua s = require("say") s:set_namespace("en") s:set('money', 'I have %s dollars') s:set('wow', 'So much money!') print(s('money', 1000)) -- I have 1000 dollars s:set_namespace("fr") -- switch to french! s:set('so_much_money', "Tant d'argent!") print(s('wow')) -- Tant d'argent! s:set_namespace("en") -- switch back to english! print(s('wow')) -- So much money! ``` say-1.3-1/say-1.3-1.rockspec000066400000000000000000000007441247414602200153020ustar00rootroot00000000000000package = "say" version = "1.3-1" source = { url = "https://github.com/Olivine-Labs/say/archive/v1.3-1.tar.gz", dir = "say-1.3-1" } description = { summary = "Lua String Hashing/Indexing Library", detailed = [[ Useful for internationalization. ]], homepage = "http://olivinelabs.com/busted/", license = "MIT " } dependencies = { "lua >= 5.1" } build = { type = "builtin", modules = { ["say.init"] = "src/init.lua" } } say-1.3-1/spec/000077500000000000000000000000001247414602200132435ustar00rootroot00000000000000say-1.3-1/spec/say_spec.lua000066400000000000000000000025431247414602200155600ustar00rootroot00000000000000local s describe("Tests to make sure the say library is functional", function() setup(function() package.loaded['say'] = false -- busted uses it, must force to reload s = require('init') -- devcode is in /src/init.lua not in /src/say/init.lua end) it("tests the set function metamethod", function() s:set('herp', 'derp') assert(s._registry.en.herp == 'derp') end) it("tests the __call metamethod", function() s:set('herp', 'derp') assert(s('herp') == 'derp') s:set('herp', '%s') assert(s('herp', {'test'}) == 'test') s:set('herp', '%s%s') assert(s('herp', {'test', 'test'}) == 'testtest') end) it("tests the substitution of variable types; boolean, number, string and table", function() s:set('substitute_test', 'boolean = %s, number = %s, string = "%s", table = %s') local atable = {} assert(s('substitute_test', {true, 100, 'some text', atable}) == 'boolean = true, number = 100, string = "some text", table = ' .. tostring(atable)) end) it("tests the set_fallback method", function() s:set_namespace('en') s:set('herp', 'derp') s:set_namespace('not-en') s:set('not-herp', 'not-derp') assert(s('not-herp') == 'not-derp') assert(s('herp') == 'derp') end) it("tests missing elements returns nil", function() assert(s('this does not exist') == nil) end) end) say-1.3-1/src/000077500000000000000000000000001247414602200131005ustar00rootroot00000000000000say-1.3-1/src/init.lua000066400000000000000000000025021247414602200145450ustar00rootroot00000000000000local unpack = table.unpack or unpack local registry = { } local current_namespace local fallback_namespace local s = { _COPYRIGHT = "Copyright (c) 2012 Olivine Labs, LLC.", _DESCRIPTION = "A simple string key/value store for i18n or any other case where you want namespaced strings.", _VERSION = "Say 1.2", set_namespace = function(self, namespace) current_namespace = namespace if not registry[current_namespace] then registry[current_namespace] = {} end end, set_fallback = function(self, namespace) fallback_namespace = namespace if not registry[fallback_namespace] then registry[fallback_namespace] = {} end end, set = function(self, key, value) registry[current_namespace][key] = value end } local __meta = { __call = function(self, key, vars) vars = vars or {} local str = registry[current_namespace][key] or registry[fallback_namespace][key] if str == nil then return nil end str = tostring(str) local strings = {} for i,v in ipairs(vars) do table.insert(strings, tostring(v)) end return #strings > 0 and str:format(unpack(strings)) or str end, __index = function(self, key) return registry[key] end } s:set_fallback('en') s:set_namespace('en') s._registry = registry return setmetatable(s, __meta)