acts_as_metable 0.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: 09a0163d1512591eadf2fc9b9fdb8608ec284d9a
4
+ data.tar.gz: 54b90a2481fb9c15318eee02883d1419d731644b
5
+ SHA512:
6
+ metadata.gz: fa39d7b2b0d720f5b09e2461a83fd13511fc95565d88ecdeefd1dd6a96fd4af74b74e10947a09755a6e200dbd191b89b2a620e54c1b68745ee8e0d08329b8e34
7
+ data.tar.gz: 58ce21b856b9e36c00d9441f6a49a410fdcfeaef4562912e03868148c97c1a615844cf330773edb41531fea4f4dab1837d3734ea2c75c28977f2667ba069eaeb
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Sergey Novikov
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/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ActsAsMetable'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ module ActsAsMetable
2
+ class Tag < ActiveRecord::Base
3
+ belongs_to :metable, polymorphic: true
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class CreateActsAsMetableTags < ActiveRecord::Migration
2
+ def change
3
+ create_table :acts_as_metable_tags do |t|
4
+ t.references :metable, polymorphic: true, index: true
5
+ t.string :name
6
+ t.string :content
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ require 'acts_as_metable/metable'
2
+ require 'acts_as_metable/engine'
3
+
4
+ module ActsAsMetable
5
+ @tags = []
6
+
7
+ class << self
8
+ def add_tag name, content
9
+ @tags << { :name => name, :content => content }
10
+ end
11
+
12
+ def add_model model_name, id
13
+ ActsAsMetable::Tag.where(:metable_type => model_name.to_s.camelize, :metable_id => id).each do |tag|
14
+ add_tag tag.name, tag.content
15
+ end
16
+ end
17
+
18
+ def render
19
+ result = @tags.map do |tag|
20
+ ActionController::Base.helpers.tag(:meta, name: tag[:name], content: tag[:content])
21
+ end.join("\n").html_safe
22
+
23
+ @tags = []
24
+
25
+ result
26
+ end
27
+ end
28
+ end
29
+
30
+ ActiveSupport.on_load :active_record do
31
+ extend ActsAsMetable::Metable
32
+ end
@@ -0,0 +1,5 @@
1
+ module ActsAsMetable
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ActsAsMetable
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module ActsAsMetable
2
+ module Metable
3
+ def acts_as_metable
4
+ class_eval do
5
+ has_many :meta_tags, as: :metable, dependent: :destroy, class_name: '::ActsAsMetable::Tag', :foreign_key => :metable_id
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ActsAsMetable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/base'
2
+
3
+ module ActsAsMetable
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ def install_migrations
7
+ Dir.chdir(Rails.root) do
8
+ `rake acts_as_metable:install:migrations`
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_metable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Novikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-13 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.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.10
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.10
41
+ description: Meta tags from polymorphic model.
42
+ email:
43
+ - novikov359@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - Rakefile
50
+ - app/models/acts_as_metable/tag.rb
51
+ - db/migrate/20150913104251_create_acts_as_metable_tags.rb
52
+ - lib/acts_as_metable.rb
53
+ - lib/acts_as_metable/engine.rb
54
+ - lib/acts_as_metable/metable.rb
55
+ - lib/acts_as_metable/version.rb
56
+ - lib/generators/acts_as_metable/install_generator.rb
57
+ homepage: https://github.com/droptheplot/acts_as_metable
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.6
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Meta tags from polymorphic model.
81
+ test_files: []