liquid_stream 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +16 -5
- data/lib/liquid_stream/stream.rb +22 -12
- data/{spec → lib}/liquid_stream/utils.rb +0 -0
- data/lib/liquid_stream/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 030832c0751d60e0b1ba8a20b10dd2c6c5da59bc
|
4
|
+
data.tar.gz: ccaf5b71f6f6d8cada5f15ec8fe675aca28f3d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ba6ae8462051277b9ef97d7837f6ae92e68334b619f67301aa50fcd3fdf4dbc6a0313ef72ca398592a2b6e40168f3b5239e2335da14af712d0f82d278422b59
|
7
|
+
data.tar.gz: 92f0d41dd6b43e0158a711bc619a495c0ba1779c0db771f41b7ac0c83a7b3c77995d24f02541acef582ffbceb80fbf1c95d94c95aed11b4c186505b75b3e7ecf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
# LiquidStream
|
2
2
|
|
3
|
-
|
3
|
+
This library does two things:
|
4
|
+
|
5
|
+
1) Allows **chaining** of Liquid objects with a clean DSL, which allows a more Ruby-like way to traverse Liquid objects. For example:
|
4
6
|
|
5
7
|
{% for post in posts.published.popular do %}
|
6
8
|
{{ post.name }}
|
7
9
|
{% endfor %}
|
8
10
|
|
11
|
+
2) Mimic accepting of arguments on drops
|
12
|
+
|
13
|
+
{{ image.resize_to["240x240#"].url }}
|
14
|
+
{{ images["23"].url }}
|
15
|
+
|
9
16
|
[See why](https://github.com/Shopify/liquid/issues/29).
|
10
17
|
|
11
18
|
## Installation
|
@@ -63,7 +70,7 @@ Then, in Liquid:
|
|
63
70
|
|
64
71
|
### Stream Context
|
65
72
|
|
66
|
-
LiquidStream has a notion of context too. To avoid confusion with Liquid's context, let's call it
|
73
|
+
LiquidStream has a notion of context too. To avoid confusion with Liquid's context, let's call it "stream context". The reason there's a stream context is so that if you have a need to share information within a chained stream, then you need to pass it as a hash. I found this useful when the I needed the streams to know about which controller it was being used:
|
67
74
|
|
68
75
|
class PostsController < ApplicationController
|
69
76
|
def show
|
@@ -80,7 +87,7 @@ LiquidStream has a notion of context too. To avoid confusion with Liquid's conte
|
|
80
87
|
if controller.request.fullpath =~ /^preview/
|
81
88
|
polymorphic_path :preview, source
|
82
89
|
else
|
83
|
-
|
90
|
+
polymorphic_path source
|
84
91
|
end
|
85
92
|
end
|
86
93
|
|
@@ -92,7 +99,7 @@ LiquidStream has a notion of context too. To avoid confusion with Liquid's conte
|
|
92
99
|
|
93
100
|
end
|
94
101
|
|
95
|
-
It's a very specific use-case, but this allows you to render the links to other posts a different way if the person viewing is viewing the post from
|
102
|
+
It's a very specific use-case, but this allows you to render the links to other posts a different way if the person viewing is viewing the post from `/preview/posts/:id` compared to what is rendered when in `/posts/:id`. If you find other uses please fork this repo and add it to this readme.
|
96
103
|
|
97
104
|
## Stream is a Liquid::Drop
|
98
105
|
|
@@ -102,7 +109,7 @@ A stream is a drop - with extra stuff added on to it.
|
|
102
109
|
|
103
110
|
You may not want to expose something that will make it easy for a user to break your system. For example, let's say you have 2 million posts, then you won't want to expose all of those posts through a stream:
|
104
111
|
|
105
|
-
posts = Post.scoped # ActiveRecord's scoped returns a lazily executed Arel. If you call #all on this, you'll get 2 million records
|
112
|
+
posts = Post.scoped # ActiveRecord's scoped returns a lazily executed Arel. If you call #all or #to_a on this, you'll get 2 million records
|
106
113
|
posts_stream = PostsStream.new(posts)
|
107
114
|
posts_stream.to_a # boom!
|
108
115
|
|
@@ -113,3 +120,7 @@ You may not want to expose something that will make it easy for a user to break
|
|
113
120
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
114
121
|
4. Push to the branch (`git push origin my-new-feature`)
|
115
122
|
5. Create new Pull Request
|
123
|
+
|
124
|
+
## Thanks
|
125
|
+
|
126
|
+
Check out the [awesome contributors](https://github.com/ramontayag/liquid_stream/graphs/contributors).
|
data/lib/liquid_stream/stream.rb
CHANGED
@@ -17,19 +17,9 @@ module LiquidStream
|
|
17
17
|
# DefinesStreamMethod
|
18
18
|
if block_given?
|
19
19
|
if options.has_key?(:matching)
|
20
|
-
self.
|
21
|
-
instance_exec(method_arg, &block)
|
22
|
-
end
|
20
|
+
self.define_method_with_block method_name, block
|
23
21
|
else
|
24
|
-
self.
|
25
|
-
class_name = generate_stream_class_name method_name
|
26
|
-
klass = find_or_create_stream_class class_name
|
27
|
-
stream = klass.new(source, stream_context)
|
28
|
-
klass.send :define_method, :before_method do |before_method_arg|
|
29
|
-
stream.instance_exec(before_method_arg, &block)
|
30
|
-
end
|
31
|
-
stream
|
32
|
-
end
|
22
|
+
self.delegate_method_with_block_to_new_stream_instance method_name, block
|
33
23
|
end
|
34
24
|
else
|
35
25
|
self.send(:define_method, method_name) do |*args|
|
@@ -90,6 +80,26 @@ module LiquidStream
|
|
90
80
|
|
91
81
|
private
|
92
82
|
|
83
|
+
def self.define_method_with_block method_name, block
|
84
|
+
self.send :define_method, method_name do |method_arg|
|
85
|
+
self.instance_exec(method_arg, &block)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.delegate_method_with_block_to_new_stream_instance method_name, block
|
90
|
+
self.send :define_method, method_name do |*method_args|
|
91
|
+
class_name = generate_stream_class_name method_name
|
92
|
+
stream_klass = find_or_create_stream_class class_name
|
93
|
+
|
94
|
+
stream_instance = stream_klass.new(source, stream_context)
|
95
|
+
|
96
|
+
stream_klass.send :define_method, :before_method do |before_method_arg|
|
97
|
+
stream_instance.instance_exec(before_method_arg, &block)
|
98
|
+
end
|
99
|
+
stream_instance
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
93
103
|
def matching_stream_names_for(method_name)
|
94
104
|
self.class.liquid_streams.select do |stream_name, data|
|
95
105
|
match_regex = data[:options][:matching]
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramon Tayag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/liquid_stream/errors.rb
|
126
126
|
- lib/liquid_stream/stream.rb
|
127
127
|
- lib/liquid_stream/streams.rb
|
128
|
+
- lib/liquid_stream/utils.rb
|
128
129
|
- lib/liquid_stream/version.rb
|
129
130
|
- liquid_stream.gemspec
|
130
131
|
- spec/fixtures/base.rb
|
@@ -141,7 +142,6 @@ files:
|
|
141
142
|
- spec/integrations/allow_chaining_via_stream_spec.rb
|
142
143
|
- spec/liquid_stream/stream_spec.rb
|
143
144
|
- spec/liquid_stream/streams_spec.rb
|
144
|
-
- spec/liquid_stream/utils.rb
|
145
145
|
- spec/liquid_stream/utils_spec.rb
|
146
146
|
- spec/spec_helper.rb
|
147
147
|
- spec/support/streamer_resetter.rb
|
@@ -184,7 +184,6 @@ test_files:
|
|
184
184
|
- spec/integrations/allow_chaining_via_stream_spec.rb
|
185
185
|
- spec/liquid_stream/stream_spec.rb
|
186
186
|
- spec/liquid_stream/streams_spec.rb
|
187
|
-
- spec/liquid_stream/utils.rb
|
188
187
|
- spec/liquid_stream/utils_spec.rb
|
189
188
|
- spec/spec_helper.rb
|
190
189
|
- spec/support/streamer_resetter.rb
|