adva_meta_tags 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9f6d1dc8772d47868842b1d04e713053ad151bf
4
+ data.tar.gz: 358afb383e4017ae8b1ca50edff00d4a04446081
5
+ SHA512:
6
+ metadata.gz: 80f22acc7ea3043dcf4e3730d80bed3adc0627fe0175c865abad6853ec3952977774981106fd1a6cca3ad232e66b941786c88bf9813d6992a17a68dabc176a28
7
+ data.tar.gz: d0be06aa5d6011103252c96e5344a8f8fa1014c5eaa81dd12b5e41f27fe7e5d9d17ebd466e8be7a91bd6063d6fa26aceaae2242f6f90221f4958b1773afd968d
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in adva_meta_tags.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Micah Geisel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ in your layout:
2
+
3
+ <%= meta_tags(@article) if @article %>
@@ -0,0 +1,29 @@
1
+ # AdvaMetaTags
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'adva_meta_tags'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install adva_meta_tags
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/adva_meta_tags/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Micah Geisel"]
6
+ gem.email = ["micah@botandrose.com"]
7
+ gem.description = %q{Adva Meta Tags}
8
+ gem.summary = %q{Engine for Adva CMS meta tag handling}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "adva_meta_tags"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = AdvaMetaTags::VERSION
17
+ end
@@ -0,0 +1,30 @@
1
+ module MetaTagsHelper
2
+ DEFAULT_FIELDS = %w(author geourl copyright keywords description)
3
+
4
+ def meta_tags(resource=nil)
5
+ current_resource = controller.try(:current_resource)
6
+ resources = [resource, current_resource, @site].compact
7
+
8
+ # TODO: check if we actually need this fallback
9
+ # fields = resource.class.try(:meta_fields) || DEFAULT_FIELDS
10
+
11
+ DEFAULT_FIELDS.map do |name|
12
+ resource = resources.find do |r|
13
+ r.respond_to?(:"meta_#{name}")
14
+ end
15
+
16
+ if resource
17
+ content = meta_value_from(resource.send(:"meta_#{name}"), resource.try(:"default_meta_#{name}"))
18
+ meta_tag(name, content)
19
+ end
20
+ end.join("\n").html_safe
21
+ end
22
+
23
+ def meta_tag(name, content)
24
+ tag 'meta', :name => name, :content => content
25
+ end
26
+
27
+ def meta_value_from(*args)
28
+ args.detect { |arg| arg.present? }
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ <%= f.text_field :meta_keywords, :label => true, :value => meta_value_from(@article.meta_keywords, @site.meta_keywords), :hint => :'adva.hints.meta_keywords' %>
2
+ <%= f.text_area :meta_description, :class => 'small', :label => true, :hint => :'adva.hints.meta_description' %>
3
+ <%= f.text_field :meta_author, :label => true, :value => meta_value_from(@article.meta_author, @site.meta_author, current_user.name) %>
4
+ <%= f.text_field :meta_copyright, :label => true, :value => meta_value_from(@article.meta_copyright, @site.meta_copyright, "#{Date.today.year}, #{current_user.name}") %>
5
+ <%= f.text_field :meta_geourl, :label => true, :value => meta_value_from(@article.meta_geourl, @site.meta_geourl),
6
+ :hint => I18n.t(:'adva.meta_tags.hints.meta_geourl',
7
+ :meta_geourl_link => link_to(I18n.t(:'adva.meta_tags.hints.meta_geourl_link'), I18n.t(:'adva.meta_tags.hints.meta_geourl_link'), :popup => true)) %>
@@ -0,0 +1,15 @@
1
+ <h2><%= t(:'adva.titles.meta_tags') %></h2>
2
+ <% f.field_set :meta_tags do %>
3
+ <% column do %>
4
+ <%= f.text_field :meta_keywords, :label => true, :hint => :'adva.hints.meta_keywords' %>
5
+ <%= f.text_area :meta_description, :class => 'small', :label => true, :hint => :'adva.hints.meta_description' %>
6
+ <% end %>
7
+
8
+ <% column do %>
9
+ <%= f.text_field :meta_author, :label => true, :tabindex => :site_meta_keywords %>
10
+ <%= f.text_field :meta_copyright, :label => true %>
11
+ <%= f.text_field :meta_geourl, :label => true,
12
+ :hint => I18n.t(:'adva.meta_tags.hints.meta_geourl',
13
+ :meta_geourl_link => link_to(I18n.t(:'adva.meta_tags.hints.meta_geourl_link'), I18n.t(:'adva.meta_tags.hints.meta_geourl_link'), :popup => true)) %>
14
+ <% end %>
15
+ <% end %>
@@ -0,0 +1,19 @@
1
+ ActionDispatch::Callbacks.to_prepare do
2
+ Article.class_eval do
3
+ cattr_accessor :meta_fields
4
+ self.meta_fields = %w(keywords description author copyright geourl)
5
+
6
+ def default_meta_description
7
+ sanitizer = defined?(Rails::Html::WhiteListSanitizer) ? Rails::Html::WhiteListSanitizer.new : HTML::FullSanitizer.new
8
+ sanitizer.sanitize(body).gsub(/\s+/, " ").strip.truncate(160)
9
+ end
10
+ end
11
+ end
12
+
13
+ class ArticleFormBuilder < ExtensibleFormBuilder
14
+ after :article, :tab_options do |f|
15
+ tab :meta_tags do |f|
16
+ render :partial => 'admin/articles/meta_tags', :locals => { :f => f }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ ActionDispatch::Callbacks.to_prepare do
2
+ require_dependency 'site'
3
+
4
+ class Site
5
+ cattr_reader :meta_fields
6
+ @@meta_fields = %w(keywords description author copyright geourl)
7
+ end
8
+ end
9
+
10
+ class SiteFormBuilder < ExtensibleFormBuilder
11
+ after(:site, :default_fields) do |f|
12
+ render :partial => 'admin/sites/meta_tags', :locals => { :f => f }
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ de:
2
+ adva:
3
+ meta_tags:
4
+ hints:
5
+ meta_geourl_link: http://geourl.org/
6
+ meta_geourl: "Nähere Details unter %{meta_geourl_link} (Englisch)."
@@ -0,0 +1,6 @@
1
+ en:
2
+ adva:
3
+ meta_tags:
4
+ hints:
5
+ meta_geourl_link: http://geourl.org/
6
+ meta_geourl: "See %{meta_geourl_link} for details."
@@ -0,0 +1,17 @@
1
+ class AddMetatagsToContents < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :contents, :meta_author, :string
4
+ add_column :contents, :meta_geourl, :string
5
+ add_column :contents, :meta_copyright, :string
6
+ add_column :contents, :meta_keywords, :string
7
+ add_column :contents, :meta_description, :text
8
+ end
9
+
10
+ def self.down
11
+ remove_column :contents, :meta_author
12
+ remove_column :contents, :meta_geourl
13
+ remove_column :contents, :meta_copyright
14
+ remove_column :contents, :meta_keywords
15
+ remove_column :contents, :meta_description
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class AddMetatagsToSites < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :sites, :meta_author, :string
4
+ add_column :sites, :meta_geourl, :string
5
+ add_column :sites, :meta_copyright, :string
6
+ add_column :sites, :meta_keywords, :string
7
+ add_column :sites, :meta_description, :text
8
+ end
9
+
10
+ def self.down
11
+ remove_column :sites, :meta_author
12
+ remove_column :sites, :meta_geourl
13
+ remove_column :sites, :meta_copyright
14
+ remove_column :sites, :meta_keywords
15
+ remove_column :sites, :meta_description
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # require "adva_meta_tags/version"
2
+ require "rails"
3
+
4
+ module AdvaMetaTags
5
+ class Engine < Rails::Engine
6
+ initializer "adva_meta_tags.init" do
7
+ BaseController.helper :meta_tags
8
+ Admin::BaseController.helper :meta_tags
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module AdvaMetaTags
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,42 @@
1
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../app/helpers')
2
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+ require 'meta_tags_helper'
4
+
5
+ require 'rubygems'
6
+ require 'action_controller'
7
+ require 'action_view'
8
+ require 'action_view/test_case'
9
+
10
+ class RailsExtTest < ActionView::TestCase
11
+ class MetaTagThingy
12
+ attr_accessor :meta_author, :meta_geourl, :meta_copyright, :meta_keywords, :meta_description
13
+ def initialize(*args)
14
+ @meta_author, @meta_geourl, @meta_copyright, @meta_keywords, @meta_description = *args
15
+ end
16
+ end
17
+
18
+ class MetaTagThingyController
19
+ def current_resource
20
+ MetaTagThingy.new("the author", "the geourl", "the copyright", "the keywords", "the description")
21
+ end
22
+ end
23
+
24
+ tests MetaTagsHelper
25
+
26
+ def setup
27
+ super
28
+ @controller = MetaTagThingyController.new
29
+ @resource = MetaTagThingy.new("the author", "the geourl", "the copyright", "the keywords", "the description")
30
+ @tags = meta_tags(@resource).split(/\n/)
31
+ end
32
+
33
+ test "returns meta tags as expected" do
34
+ assert Array === @tags
35
+ assert_equal 5, @tags.size
36
+ assert_equal '<meta content="the author" name="author" />', @tags.first
37
+ end
38
+
39
+ test "#meta_value_from returns first non-blank value" do
40
+ assert_equal 'foo', meta_value_from(nil, '', 'foo')
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adva_meta_tags
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Micah Geisel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Adva Meta Tags
14
+ email:
15
+ - micah@botandrose.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE
23
+ - README
24
+ - README.md
25
+ - Rakefile
26
+ - adva_meta_tags.gemspec
27
+ - app/helpers/meta_tags_helper.rb
28
+ - app/views/admin/articles/_meta_tags.html.erb
29
+ - app/views/admin/sites/_meta_tags.html.erb
30
+ - config/initializers/article.rb
31
+ - config/initializers/site.rb
32
+ - config/locales/de.yml
33
+ - config/locales/en.yml
34
+ - db/migrate/20090218083515_add_metatags_to_contents.rb
35
+ - db/migrate/20090522082000_add_metatags_to_sites.rb
36
+ - lib/adva_meta_tags.rb
37
+ - lib/adva_meta_tags/version.rb
38
+ - test/meta_tags_test.rb
39
+ homepage: ''
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.4.6
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Engine for Adva CMS meta tag handling
62
+ test_files:
63
+ - test/meta_tags_test.rb