djanowski-tti 0.2.2 → 0.4.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.
Files changed (4) hide show
  1. data/lib/configurable.rb +9 -0
  2. data/lib/tti.rb +11 -4
  3. data/rails/init.rb +1 -0
  4. metadata +1 -1
data/lib/configurable.rb CHANGED
@@ -6,6 +6,7 @@ module Configurable
6
6
  def self.configure
7
7
  self.configuration ||= Configuration.new(self)
8
8
  yield(configuration)
9
+ configuration
9
10
  end
10
11
  EOS
11
12
  end
@@ -26,6 +27,14 @@ module Configurable
26
27
  @config[key]
27
28
  end
28
29
  end
30
+
31
+ def default!
32
+ @default_config = @config.dup
33
+ end
34
+
35
+ def reset!
36
+ @config = @default_config ? @default_config.dup : {}
37
+ end
29
38
  end
30
39
 
31
40
  def config
data/lib/tti.rb CHANGED
@@ -56,7 +56,7 @@ class Tti
56
56
  end
57
57
 
58
58
  def url
59
- CGI.escape [config.url_prefix || config.path_prefix, filename].join('/')
59
+ [config.url_prefix || config.path_prefix, filename].join('/')
60
60
  end
61
61
 
62
62
  def width_or_computed
@@ -89,17 +89,24 @@ class Tti
89
89
 
90
90
  def to_html
91
91
  save
92
- %{<img src="#{url}" alt="#{text}" />}
92
+ %{<img src="#{h url}" alt="#{h text}" />}
93
93
  end
94
94
 
95
95
  def font_file
96
- file = Dir["#{font}.*"].first || Dir["fonts/#{font}.*"].first
96
+ file = Array(config.fonts_dir).detect do |dir|
97
+ Dir[File.join(dir, "#{font}.*")].first
98
+ end
97
99
 
98
100
  file ? File.join(Dir.pwd, file) : font
99
101
  end
100
102
 
103
+ def h(*args)
104
+ CGI.escapeHTML(*args)
105
+ end
106
+
101
107
  configure do |config|
102
108
  config.path_prefix = 'tmp'
103
109
  config.font_size = 24
104
- end
110
+ config.fonts_dir = ['.', 'fonts']
111
+ end.default!
105
112
  end
data/rails/init.rb CHANGED
@@ -5,4 +5,5 @@ ActionView::Base.send(:include, Tti::Helper)
5
5
  Tti.configure do |config|
6
6
  config.path_prefix = 'public/images/tti'
7
7
  config.url_prefix = '/images/tti'
8
+ config.fonts_dir = ['', 'fonts'].map {|d| File.join(RAILS_ROOT, d) } if Object.const_defined?(:RAILS_ROOT)
8
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djanowski-tti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Janowski