diff --git a/app/models/asset_tags.rb b/app/models/asset_tags.rb index a84e000..2fd7582 100644 --- a/app/models/asset_tags.rb +++ b/app/models/asset_tags.rb @@ -114,10 +114,9 @@ class TagError < StandardError; end desc %{ Renders an image tag for the asset. - Using the optional @size@ attribute, different sizes can be display. + Using the optional @size@ attribute, different sizes can be displayed. “thumbnail” and “icon” sizes are built in, but custom ones can be set - using by changing assets.addition_thumbnails in the Radiant::Config - settings. + by changing assets.addition_thumbnails in the Radiant::Config settings. *Usage:*
@@ -129,10 +128,14 @@ class TagError < StandardError; end geometry = options['geometry'] ? options.delete('geometry') : nil #This is very experimental and will generate new sizes on the fly asset.generate_style(size, { :size => geometry }) if geometry - - alt = " alt='#{asset.title}'" unless tag.attr['alt'] rescue nil + + width = (options.delete('width') || asset.width(size)).to_i + height = (options.delete('height') || asset.height(size)).to_i + dimensions = %Q{ width="#{width}" height="#{height}"} if width > 0 && height > 0 + alt = %Q{ alt="#{h asset.title}"} unless tag.attr['alt'] rescue nil attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip attributes << alt unless alt.nil? + attributes << dimensions unless dimensions.nil? url = asset.thumbnail(size) %{} rescue nil end diff --git a/app/views/admin/assets/_assets_container.html.haml b/app/views/admin/assets/_assets_container.html.haml index b42e98b..7ddf721 100644 --- a/app/views/admin/assets/_assets_container.html.haml +++ b/app/views/admin/assets/_assets_container.html.haml @@ -60,13 +60,13 @@ - asset_panes.search do #search-assets.pane - - form_tag do + - form_remote_tag :url => admin_assets_path, :method => :get, :update => 'search-results' do %p %label.note{ :for => 'search' } = t("paperclipped.search_assets") - %input{ :type => "hidden", :name => "search", :value => @page.id } + %input{ :type => "hidden", :name => "asset_page", :value => @page.id } %input{ :type => "search", :id => "search", :name => "search" } = submit_tag t("paperclipped.search") #search-results .clear - = observe_field 'search', :frequency => 1, :update => 'search-results', :url => admin_assets_path(:asset_page => @page), :method => 'get', :with => "'search=' + escape(value)" \ No newline at end of file + = observe_field 'search', :frequency => 1, :update => 'search-results', :url => admin_assets_path(:asset_page => @page), :method => 'get', :with => "'search=' + escape(value)" diff --git a/lib/tasks/assets_extension_tasks.rake b/lib/tasks/assets_extension_tasks.rake index 0903c8c..bf6ee11 100644 --- a/lib/tasks/assets_extension_tasks.rake +++ b/lib/tasks/assets_extension_tasks.rake @@ -33,21 +33,22 @@ namespace :radiant do # cp file, local_tasks_path, :verbose => false # end # end + end - desc "Syncs all available translations for this ext to the English ext master" - task :sync => :environment do - # The main translation root, basically where English is kept - language_root = PaperclippedExtension.get_translation_keys(language_root) + desc "Syncs all available translations for this ext to the English ext master" + task :sync => :environment do + # The main translation root, basically where English is kept + language_root = PaperclippedExtension.get_translation_keys(language_root) + words = TranslationSupport.get_translation_keys(language_root) - Dir["#{language_root}/*.yml"].each do |filename| - next if filename.match('_available_tags') - basename = File.basename(filename, '.yml') - puts "Syncing #{basename}" - (comments, other) = TranslationSupport.read_file(filename, basename) - words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist - other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml - TranslationSupport.write_file(filename, basename, comments, other) - end + Dir["#{language_root}/*.yml"].each do |filename| + next if filename.match('_available_tags') + basename = File.basename(filename, '.yml') + puts "Syncing #{basename}" + (comments, other) = TranslationSupport.read_file(filename, basename) + words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist + other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml + TranslationSupport.write_file(filename, basename, comments, other) end end diff --git a/spec/models/asset_tags_spec.rb b/spec/models/asset_tags_spec.rb new file mode 100644 index 0000000..47a1162 --- /dev/null +++ b/spec/models/asset_tags_spec.rb @@ -0,0 +1,69 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe 'Asset Tags' do + dataset :pages + + describe '' do + before(:each) do + @image = Asset.create({ + :asset_file_name => 'foo.jpg', + :asset_content_type => 'image/jpeg', + :asset_file_size => '24680' + }) + Asset.stub!(:find).and_return(@image) + end + + it 'should render an img tag by ID with a default alt text' do + tag = %{} + expected = %r{\A\z} + + pages(:home).should render(tag).matching(expected) + end + + it 'should render an img tag by title with a default alt text' do + tag = %{} + expected = %r{\A\z} + + pages(:home).should render(tag).matching(expected) + end + + it 'should use the given title as the alt text' do + @image.stub!(:title).and_return('My Title') + tag = %{} + expected = %r{\A\z} + + pages(:home).should render(tag).matching(expected) + end + + it 'should escape the title in the alt text' do + @image.stub!(:title).and_return(%{Harry "Snapper" Organs & Stig O'Tracey}) + tag = %{} + expected = %r{\A\z} + + pages(:home).should render(tag).matching(expected) + end + + it 'should use the given alt text' do + tag = %{} + expected = %r{\A\z} + + pages(:home).should render(tag).matching(expected) + end + + it 'should include the image dimensions' do + @image.stub!(:dimensions).and_return([200,100]) + tag = %{} + expected = %r{\A\z} + + pages(:home).should render(tag).matching(expected) + end + + it 'should override the image dimensions with the given dimensions' do + @image.stub!(:dimensions).and_return([200,100]) + tag = %{} + expected = %r{\A\z} + + pages(:home).should render(tag).matching(expected) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c2a2106..dadfaf8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,10 +3,9 @@ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/boot" require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment" end +require "#{RADIANT_ROOT}/spec/spec_helper" -require 'spec/rails' - -# require File.expand_path(File.dirname(__FILE__) + "/blueprints") +# Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets") Spec::Runner.configure do |config| config.use_transactional_fixtures = true @@ -24,4 +23,4 @@ # # If you declare global fixtures, be aware that they will be declared # for all of your examples, even those that don't use them. -end \ No newline at end of file +end