Skip to content

Commit

Permalink
bug fix : og scope
Browse files Browse the repository at this point in the history
  • Loading branch information
yulii committed Aug 31, 2013
1 parent 9e9ce4e commit dce8b2a
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 38 deletions.
6 changes: 5 additions & 1 deletion app/views/snipp/html.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<%
set_html_meta({
og: {
type: "article"
},
link: {
canonical: "http://127.0.0.1/canonical"
}
}, {
value: "Embedding Values"
value: "Embedding Values",
text: "Insert"
})
%>
<h1>Html - Snippets Sample</h1>
14 changes: 12 additions & 2 deletions config/locales/snipp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@ en:
meta:
title: "Default Title"
description: "Default Description"
keywords: "Default Description"
keywords: "Default Keywords"
og:
site_name: "Snipp"
title: "Default Title for Open Graph"
description: "Default Description for Open Graph"
type: "website"

views:
snipp:
html:
meta:
title: "HTML Title -- %{value}"
description: "Render from I18n"
page_title: "HTML Title -- %{value} Page %{page}"
og:
title: "Open Graph Title from I18n"

breadcrumb:
meta:
title: "Snipp"

breadcrumb:
# Sample
index: "Top"
Expand Down
23 changes: 12 additions & 11 deletions lib/snipp/markups/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ module Html

def set_html_meta args, options = {}
i18n_options = {
#scope: ([:views].push(*params[:controller].split('/')) << params[:action] << :meta),
scope: [:views, params[:controller], params[:action], :meta],
default_scope: [:default, :meta]
}.merge(options)

link = args.delete(:link)
html_meta.merge!(link: link) if link

Snipp.config.html_meta_tags.merge(args).each do |name, content|
value = html_meta_contents(name, content, i18n_options)
Snipp.config.html_meta_tags.each do |name, content|
value = html_meta_contents(name, content, args[name], i18n_options)
html_meta[name] = value unless value.blank?
end
end
Expand Down Expand Up @@ -40,24 +41,24 @@ def html_meta_tags
end

meta_link.each do |rel, href|
result << tag(:link, :rel => rel, :href => href) unless href.blank?
result << tag(:link, rel: rel, href: href) unless href.blank?
end

result.blank? ? nil : result.html_safe
end

private
def html_meta_contents property, content, options = {}
private
def html_meta_contents property, content, arg, options = {}
result = {}
if content.is_a?(Hash)
opts = options.dup
opts[:scope] << property
opts[:default_scope] << property
content.each do |key, value|
options = options.dup
options[:scope] << property
options[:default_scope] << property
result[key] = html_meta_contents(key, value, options)
result[key] = html_meta_contents(key, value, (arg ? arg[key] : nil), opts)
end
else
result = content
result = arg||content
result = I18n.t(property, options.merge(default: '')) if result.blank?
result = I18n.t(property, scope: options[:default_scope], default: '') if result.blank?
end
Expand All @@ -75,7 +76,7 @@ def build_meta_property_tags(property, content)
if c.is_a?(Hash)
result << build_meta_property_tags(property, c)
else
result << tag(:meta, :property => "#{property}", :content => c) unless c.blank?
result << tag(:meta, property: "#{property}", content: c) unless c.blank?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/snipp/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Snipp
VERSION = "0.1.1"
VERSION = "0.1.2"
end
1 change: 1 addition & 0 deletions snipp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
gem.description = %q{Search Engine Optimization (SEO) helpers for Ruby on Rails}
gem.summary = %q{Let search engines understand the content on your website}
gem.homepage = "https://github.com/yulii/snipp"
gem.license = 'MIT'

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
Expand Down
28 changes: 20 additions & 8 deletions spec/fake_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,47 @@
app.initialize!

# routing
ITEMTYPES = [:index, :html, :breadcrumb, :geo]
ITEMTYPES = [:index, :html, :breadcrumb, :geo]
#ACTION_NAME = lambda {|e| "action#{e}" }
app.routes.draw do

ITEMTYPES.each do |e|
get "/#{e}" => "snipp##{e}", as: e
end

# HTML Meta Tags
get "/html" => "snipp#html", as: :html

# for Breadcumb
get "/foods" => "snipp#breadcrumb", as: :foods
get "/foods/fruits" => "snipp#breadcrumb", as: :fruits
get "/foods/fruits/:color" => "snipp#breadcrumb", as: :fruits_color
get "/foods/fruits/:color/:name" => "snipp#breadcrumb", as: :food

# scope "/admin" ,:module=>'admin' ,as: :admin do
# 10.times do |e|
# get "/#{ACTION_NAME.call(e)}" => "snipp##{ACTION_NAME.call(e)}"
# end
# end
end

# controllers
class ApplicationController < ActionController::Base ; end

class SnippController < ApplicationController

ITEMTYPES.each do |e|
define_method e do
end
end
ITEMTYPES.each {|e| define_method(e, lambda {}) }

end

#module Admin
# class SnippController < ApplicationController
#
# 10.times do |e|
# define_method ACTION_NAME.call(e) do
# render text: ACTION_NAME.call(e), layout: "application"
# end
# end
#
# end
#end

# helpers
Object.const_set(:ApplicationHelper, Module.new)
36 changes: 21 additions & 15 deletions spec/snipp/markups/html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,38 @@ class Snipp::Markup::Html::Spec
DEFAULT_SCOPE = [:default, :meta]
PAGE_SCOPE = [:views, :snipp, :html, :meta]

META = [
{ id: "TDK", title: I18n.t(:title, scope: PAGE_SCOPE, value: "Embedding Values"), description: I18n.t(:description, scope: DEFAULT_SCOPE), keywords: I18n.t(:keywords, scope: DEFAULT_SCOPE) }
]

META = {
title: I18n.t(:title ,scope: PAGE_SCOPE, value: "Embedding Values"),
description: I18n.t(:description ,scope: PAGE_SCOPE),
keywords: I18n.t(:keywords ,scope: DEFAULT_SCOPE)
}
OG = {
site_name: I18n.t("og.site_name" ,scope: DEFAULT_SCOPE),
title: I18n.t("og.title" ,scope: PAGE_SCOPE ,text: "Insert"),
description: I18n.t("og.description" ,scope: DEFAULT_SCOPE),
type: "article"
}
end

describe Snipp::Markup::Html do

before do
Snipp::Hooks.init
visit "/html"
#puts page.html
end

describe "HTML Meta Tags" do

Snipp::Markup::Html::Spec::META.each do |e|
id = e.delete(:id)
context id do
e.each do |key, value|
it "should have a `#{key}` tag" do
expect(page).to have_selector("meta[name=\"#{key}\"][content=\"#{value}\"]", count: 1)
end
end
context "HTML Meta Tags" do
Snipp::Markup::Html::Spec::META.each do |key, value|
it "should have a `#{key}` tag" do
expect(page).to have_selector("meta[name=\"#{key}\"][content=\"#{value}\"]", count: 1)
end
end
Snipp::Markup::Html::Spec::OG.each do |key, value|
it "should have a `og:#{key}` tag" do
expect(page).to have_selector("meta[property=\"og:#{key}\"][content=\"#{value}\"]", count: 1)
end
end

end

end

0 comments on commit dce8b2a

Please sign in to comment.