titlefy 0.3.0 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e2d959eb9c1ad291b7512726b2ac4278b48c362f
4
- data.tar.gz: a5d8503f6e1821ea8e2250852c59cbea2b7f1169
2
+ SHA256:
3
+ metadata.gz: 03204f228f1fc76ef22c2cd0ecd6c3ccb2da971839cfe241d671193de8edb870
4
+ data.tar.gz: 9a33f1b079cfe5afcbdba61bd0cefd737f2da72a4bda5751c63eb192b81ad134
5
5
  SHA512:
6
- metadata.gz: 18b86637f93e3f96894ce51f62a7e720aa65295e70832b5ea46f29a85c117d6dceaa59e7e19717e06b0fb9c52a01fca16edd3e5b7daaacb4b88b45514690e8e3
7
- data.tar.gz: 1ad2278a76780a5ef2cdd2cd7b91218047b5a1408cb3ca327920e0236d198dc7388b8e898354ad13bc414a882cf0a8c8bedcc4b1dced05d7c22f9ace680da17d
6
+ metadata.gz: 97a31e76f4e493ba7f965111c61107ce23767eaeae1a3002abd0f63b5c084b4357253899a6bc0f5cb0ee8eb574264dcebaadd4dc85e70de053094240a07ac816
7
+ data.tar.gz: 0c4188f53c8bd2f0a7c88a90b660ba2f3807b1fbda26769e7cf4a653e2082c4be5093b571ea33646009970854eff7ae2036f723e5b45867557443b419b58cc78
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Titlefy
2
2
 
3
- Awesome title tag magic with I18n support, passing variables and default title.
4
- No more unnecessary lines in each controller method, no more setting title tags out of a view.
3
+ Awesome title tag magic with I18n support, passing variables and default title.
4
+ No more unnecessary lines in each controller method, no more setting title tags out of a view.
5
5
  Avoid messy code - be slim and dry - kepp just one central place to control all your title tags!
6
6
 
7
7
  ## Usage
@@ -11,7 +11,7 @@ Define your tiltetags within one structured file. Just simply do the following:
11
11
  gem "titlefy", git: 'git://github.com/krtschmr/titlefy.git'
12
12
  ```
13
13
 
14
- Using @page_title into your HTML
14
+ Using @page_title into your HTML
15
15
  ````
16
16
  <title><%=@page_title %></title>
17
17
  ````
@@ -32,7 +32,7 @@ Create an YML file and add the :title_tags scope. Define what you need
32
32
  routes:
33
33
  list_items_path: Index of Items
34
34
  order_path: Order at our Webshop
35
-
35
+
36
36
  #### TitleTag by Controller/Action
37
37
  en:
38
38
  title_tags:
@@ -45,12 +45,12 @@ For Admin::DashboardController
45
45
 
46
46
  en:
47
47
  title_tags:
48
- admin:
48
+ admin:
49
49
  dashboard_conroller:
50
50
  index: Overview
51
51
  stats: Detailed Stats
52
-
53
-
52
+
53
+
54
54
 
55
55
  #### Using variables in title tag
56
56
 
@@ -60,14 +60,14 @@ For Admin::DashboardController
60
60
  show: Details of user: {{@user.name}}
61
61
  videos:
62
62
  index: Videos of user: {{@user.name}}
63
- show: Video "{{@video.name}} from {{@user.name}} posted on {{@video.time}}"
63
+ show: Video {{@video.name}} from {{@user.name}} posted on {{@video.time}}
64
64
 
65
65
 
66
66
  It also supports any kind of resource-controller where the object is called "resource"
67
67
 
68
68
  en:
69
69
  title_tags:
70
- routes:
70
+ routes:
71
71
  dogs_path: "{{resource.funky_dog_name}} - my-petwebsite"
72
72
  cats_path: "{{resource.funky_cat_name}} - my-petwebsite"
73
73
 
@@ -75,8 +75,8 @@ It also supports any kind of resource-controller where the object is called "res
75
75
  If your title-tag starts with a placeholder its neccessary to **start with quotes** to keep valid YML.
76
76
 
77
77
 
78
-
79
- Lookup order is Namespace/Controller/Action, Controller/Action, RouteName, Default, RaillsAppName.
78
+
79
+ Lookup order is Namespace/Controller/Action, Controller/Action, RouteName, Default, RaillsAppName.
80
80
  Simply set the titletag from your controller like this
81
81
  ````
82
82
  def index
@@ -85,12 +85,33 @@ Simply set the titletag from your controller like this
85
85
  ````
86
86
 
87
87
 
88
+ You can add dynamic extra lookups:
89
+ ````
90
+ ApplicationController
91
+ before_action do
92
+ Titlefy.config.extra_lookup = current_currency
93
+ end
94
+ def current_currency
95
+ #...
96
+ end
97
+
98
+ # This will first lookup based on current_currency
99
+ # "Titlefy Lookup: title_tags.object.home.index.eur"
100
+ # "Titlefy Lookup: title_tags.object.home.index"
101
+ # "Titlefy Lookup: title_tags.home.index.eur"
102
+ # "Titlefy Lookup: title_tags.home.index"
103
+
104
+ ````
105
+
106
+
107
+
108
+
88
109
  # TODO
89
110
  - Multi Namespacing Support
90
111
 
91
112
  ### Changelog
92
113
 
93
- 0.3.0
114
+ 0.3.0
94
115
  - supports passing of variables
95
116
  - changed lookup path of routes
96
117
  - changed @title to @page_title
@@ -0,0 +1,7 @@
1
+ require 'singleton'
2
+ module Titlefy
3
+ class Config
4
+ include Singleton
5
+ attr_accessor :extra_lookup
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Titlefy
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/titlefy.rb CHANGED
@@ -1,33 +1,62 @@
1
1
  require "titlefy/version"
2
+ require 'titlefy/config'
2
3
  require 'active_support/concern'
3
4
 
4
5
  module Titlefy
5
6
  extend ActiveSupport::Concern
6
7
 
7
- def titlefy
8
+ def titlefy(*args)
8
9
  send :include, InstanceMethods
9
10
  end
10
11
 
12
+ def self.config
13
+ @@config ||= Titlefy::Config.instance
14
+ @@config.extra_lookup ||= nil
15
+ @@config
16
+ end
17
+
18
+
11
19
  included do
12
20
 
21
+ def titlefy_lookup(val)
22
+ @titlefy_prefix ||= val
23
+ end
24
+
13
25
  def render(*args)
14
26
  set_title_tag unless @page_title
15
27
  super
16
28
  end
17
29
 
18
30
  def set_title_tag
19
- title = I18n.t "title_tags.#{namespace}.#{controller_name}.#{action_name}", default: ""
20
- title = I18n.t "title_tags.#{controller_name}.#{action_name}", default: "" if title.empty?
21
- title = I18n.t route_name, scope: [:title_tags, :routes], default: "" if title.empty? and route_name != ""
22
- title = default_title if title == ""
23
-
31
+ lookup = "title_tags"
32
+ lookup << ".#{@titlefy_prefix}" if @titlefy_prefix
33
+
34
+ paths = [
35
+ "#{lookup}.#{namespace}.#{controller_name}.#{action_name}.#{Titlefy.config.extra_lookup}",
36
+ "#{lookup}.#{namespace}.#{controller_name}.#{action_name}",
37
+ "#{lookup}.#{controller_name}.#{action_name}.#{Titlefy.config.extra_lookup}",
38
+ "#{lookup}.#{controller_name}.#{action_name}"
39
+ ]
40
+ title = nil
41
+ paths.each do |path|
42
+ p "Titlefy Lookup: #{path}" if Rails.env.development?
43
+ title = I18n.t(path ,default: "")
44
+ break if title.present?
45
+ end
46
+
47
+ if title.empty? and route_name != ""
48
+ title = I18n.t route_name, scope: [:title_tags, :routes], default: ""
49
+ elsif title == ""
50
+ title = default_title
51
+ end
52
+
24
53
  title.scan(/\{\{.*?\}\}/).each do |replace|
25
54
  #{{@game.name}} => @game.name
26
- variable = replace.gsub(/\{|\}/, "")
55
+ variable = replace.gsub(/\{|\}/, "")
27
56
 
28
57
  # catch resource_controller or similar
29
58
  # variable named resource is an AR object
30
- # rename to @tempresource so we can handle it
59
+ # rename to @tempresource so we can handle it
31
60
  if variable.starts_with? "resource"
32
61
  @tempresource = resource
33
62
  variable.gsub!("resource", "@tempresource")
@@ -35,7 +64,7 @@ module Titlefy
35
64
 
36
65
  # make "@variable.name" or "@variable" accessable without eval (!)
37
66
  # and replace the {{placeholder}} with @variables value
38
- if variable.starts_with?("@")
67
+ if variable.starts_with?("@")
39
68
  content = variable.split('.').inject(nil){|clazz, method| clazz.nil? ? instance_variable_get(method) : clazz.send(method)}
40
69
  title.gsub! replace, content
41
70
  end
data/titlefy.gemspec CHANGED
@@ -7,20 +7,12 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "titlefy"
8
8
  spec.version = Titlefy::VERSION
9
9
  spec.authors = ["Tim Kretschmer"]
10
- spec.email = ["github@krtschmr.de"]
10
+ spec.email = ["tim@krtschmr.de"]
11
11
 
12
12
  spec.summary = %q{Extract your titletags from I18n backend.}
13
13
  spec.description = %q{Set your title-tag content based on I18n locales. Just add title_tag key to your YML File and the magic begins. Lookup for Namespace|Controller|ActionName or Controller|Actionname or RouteName or Default. Also supports passing variables into the title tag}
14
14
  spec.homepage = ""
15
15
 
16
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
- # delete this section to allow pushing this gem to any host.
18
- if spec.respond_to?(:metadata)
19
- #spec.metadata['allowed_push_host'] = "http://mygemserver.com'"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- end
23
-
24
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
17
  spec.bindir = "exe"
26
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: titlefy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Kretschmer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -43,7 +43,7 @@ description: Set your title-tag content based on I18n locales. Just add title_ta
43
43
  or Controller|Actionname or RouteName or Default. Also supports passing variables
44
44
  into the title tag
45
45
  email:
46
- - github@krtschmr.de
46
+ - tim@krtschmr.de
47
47
  executables: []
48
48
  extensions: []
49
49
  extra_rdoc_files: []
@@ -55,6 +55,7 @@ files:
55
55
  - bin/console
56
56
  - bin/setup
57
57
  - lib/titlefy.rb
58
+ - lib/titlefy/config.rb
58
59
  - lib/titlefy/version.rb
59
60
  - titlefy.gemspec
60
61
  homepage: ''
@@ -75,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
78
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.4.8
79
+ rubygems_version: 3.0.3
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: Extract your titletags from I18n backend.