cambelt 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .redcar/*
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ Cambelt - Image Placeholders
2
+ ============================
3
+
4
+ <img src="https://cambelt.herokuapp.com/852x120/Cambelt+Placeholders?color=234653,eeeeee&font=Questrial&font_size=30" />
5
+
6
+ Cambelt is a service that allows you to generate free image placeholders, simply and easily. If you would like to learn more about the service itself, have a look at http://cambelt.co for more information.
7
+
8
+
9
+ ## Quickstart
10
+
11
+ To install Cambelt on your machine you can type:
12
+
13
+ gem install cambelt
14
+
15
+ or use
16
+
17
+ gem 'cambelt'
18
+
19
+ in your Gemfile.
20
+
21
+ Cambelt detects if you are running Ruby on Rails, and if so adds a _placeholder_image_tag()_ method to ActionView, allowing you to do:
22
+
23
+ <%= placeholder_image_tag %>
24
+
25
+ in your views and get a nice placeholder back! For your convenience this is also aliased to a simple call of:
26
+
27
+ <%= placeholder %>
28
+
29
+ ## Configuring Cambelt
30
+
31
+ This gem currently only interfaces with the basic free Cambelt service, which gives a limited number of configuration options that you can set as defaults. When you make a call to _placeholder_image_tag()_, Cambelt checks for these defaults to create the image, but allows you to pass in a hash of values to override any of them.
32
+
33
+ To configure Cambelt in Rails, you can run the following generator to create a Cambelt initializer file:
34
+
35
+ $ rails g cambelt:install
36
+
37
+ Then you can edit this file to customise your default settings. If you are not using Rails, then the command to configure Cambelt is the same as in the initializer, and is presented below:
38
+
39
+ Cambelt.configure do |config|
40
+ width = 640
41
+ height = 360
42
+ font = "Questrial"
43
+ font_size = 48
44
+ text = "Sample Text"
45
+ bg_color = "#cccccc"
46
+ fg_color = "#333333"
47
+ end
48
+
49
+ These are the default settings that are provided, so if you are happy with those you don't actually need to call _Cambelt.configure()_ at all. Each of these methods is overridable on any given call to _placeholder_image_tag()_, and to do this you supply a hash as the first parameter:
50
+
51
+ placeholder_image_tag(:text => "I love Cambelt!")
52
+
53
+ Finally, you can supply a second hash to the method which contains html attributes that your want your image tag to have, so:
54
+
55
+ placeholder_image_tag({:text => "I love Cambelt!"}, {:class => "cambelt_is_classy"})
56
+
57
+ will give you the following:
58
+
59
+ <img src="http://cambelt.co/640x360/I+love+Cambelt!?font=Questrial&font_size=48&color=cccccc,333333" class="cambelt_is_classy" />
60
+
61
+ Simple, isn't it?
62
+
data/cambelt.gemspec CHANGED
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
23
+ # s.add_dependency "actionpack"
24
24
  end
@@ -0,0 +1,19 @@
1
+ module Cambelt
2
+ class Configuration
3
+ attr_accessor :width, :height, :font, :font_size, :text
4
+
5
+ def initialize
6
+ @width = 640
7
+ @height = 360
8
+ @font = "Questrial"
9
+ @font_size = 48
10
+ @text = "Sample Text"
11
+ @bg_color = "#cccccc"
12
+ @fg_color = "#333333"
13
+ end
14
+
15
+ def to_hash
16
+ self.instance_variables.inject({}) { |hash,var| hash[var[1..-1].to_sym] = self.instance_variable_get(var); hash }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Cambelt
2
+ module Helpers
3
+ module Placeholder
4
+ def placeholder_image_tag(cambelt_opts={}, image_opts={})
5
+ string = Cambelt.placeholder(cambelt_opts)
6
+ if defined? Rails
7
+ image_tag(string, image_opts).html_safe
8
+ else
9
+ image_tag(string, image_opts)
10
+ end
11
+ end
12
+ alias_method :placeholder, :placeholder_image_tag
13
+
14
+ private
15
+ def image_tag(link, options)
16
+ string = "<img src=\"#{link}\" "
17
+ options.each{ |key, val| string << "#{key}=\"#{val}\" " }
18
+ string << ' />'
19
+ string
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Cambelt
2
+ module Helpers
3
+ end
4
+ end
5
+ require 'cambelt/helpers/placeholder'
@@ -1,3 +1,3 @@
1
1
  module Cambelt
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/cambelt.rb CHANGED
@@ -1,5 +1,31 @@
1
1
  require "cambelt/version"
2
+ require "cambelt/configuration"
3
+ require "cambelt/helpers"
2
4
 
3
5
  module Cambelt
4
- # Your code goes here...
6
+ class << self
7
+ attr_accessor :configuration
8
+
9
+ def configure
10
+ self.configuration ||= Configuration.new
11
+ yield(configuration)
12
+ end
13
+
14
+ def placeholder(opts={})
15
+ args = opts_to_args(opts)
16
+ "//cambelt.co/#{args[:width]}x#{args[:height]}/#{args[:text].gsub(" ", "+")}?font=#{args[:font]}&font_size=#{args[:font_size]}"
17
+ end
18
+
19
+
20
+ private
21
+ def opts_to_args(opts)
22
+ self.configuration ||= Configuration.new
23
+ self.configuration.to_hash.merge(opts)
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ if defined? Rails
30
+ require 'rails-helper'
5
31
  end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module Cambelt
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+
7
+ desc 'Creates a Cambelt gem initializer at config/initializers/cambelt.rb'
8
+
9
+ def self.source_root
10
+ @_cambelt_source_root ||= File.expand_path("../templates", __FILE__)
11
+ end
12
+
13
+ def create_initializer_file
14
+ template 'initializer.rb', File.join('config', 'initializers', 'cambelt.rb')
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ #
2
+ # The initializer file for Cambelt - the Image Placeholder service.
3
+ # Currently, all of the settings below are the defaults, to change
4
+ # a default, then please uncomment the top and bottom lines, and then
5
+ # uncomment and change any of the other lines you wish.
6
+ #
7
+
8
+ #Cambelt.configure do |config|
9
+ # width = 640
10
+ # height = 360
11
+ # font = "Questrial"
12
+ # font_size = 48
13
+ # text = "Sample Text"
14
+ # bg_color = "#cccccc"
15
+ # fg_color = "#333333"
16
+ #end
@@ -0,0 +1,9 @@
1
+ require 'action_view/helpers'
2
+ ActionView::Helpers::AssetTagHelper.module_eval do
3
+ include Cambelt::Helpers::Placeholder
4
+ #def placeholder_image_tag(cambelt_opts={}, image_opts={})
5
+ # string = Cambelt.placeholder(cambelt_opts)
6
+ # image_tag(string, image_opts)
7
+ #end
8
+ #alias_method :placeholder, :placeholder_image_tag
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cambelt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,10 +21,17 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
23
  - Gemfile
24
+ - README.md
24
25
  - Rakefile
25
26
  - cambelt.gemspec
26
27
  - lib/cambelt.rb
28
+ - lib/cambelt/configuration.rb
29
+ - lib/cambelt/helpers.rb
30
+ - lib/cambelt/helpers/placeholder.rb
27
31
  - lib/cambelt/version.rb
32
+ - lib/rails-helper.rb
33
+ - lib/rails/generators/cambelt/install/install_generator.rb
34
+ - lib/rails/generators/cambelt/install/templates/initializer.rb
28
35
  homepage: http://cambelt.co
29
36
  licenses: []
30
37
  post_install_message: