walrus-rb 0.10.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Guardfile +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +17 -0
- data/lib/walrus.rb +7 -0
- data/lib/walrus/config.rb +29 -0
- data/lib/walrus/context.rb +42 -0
- data/lib/walrus/version.rb +3 -0
- data/spec/blocks_spec.rb +13 -0
- data/spec/collections_spec.rb +15 -0
- data/spec/context_spec.rb +13 -0
- data/spec/currencies_spec.rb +13 -0
- data/spec/dates_spec.rb +13 -0
- data/spec/domain_spec.rb +20 -0
- data/spec/filters_spec.rb +13 -0
- data/spec/inflections_spec.rb +13 -0
- data/spec/math_spec.rb +14 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/strings_spec.rb +11 -0
- data/spec/support/javascripts/walrus_domain_objects.js +22 -0
- data/vendor/walrus.collections.js +234 -0
- data/vendor/walrus.currencies.js +57 -0
- data/vendor/walrus.dates.js +296 -0
- data/vendor/walrus.inflections.js +120 -0
- data/vendor/walrus.js +1304 -0
- data/vendor/walrus.math.js +144 -0
- data/vendor/walrus.strings.js +127 -0
- data/walrus.gemspec +30 -0
- metadata +187 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
(function() {
|
2
|
+
var Walrus;
|
3
|
+
|
4
|
+
Walrus = (typeof exports !== "undefined" && exports !== null ? require('./walrus') : this).Walrus;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* *:plus*
|
8
|
+
* Returns the sum of two numbers
|
9
|
+
*
|
10
|
+
* Parameters:
|
11
|
+
* number - the number to add to the expression
|
12
|
+
*
|
13
|
+
* Usage:
|
14
|
+
*
|
15
|
+
* {{ 15 | :plus( 6 ) }} // => 21
|
16
|
+
*/
|
17
|
+
|
18
|
+
Walrus.addFilter('plus', function(value, number) {
|
19
|
+
return value + number;
|
20
|
+
});
|
21
|
+
|
22
|
+
/**
|
23
|
+
* *:minus*
|
24
|
+
* Returns the difference of two numbers
|
25
|
+
*
|
26
|
+
* Parameters:
|
27
|
+
* number - the number to subtract from the expression
|
28
|
+
*
|
29
|
+
* Usage:
|
30
|
+
*
|
31
|
+
* {{ 15 | :minus( 6 ) }} // => 9
|
32
|
+
*/
|
33
|
+
|
34
|
+
Walrus.addFilter('minus', function(value, number) {
|
35
|
+
return value - number;
|
36
|
+
});
|
37
|
+
|
38
|
+
/**
|
39
|
+
* *:gt*
|
40
|
+
* Returns whether `value` is greater than the given number
|
41
|
+
*
|
42
|
+
* Parameters:
|
43
|
+
* number - the number to compare against
|
44
|
+
*
|
45
|
+
* Usage:
|
46
|
+
*
|
47
|
+
* {{ 15 | :gt( 5 ) }} // => true
|
48
|
+
*/
|
49
|
+
|
50
|
+
Walrus.addFilter('gt', function(value, number) {
|
51
|
+
return value > number;
|
52
|
+
});
|
53
|
+
|
54
|
+
/**
|
55
|
+
* *:gte*
|
56
|
+
* Returns whether `value` is greater than or equal to the given number
|
57
|
+
*
|
58
|
+
* Parameters:
|
59
|
+
* number - the number to compare against
|
60
|
+
*
|
61
|
+
* Usage:
|
62
|
+
*
|
63
|
+
* {{ 15 | :gte( 5 ) }} // => true
|
64
|
+
*/
|
65
|
+
|
66
|
+
Walrus.addFilter('gte', function(value, number) {
|
67
|
+
return value >= number;
|
68
|
+
});
|
69
|
+
|
70
|
+
/**
|
71
|
+
* *:lt*
|
72
|
+
* Returns whether `value` is less than the given number
|
73
|
+
*
|
74
|
+
* Parameters:
|
75
|
+
* number - the number to compare against
|
76
|
+
*
|
77
|
+
* Usage:
|
78
|
+
*
|
79
|
+
* {{ 15 | :lt( 5 ) }} // => false
|
80
|
+
*/
|
81
|
+
|
82
|
+
Walrus.addFilter('lt', function(value, number) {
|
83
|
+
return value < number;
|
84
|
+
});
|
85
|
+
|
86
|
+
/**
|
87
|
+
* *:lte*
|
88
|
+
* Returns whether `value` is less than or equal to the given number
|
89
|
+
*
|
90
|
+
* Parameters:
|
91
|
+
* number - the number to compare against
|
92
|
+
*
|
93
|
+
* Usage:
|
94
|
+
*
|
95
|
+
* {{ 15 | :lte( 5 ) }} // => false
|
96
|
+
*/
|
97
|
+
|
98
|
+
Walrus.addFilter('lte', function(value, number) {
|
99
|
+
return value <= number;
|
100
|
+
});
|
101
|
+
|
102
|
+
/**
|
103
|
+
* *:floor*
|
104
|
+
* Returns the given number rounded down to the nearest integer.
|
105
|
+
*
|
106
|
+
* Parameters: none
|
107
|
+
*
|
108
|
+
* Usage:
|
109
|
+
* {{ 5.6 | :floor }} // => 5
|
110
|
+
*/
|
111
|
+
|
112
|
+
Walrus.addFilter('floor', function(value) {
|
113
|
+
return Math.floor(value);
|
114
|
+
});
|
115
|
+
|
116
|
+
/**
|
117
|
+
* *:ceil*
|
118
|
+
* Returns the given number rounded up to the nearest integer.
|
119
|
+
*
|
120
|
+
* Parameters: none
|
121
|
+
*
|
122
|
+
* Usage:
|
123
|
+
* {{ 5.6 | :ceil }} // => 6
|
124
|
+
*/
|
125
|
+
|
126
|
+
Walrus.addFilter('ceil', function(value) {
|
127
|
+
return Math.ceil(value);
|
128
|
+
});
|
129
|
+
|
130
|
+
/**
|
131
|
+
* *:round*
|
132
|
+
* Returns the given number rounded to the nearest integer.
|
133
|
+
*
|
134
|
+
* Parameters: none
|
135
|
+
*
|
136
|
+
* Usage:
|
137
|
+
* {{ 5.6 | :round }} // => 6
|
138
|
+
*/
|
139
|
+
|
140
|
+
Walrus.addFilter('round', function(value) {
|
141
|
+
return Math.round(value);
|
142
|
+
});
|
143
|
+
|
144
|
+
}).call(this);
|
@@ -0,0 +1,127 @@
|
|
1
|
+
(function() {
|
2
|
+
var Walrus;
|
3
|
+
|
4
|
+
Walrus = (typeof exports !== "undefined" && exports !== null ? require('./walrus') : this).Walrus;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* *:reverse*
|
8
|
+
* Reverses a string.
|
9
|
+
*
|
10
|
+
* Parameters: none
|
11
|
+
*
|
12
|
+
* Usage:
|
13
|
+
*
|
14
|
+
* {{ "hello" | :reverse }} // => "olleh"
|
15
|
+
*/
|
16
|
+
|
17
|
+
Walrus.addFilter('reverse', function(value) {
|
18
|
+
return value.split('').reverse().join('');
|
19
|
+
});
|
20
|
+
|
21
|
+
/**
|
22
|
+
* *:downcase*
|
23
|
+
* Converts a string to lowercase characters. Opposite of `:upcase`.
|
24
|
+
*
|
25
|
+
* Parameters: none
|
26
|
+
*
|
27
|
+
* Usage:
|
28
|
+
*
|
29
|
+
* {{ "HelLO!" | :downcase }} // => "hello!"
|
30
|
+
*/
|
31
|
+
|
32
|
+
Walrus.addFilter('downcase', function(value) {
|
33
|
+
return value.toLowerCase();
|
34
|
+
});
|
35
|
+
|
36
|
+
/**
|
37
|
+
* *:upcase*
|
38
|
+
* Converts a string to uppercase characters. Opposite of `:downcase`.
|
39
|
+
*
|
40
|
+
* Parameters: none
|
41
|
+
*
|
42
|
+
* Usage:
|
43
|
+
*
|
44
|
+
* {{ "HelLO!" | :upcase }} // => "HELLO!"
|
45
|
+
*/
|
46
|
+
|
47
|
+
Walrus.addFilter('upcase', function(value) {
|
48
|
+
return value.toUpperCase();
|
49
|
+
});
|
50
|
+
|
51
|
+
/**
|
52
|
+
* *:squish*
|
53
|
+
* Removes all leading and trailing whitespace, then condenses any internal whitespace
|
54
|
+
* groups to a single space each.
|
55
|
+
*
|
56
|
+
* Parameters: none
|
57
|
+
*
|
58
|
+
* Usage:
|
59
|
+
*
|
60
|
+
* {{ " foo bar \n baz" | :squish }} // => "foo bar baz"
|
61
|
+
*/
|
62
|
+
|
63
|
+
Walrus.addFilter('squish', function(string) {
|
64
|
+
return Walrus.Utils.trim(string).replace(/\s+/g, ' ');
|
65
|
+
});
|
66
|
+
|
67
|
+
/**
|
68
|
+
* *:truncate*
|
69
|
+
* Truncates a string to the specified `length`, optionally breaking at a separator
|
70
|
+
* or providing a custom string to denote an omission.
|
71
|
+
*
|
72
|
+
* Parameters:
|
73
|
+
* length (int) - the number of characters to keep, at most
|
74
|
+
* separator (string) - Optional: a specified string to break on
|
75
|
+
* omission (string) - Optional: a string to denote an omission
|
76
|
+
*
|
77
|
+
* Usage:
|
78
|
+
*
|
79
|
+
* {{ "Once upon a time in a world far far away" | :truncate( 27, ' ' ) }} // => "Once upon a time in a..."
|
80
|
+
*/
|
81
|
+
|
82
|
+
Walrus.addFilter('truncate', function(string, length, separator, omission) {
|
83
|
+
var chars, stop;
|
84
|
+
if (separator == null) separator = false;
|
85
|
+
if (omission == null) omission = '...';
|
86
|
+
chars = length - omission.length;
|
87
|
+
stop = separator ? string.lastIndexOf(separator, chars) || chars : chars;
|
88
|
+
if (string.length > length) {
|
89
|
+
return string.substr(0, stop) + omission;
|
90
|
+
} else {
|
91
|
+
return string;
|
92
|
+
}
|
93
|
+
});
|
94
|
+
|
95
|
+
/**
|
96
|
+
* *:titleize*
|
97
|
+
* Capitalizes all words within a string
|
98
|
+
*
|
99
|
+
* Parameters: none
|
100
|
+
*
|
101
|
+
* Usage:
|
102
|
+
*
|
103
|
+
* { "man from the boondocks" | :titleize } // => "Man From The Boondocks"
|
104
|
+
* { "x-men: the last stand" | :titleize } // => "X Men: The Last Stand"
|
105
|
+
* { "TheManWithoutAPast" | :titleize } // => "The Man Without A Past"
|
106
|
+
* { "raiders_of_the_lost_ark" | :titleize } // => "Raiders Of The Lost Ark"
|
107
|
+
*/
|
108
|
+
|
109
|
+
Walrus.addFilter('titleize', function(string) {
|
110
|
+
var capitalize, title, word, words;
|
111
|
+
title = string.replace(/[ \-_]+/g, ' ');
|
112
|
+
words = Walrus.Utils.trim(title.replace(/([A-Z])/g, " $&")).split(' ');
|
113
|
+
capitalize = function(word) {
|
114
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
115
|
+
};
|
116
|
+
return ((function() {
|
117
|
+
var _i, _len, _results;
|
118
|
+
_results = [];
|
119
|
+
for (_i = 0, _len = words.length; _i < _len; _i++) {
|
120
|
+
word = words[_i];
|
121
|
+
_results.push(capitalize(word));
|
122
|
+
}
|
123
|
+
return _results;
|
124
|
+
})()).join(' ');
|
125
|
+
});
|
126
|
+
|
127
|
+
}).call(this);
|
data/walrus.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'walrus/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "walrus-rb"
|
8
|
+
spec.version = Walrus::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
10
|
+
spec.authors = ["Grant Klinsing"]
|
11
|
+
spec.email = ["grant@digitalopera.com"]
|
12
|
+
spec.summary = %q{Ruby bindings for the walrus.js templating library}
|
13
|
+
spec.description = %q{Uses the actual JavaScript implementation of walrus.js, but supports using Ruby objects as template contexts and Ruby procs as view functions and named helpers}
|
14
|
+
spec.homepage = "http://digitalopera.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "therubyracer", "~> 0.12.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec", "~> 2.0"
|
27
|
+
spec.add_development_dependency 'mocha', '~> 0.13.1'
|
28
|
+
spec.add_development_dependency 'guard-rspec', '~> 2.3.0'
|
29
|
+
spec.add_development_dependency 'guard-spork', '~> 1.5.0'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: walrus-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Grant Klinsing
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: therubyracer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.12.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.13.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.13.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.3.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.3.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-spork
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.5.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.5.0
|
111
|
+
description: Uses the actual JavaScript implementation of walrus.js, but supports
|
112
|
+
using Ruby objects as template contexts and Ruby procs as view functions and named
|
113
|
+
helpers
|
114
|
+
email:
|
115
|
+
- grant@digitalopera.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- Gemfile
|
123
|
+
- Guardfile
|
124
|
+
- MIT-LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- lib/walrus.rb
|
128
|
+
- lib/walrus/config.rb
|
129
|
+
- lib/walrus/context.rb
|
130
|
+
- lib/walrus/version.rb
|
131
|
+
- spec/blocks_spec.rb
|
132
|
+
- spec/collections_spec.rb
|
133
|
+
- spec/context_spec.rb
|
134
|
+
- spec/currencies_spec.rb
|
135
|
+
- spec/dates_spec.rb
|
136
|
+
- spec/domain_spec.rb
|
137
|
+
- spec/filters_spec.rb
|
138
|
+
- spec/inflections_spec.rb
|
139
|
+
- spec/math_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/strings_spec.rb
|
142
|
+
- spec/support/javascripts/walrus_domain_objects.js
|
143
|
+
- vendor/walrus.collections.js
|
144
|
+
- vendor/walrus.currencies.js
|
145
|
+
- vendor/walrus.dates.js
|
146
|
+
- vendor/walrus.inflections.js
|
147
|
+
- vendor/walrus.js
|
148
|
+
- vendor/walrus.math.js
|
149
|
+
- vendor/walrus.strings.js
|
150
|
+
- walrus.gemspec
|
151
|
+
homepage: http://digitalopera.com
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.2.0
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Ruby bindings for the walrus.js templating library
|
175
|
+
test_files:
|
176
|
+
- spec/blocks_spec.rb
|
177
|
+
- spec/collections_spec.rb
|
178
|
+
- spec/context_spec.rb
|
179
|
+
- spec/currencies_spec.rb
|
180
|
+
- spec/dates_spec.rb
|
181
|
+
- spec/domain_spec.rb
|
182
|
+
- spec/filters_spec.rb
|
183
|
+
- spec/inflections_spec.rb
|
184
|
+
- spec/math_spec.rb
|
185
|
+
- spec/spec_helper.rb
|
186
|
+
- spec/strings_spec.rb
|
187
|
+
- spec/support/javascripts/walrus_domain_objects.js
|