country_flags 0.0.1 → 0.1.0

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: 1fe0862a7d706a2d9ef13215b8ba267e4cd726ec
4
- data.tar.gz: 07d69d293d71d7ac38c8862b447054e93e691206
3
+ metadata.gz: 7714be3c9539e45cf731da6cd61a84a53f2575eb
4
+ data.tar.gz: 0d32fc0659e52d2bfed2bc7d6eb0934135a1b4b4
5
5
  SHA512:
6
- metadata.gz: a43568f954ae21be90f300d03272174cf02f114679ae65662a9b079f40fc2b52465bc56c5d06b638579824bdc220004197887b02f1f131f2056067bc92516695
7
- data.tar.gz: 903f1af1406414037e96d25d7da904160d6dfce873ebaa53d219a4a6e7e41c8aba9a61935bc3b4dff39022994af0c141e8d0555b9bd08d8485bb65a1186922db
6
+ metadata.gz: 0fe3b03a7ff630dfaf148719da059265c3f2919cb840088d19df658c1c58600a56b3f5315c017be1323675965bee9471c0d57b0eaf1a82ecc54c056002d798ec
7
+ data.tar.gz: 08cdc532972fec3c9c4eaa848b7140bf4b0eb68951c0eb13e0663947c9ec04f6189e22ba526f13d3c386fd2556601ccc4cf592a2b530f4e4affa850c0681227d
data/README.md CHANGED
@@ -19,6 +19,14 @@ bundle install
19
19
 
20
20
  In views:
21
21
  ```ruby
22
+
23
+ # using helper
24
+ country_flag 'bg'
25
+ country_flag 'bg', format: 'gif'
26
+
27
+ image_tag country_flag_path 'bg'
28
+ image_tag country_flag_path 'bg', :gif
29
+
22
30
  # gif version
23
31
  image_tag 'country_flags/gif/bg.gif'
24
32
 
@@ -18,4 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.license = 'MIT'
19
19
 
20
20
  s.add_development_dependency('rspec', '>= 2.11')
21
+ s.add_dependency "railties", ">= 3.1"
22
+ s.add_dependency "actionview", ">= 3.1"
21
23
  end
@@ -1,4 +1,6 @@
1
+ require 'rails'
2
+
1
3
  module CountryFlags
2
- class Engine < Rails::Engine
4
+ class Engine < ::Rails::Engine
3
5
  end
4
6
  end
@@ -0,0 +1,28 @@
1
+ require 'action_view'
2
+
3
+ module CountryFlags
4
+ module Helper
5
+
6
+ include ActionView::Helpers::AssetUrlHelper
7
+ include ActionView::Helpers::AssetTagHelper
8
+
9
+ # returns path to flag image
10
+ # use ISO-3166 Alpha 2 country codes
11
+ # format can be :png or :gif
12
+ def country_flag_path( country_code, format = :png )
13
+ unless [:png, :gif].include?(format)
14
+ raise(ArgumentError, 'format must be :png or :gif')
15
+ end
16
+
17
+ path = "country_flags/#{format}/#{country_code.downcase}.#{format}"
18
+ image_path path
19
+ end
20
+
21
+
22
+ def country_flag( country_code, options = {} )
23
+ options = {format: :png}.merge(options)
24
+
25
+ image_tag country_flag_path(country_code, options[:format])
26
+ end
27
+ end
28
+ end
@@ -1,6 +1,9 @@
1
+ require 'rails'
2
+
1
3
  module CountryFlags
2
- module Rails
3
- class Railtie < ::Rails::Railtie
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'country_flags.view_helpers' do
6
+ ActionView::Base.send :include, Helper
4
7
  end
5
8
  end
6
9
  end
@@ -1,3 +1,3 @@
1
1
  module CountryFlags
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/country_flags.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'country_flags/version'
2
2
  require 'country_flags/engine'
3
3
  require 'country_flags/railtie'
4
+ require 'country_flags/helper' if defined? Rails
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe CountryFlags::Helper do
4
+
5
+ include CountryFlags::Helper
6
+
7
+ describe '#country_flag_path' do
8
+ it 'throws exception if wrong format given' do
9
+ expect { country_flag_path('bg', :tiff) }.to raise_error(ArgumentError)
10
+ end
11
+
12
+ it 'does not throw exception if format given in string' do
13
+ expect { country_flag_path('bg', 'gif') }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it 'returns image path' do
17
+ expect(country_flag_path('bg', :png)).to be_a(String)
18
+ end
19
+ end
20
+
21
+ describe '#country_flag' do
22
+ it 'returns image tag' do
23
+ expect(country_flag('bg')).to be_a(String)
24
+ end
25
+
26
+ it 'throws exception if wrong format given' do
27
+ expect { country_flag('bg', format: :tiff) }.to raise_error(ArgumentError)
28
+ end
29
+ end
30
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'rspec'
3
- require 'active_model'
4
3
 
5
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: country_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lazarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionview
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
27
55
  description: 'Gemified collection of country flags. See homepage for details: https://github.com/alexander-lazarov/isaf_id_validator'
28
56
  email: alexander.lazaroff@gmail.com
29
57
  executables: []
@@ -533,9 +561,11 @@ files:
533
561
  - country_flags.gemspec
534
562
  - lib/country_flags.rb
535
563
  - lib/country_flags/engine.rb
564
+ - lib/country_flags/helper.rb
536
565
  - lib/country_flags/railtie.rb
537
566
  - lib/country_flags/version.rb
538
567
  - project.sublime-project
568
+ - spec/country_flags/helper_spec.rb
539
569
  - spec/spec_helper.rb
540
570
  homepage: https://github.com/alexander-lazarov/country_flags
541
571
  licenses: