tb_liquid 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8ecad380e23288e05cc223b0a527a415d079ff0
4
+ data.tar.gz: 4bb34b1910e24133c404e2d70283a06e8a08ec47
5
+ SHA512:
6
+ metadata.gz: 6b612b54c74f5c108773a584131ee897443ad4826999056dd16d1d196fe834e93c2efdb17909300c03ed33c0c0b1d971a223b22c58acdc87bd7e47788195dd20
7
+ data.tar.gz: 887f983f8f73b514270093c5763b4cee44871db1ddc3f93a3b0afc5cdac96a774dbbdd5199fc3a1e18c2dabe688d79a22207b6095ed594e30455d69d424c52be
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # TB Liquid
2
+
3
+ TB Liquid is a simple gem that helps manage liquid tags within your Twice Baked application. Specifically, TB Liquid provides reusable code to handle expiring content when a liquid tag has changed.
4
+
5
+ ## Use Case
6
+
7
+ Say you have a `SpudPage` object that contains your custom liquid tag called `widget`. The `widget` tag is based on your `Widget` data model. Any time a change is made to your data, you'll need to send a message to `SpudPage` asking it to re-process it's content. TB Liquid helps faciliate this.
8
+
9
+ ## Code Sample
10
+
11
+ In this example, `:widget` represents the liquid tag name and `:name` represents the model property used to fetch the liquid tag value. This can be any column or method on your model object.
12
+
13
+ class Widget < ActiveRecord::Base
14
+ acts_as_spud_liquid_tag :widget, :name
15
+ end
16
+
17
+ class SpudPagePartial < ActiveRecord::Base
18
+ acts_as_spud_liquid_content
19
+ def postprocess_content
20
+ # handle liquid parsing here
21
+ end
22
+ end
23
+
24
+ ## How it Works
25
+
26
+ The `acts_as_spud_liquid_tag` method adds an `after_update` hook to your model. The hook does a few things.
27
+
28
+ - Find any `SpudLiquidTag` object with matching tag name and value properties.
29
+ - Call `postprocess_content` on any objects attached to any found tags.
30
+ - That's it!
31
+
32
+ The key is that the model attached to `SpudLiquidTag` must implement a `postprocess_content` method. Look at the `SpudPagePartial` model in TB CMS for an example implementation.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'TbLiquid'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ #APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ #load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,36 @@
1
+ module TbLiquid
2
+ module ActsAsLiquidContent
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ extend ClassMethods
6
+ end
7
+
8
+ def postprocess_content()
9
+ raise 'Models that call acts_as_liquid_content should implement a postprocess_content method.'
10
+ end
11
+
12
+ def update_spud_liquid_tag_list()
13
+ if @spud_liquid_template_parsed.nil?
14
+ @spud_liquid_template_parsed = Liquid::Template.parse(self.content)
15
+ end
16
+ self.spud_liquid_tags.destroy_all
17
+ @spud_liquid_template_parsed.root.nodelist.each do |node|
18
+ if !node.is_a?(String) && defined?(node.tag_name) && defined?(node.tag_value)
19
+ self.spud_liquid_tags.create(:tag_name => node.tag_name,:value => node.tag_value)
20
+ end
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+ attr_accessor :spud_liquid_template_parsed
26
+ def acts_as_spud_liquid_content
27
+ self.class_eval do
28
+ has_many :spud_liquid_tags, :as => :attachment, :dependent => :destroy
29
+ before_save :postprocess_content
30
+ after_save :update_spud_liquid_tag_list
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,38 @@
1
+ module TbLiquid
2
+ module ActsAsLiquidTag
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ extend ClassMethods
6
+ end
7
+
8
+ def expire_spud_liquid_tags
9
+ value_property = self.class.spud_liquid_tag_value_property
10
+ values = [self.send(value_property)]
11
+ if self.respond_to?("#{value_property}_changed?") && self.send("#{value_property}_changed?")
12
+ values << self.send("#{value_property}_was")
13
+ end
14
+ SpudLiquidTag.where(:tag_name => self.class.spud_liquid_tag_name, :value => values).includes(:attachment).each do |tag|
15
+ attachment = tag.attachment
16
+ if attachment.respond_to?(:postprocess_content)
17
+ attachment.postprocess_content()
18
+ attachment.save()
19
+ else
20
+ logger.debug "SpudLiquidTag attachment of class #{attachment.class} does not implement :postprocess_content."
21
+ end
22
+ end
23
+ end
24
+
25
+ module ClassMethods
26
+ attr_accessor :spud_liquid_tag_name, :spud_liquid_tag_value_property
27
+ def acts_as_spud_liquid_tag(tag_name, value_property)
28
+ @spud_liquid_tag_name = tag_name
29
+ @spud_liquid_tag_value_property = value_property
30
+ self.class_eval do
31
+ after_update :expire_spud_liquid_tags
32
+ after_touch :expire_spud_liquid_tags
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ class SpudLiquidTag < ActiveRecord::Base
2
+ belongs_to :attachment, :polymorphic => true, :touch => true
3
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ TbLiquid::Engine.routes.draw do
2
+ end
@@ -0,0 +1,12 @@
1
+ class CreateTbLiquidSpudLiquidTags < ActiveRecord::Migration
2
+ def change
3
+ create_table :spud_liquid_tags do |t|
4
+ t.integer :attachment_id
5
+ t.string :attachment_type
6
+ t.string :tag_name
7
+ t.string :value
8
+ t.timestamps
9
+ end
10
+ add_index :spud_liquid_tags, [:tag_name, :value]
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :tb_liquid do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,18 @@
1
+ require 'liquid'
2
+
3
+ module TbLiquid
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace TbLiquid
6
+
7
+ require "#{root}/app/concerns/tb_liquid/acts_as_liquid_content"
8
+ require "#{root}/app/concerns/tb_liquid/acts_as_liquid_tag"
9
+
10
+ initializer 'tb_liquid.acts_as_spud_liquid_tag' do |config|
11
+ ActiveRecord::Base.class_eval do
12
+ include TbLiquid::ActsAsLiquidTag
13
+ include TbLiquid::ActsAsLiquidContent
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module TbLiquid
2
+ VERSION = "1.0.1"
3
+ end
data/lib/tb_liquid.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "tb_liquid/engine"
2
+
3
+ module TbLiquid
4
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tb_liquid
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Westlake Design
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tb_core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: liquid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Simgle engine for managing liquid tags in Twice Baked.
56
+ email:
57
+ - greg@westlakedesign.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/concerns/tb_liquid/acts_as_liquid_content.rb
66
+ - app/concerns/tb_liquid/acts_as_liquid_tag.rb
67
+ - app/models/spud_liquid_tag.rb
68
+ - config/routes.rb
69
+ - db/migrate/20140110142037_create_tb_liquid_spud_liquid_tags.rb
70
+ - lib/tasks/tb_liquid_tasks.rake
71
+ - lib/tb_liquid.rb
72
+ - lib/tb_liquid/engine.rb
73
+ - lib/tb_liquid/version.rb
74
+ homepage: http://bitbucket.org/westlakedesign/tb_liquid
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Simgle engine for managing liquid tags in Twice Baked.
97
+ test_files: []