silverdot 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab2ceff1f7a73f70f25632b103d62f4015431a8a
4
- data.tar.gz: fdc413ef230e4c0d629448cd7966ca212e86fa0a
3
+ metadata.gz: b539e3b2820fdd3abf5cfd608410caa3f238a14a
4
+ data.tar.gz: 5ba1ebaf038990dad544bc99f70044f100ddd30f
5
5
  SHA512:
6
- metadata.gz: 1169aba1ace236e82a3f5a1494d533cee001a9b0196427504adfe8863c460d0397bb494ced3e721edc094304f03cce254af1d98822f37f147b56cb4cbb4e712d
7
- data.tar.gz: 35320ceba9ce3b41bd4436d117b37a76ff078083f414916b7e0ad94915f2db83f19f84dede6be681cd68838875c2dc2b36b6cc51576b8e648c0e04fe510d5f26
6
+ metadata.gz: f2ccb2c0933144d1f95ade458a810fd6ec0b813058f390fa91150cbe74d4db218252c5b5cab8e5a7d1537ee1f850c54cc3ed57c19ca79c60097d11798e1ce4a5
7
+ data.tar.gz: e6ac081f493dbde550cf32d61e9af5d9d12ef3b7b9cdec983341ccc63ff8da0c3314f457b83b2587a50c75e8284f9c02ededa5053f318204477b3a2f56e90cce
@@ -1,7 +1,7 @@
1
1
  require 'action_view/helpers/capture_helper'
2
2
 
3
3
  module Silverdot
4
- class Alternative
4
+ class Alternative < String
5
5
  include ::ActionView::Helpers::CaptureHelper
6
6
 
7
7
  attr_accessor :output_buffer
@@ -24,16 +24,18 @@ module Silverdot
24
24
  end
25
25
 
26
26
  def []=(index, value)
27
- pp "[#{index}]=#{value}"
28
27
  end
29
28
 
30
29
  def <<(value)
31
- pp value
32
30
  end
33
31
 
34
32
  def sort!
35
33
  end
36
34
 
35
+ def parent
36
+ @parent
37
+ end
38
+
37
39
  def parent=(value)
38
40
  @parent = value
39
41
  end
@@ -57,5 +59,13 @@ module Silverdot
57
59
  def to_s
58
60
  "{{ #{path} }}"
59
61
  end
62
+
63
+ def to_str
64
+ to_s
65
+ end
66
+
67
+ def blank?
68
+ path.blank?
69
+ end
60
70
  end
61
71
  end
@@ -0,0 +1,27 @@
1
+ module Silverdot
2
+ module ImageHelper
3
+ def self.included(base)
4
+ base.alias_method_chain :image_path, :alternative
5
+ base.alias_method_chain :image_alt, :alternative
6
+ end
7
+
8
+ def image_path_with_alternative(source)
9
+ case source
10
+ when Alternative
11
+ source.src
12
+ else
13
+ image_path_without_alternative(source)
14
+ end
15
+ end
16
+ alias :path_to_image :image_path_with_alternative
17
+
18
+ def image_alt_with_alternative(src)
19
+ case src
20
+ when Alternative
21
+ src.parent.alt
22
+ else
23
+ image_alt_without_alternative(src)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,10 +1,6 @@
1
1
  module Silverdot
2
2
  class Hooks
3
3
  def self.init
4
- ActiveSupport.on_load(:action_view) do
5
- ::ActionView::Base.send :include, Silverdot::ActionViewExtension
6
- ::ActionView::Base.send :include, Silverdot::LocalizeHelper
7
- end
8
4
  end
9
5
  end
10
6
  end
@@ -1,7 +1,11 @@
1
1
  module Silverdot
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer 'silverdot' do |_app|
4
- Silverdot::Hooks.init
4
+ ActiveSupport.on_load(:action_view) do
5
+ ::ActionView::Base.send :include, Silverdot::ActionViewExtension
6
+ ::ActionView::Base.send :include, Silverdot::LocalizeHelper
7
+ ::ActionView::Base.send :include, Silverdot::ImageHelper
8
+ end
5
9
  end
6
10
  end
7
11
  end
data/lib/silverdot.rb CHANGED
@@ -13,6 +13,7 @@ module Silverdot
13
13
  autoload :ActionViewExtension, 'silverdot/helpers/action_view_extension'
14
14
  autoload :UrlHelper, 'silverdot/helpers/url_helper'
15
15
  autoload :LocalizeHelper, 'silverdot/helpers/localize_helper'
16
+ autoload :ImageHelper, 'silverdot/helpers/image_helper'
16
17
 
17
18
  class << self
18
19
  def ejs_options
data/silverdot.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "silverdot"
3
- s.version = "0.1.2"
3
+ s.version = "0.1.3"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = ""
6
6
  s.description = "Build JST from Rails view"
@@ -0,0 +1 @@
1
+ <%= image_tag account.avatar %>
@@ -22,6 +22,13 @@ describe Silverdot::ActionViewExtension do
22
22
  it { should eq("<a href=\"{{ link.url }}\">{{ link.name }}</a>\n") }
23
23
  end
24
24
 
25
+ describe 'spec/face_app/views/_image.html.erb' do
26
+ subject { helper.emboss('image', with: :account) }
27
+ it { should =~ /\A<img[\s\S]*>\n?\z/ }
28
+ it { should =~ /src="{{ account.avatar.src }}"/ }
29
+ it { should =~ /alt="{{ account.avatar.alt }}"/ }
30
+ end
31
+
25
32
  describe 'spec/fake_app/views/locale.html.erb' do
26
33
  subject { helper.emboss('locale', with: :locale) }
27
34
  it { should eq("{{ locale.created_at }}\n") }
data/spec/render_spec.rb CHANGED
@@ -15,8 +15,8 @@ describe "Render Spec" do
15
15
 
16
16
  it "nests deep associations" do
17
17
  root = Silverdot::Alternative.new('root')
18
- root.first.second.to_s.should eq('{{ root.first.second }}')
19
- root.first.second.third.to_s.should eq('{{ root.first.second.third }}')
18
+ root.node.leaf.to_s.should eq('{{ root.node.leaf }}')
19
+ root.node.node.leaf.to_s.should eq('{{ root.node.node.leaf }}')
20
20
  end
21
21
 
22
22
  it "#each" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silverdot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - niaeashes
@@ -153,6 +153,7 @@ files:
153
153
  - lib/silverdot/alternative.rb
154
154
  - lib/silverdot/engine.rb
155
155
  - lib/silverdot/helpers/action_view_extension.rb
156
+ - lib/silverdot/helpers/image_helper.rb
156
157
  - lib/silverdot/helpers/localize_helper.rb
157
158
  - lib/silverdot/helpers/url_helper.rb
158
159
  - lib/silverdot/hooks.rb
@@ -160,6 +161,7 @@ files:
160
161
  - lib/silverdot/renderer.rb
161
162
  - silverdot.gemspec
162
163
  - spec/fake_app/rails_app.rb
164
+ - spec/fake_app/views/_image.html.erb
163
165
  - spec/fake_app/views/_link.html.erb
164
166
  - spec/fake_app/views/_locale.html.erb
165
167
  - spec/fake_app/views/_object.html.erb
@@ -193,6 +195,7 @@ specification_version: 4
193
195
  summary: ''
194
196
  test_files:
195
197
  - spec/fake_app/rails_app.rb
198
+ - spec/fake_app/views/_image.html.erb
196
199
  - spec/fake_app/views/_link.html.erb
197
200
  - spec/fake_app/views/_locale.html.erb
198
201
  - spec/fake_app/views/_object.html.erb