initialjs-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 238b306c59ac0a4dddd0e0e302bfcb884c25fce4
4
+ data.tar.gz: 09edb2d474028817ba72089d9c2324a218432c8d
5
+ SHA512:
6
+ metadata.gz: 509fbca21bc9c178345e0f7e1e599ee012a0c1f54094b90fa9eb3938a099ed138efa146e1c9716f870bf21da6f63612f9cd2516e72d7851778593e3106f52df2
7
+ data.tar.gz: 343d2bda9a88e4bfd0b3e3b228cdc15673023b8154980f561cf6df895b5fb2316b6e26ec8da4ae24d5414da9a7234e069e20b2450f8f0f5fa907374f454dfe16
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in initialjs-rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 David Gil
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # initialjs-rails
2
+
3
+ [initial.js](https://github.com/mozilla/metrics-graphics) is a simple jQuery plugin to make Gmail-like text avatars for profile pictures using SVG.
4
+
5
+ **initialjs-rails** is a wrapper to easily include it in your Rails projects using the assets pipeline.
6
+
7
+ ## Installation
8
+
9
+ Add this gem to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'initialjs-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install initialjs-rails
22
+
23
+ After that add the following directive to your Javascript manifest file (application.js), after the `//= require jquery`:
24
+
25
+ //= require initial
26
+
27
+ Add this to your application.js after page is ready:
28
+
29
+ $('.initialjs-avatar').initial();
30
+
31
+ And finally, in your views, tag your *<img/>* class with `initialjs-avatar` class. You can use *data-attributes* as described in [initial.js](https://github.com/mozilla/metrics-graphics).
32
+
33
+ Enjoy.
34
+
35
+ ## ActionView Graph Helper
36
+
37
+ For extra simplicity, you can use this helper in your view to generate your avatar image from your model. In the following examples we'll use User, but any model responding to `:name` will do. You can learn the options available and their defaults directly from the examples:
38
+
39
+ avatar_image(user) # => 100x100 image with round corners
40
+ avatar_image(user, size: 32) # => 32x32 image with round corners
41
+ avatar_image(user, class: 'extra_class') # => add an extra CSS class to <img/> tag
42
+ avatar_image(user, round_corners: false) # => disable round corners
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Versioning
51
+
52
+ initialjs-rails 0.1.0 == initial.js 0.1.0
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/[my-github-username]/initialjs-rails/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Follow the code of conduct (CODE_OF_CONDUCT.md)
59
+ 4. Commit your changes (`git commit -am 'Added some feature'`)
60
+ 5. Push to the branch (`git push origin my-new-feature`)
61
+ 6. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "initialjs/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'initialjs-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "initialjs-rails"
8
+ spec.version = InitialjsRails::VERSION
9
+ spec.authors = ["David Gil"]
10
+ spec.email = ["dgilperez@gmail.com"]
11
+
12
+ spec.summary = 'initial.js for Rails'
13
+ spec.description = 'initialjs-rails is an assets gem for initial.js'
14
+ spec.homepage = "https://github.com/dgilperez/initialjs-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'railties', [">= 3.1", "< 5.0"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,3 @@
1
+ require 'initialjs-rails/version'
2
+ require 'initialjs-rails/view_helpers'
3
+ require 'initialjs-rails/engine' if defined?(::Rails)
@@ -0,0 +1,7 @@
1
+ module InitialjsRails
2
+ class Engine < ::Rails::Engine
3
+ initializer 'initialjs-rails.helper' do
4
+ ActionView::Base.send :include, ViewHelpers
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module InitialjsRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'json'
2
+
3
+ module InitialjsRails
4
+ module ViewHelpers
5
+ def avatar_image(avatarable, options = {})
6
+ size = options.fetch(:size) { 100 }
7
+ klass = options.fetch(:class) { '' }
8
+ round_corners = options.fetch(:round_corners) { true }
9
+
10
+ data_attributes = { name: avatarable.name,
11
+ height: size,
12
+ width: size,
13
+ "font-size" => (size * 0.6) }
14
+
15
+ data_attributes.merge!(radius: (size * 0.13).round) if round_corners
16
+
17
+ content_tag :img, nil, class: "initialjs-avatar #{klass}", data: data_attributes
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,64 @@
1
+ (function ($) {
2
+ $.fn.initial = function (options) {
3
+
4
+ // Defining Colors
5
+ var colors = ["#1abc9c", "#16a085", "#f1c40f", "#f39c12", "#2ecc71", "#27ae60", "#e67e22", "#d35400", "#3498db", "#2980b9", "#e74c3c", "#c0392b", "#9b59b6", "#8e44ad", "#bdc3c7", "#34495e", "#2c3e50", "#95a5a6", "#7f8c8d", "#ec87bf", "#d870ad", "#f69785", "#9ba37e", "#b49255", "#b49255", "#a94136"];
6
+
7
+ return this.each(function () {
8
+
9
+ var e = $(this);
10
+ var settings = $.extend({
11
+ // Default settings
12
+ name: 'Name',
13
+ charCount: 1,
14
+ textColor: '#ffffff',
15
+ height: 100,
16
+ width: 100,
17
+ fontSize: 60,
18
+ fontWeight: 400,
19
+ fontFamily: 'HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica, Arial,Lucida Grande, sans-serif',
20
+ radius: 0
21
+ }, options);
22
+
23
+ // overriding from data attributes
24
+ settings = $.extend(settings, e.data());
25
+
26
+ // making the text object
27
+ var c = settings.name.substr(0, settings.charCount).toUpperCase();
28
+ var cobj = $('<text text-anchor="middle"></text>').attr({
29
+ 'y': '50%',
30
+ 'x': '50%',
31
+ 'dy' : '0.35em',
32
+ 'pointer-events':'auto',
33
+ 'fill': settings.textColor,
34
+ 'font-family': settings.fontFamily
35
+ }).html(c).css({
36
+ 'font-weight': settings.fontWeight,
37
+ 'font-size': settings.fontSize+'px',
38
+ });
39
+
40
+ var colorIndex = Math.floor((c.charCodeAt(0) - 65) % colors.length);
41
+
42
+ var svg = $('<svg></svg>').attr({
43
+ 'xmlns': 'http://www.w3.org/2000/svg',
44
+ 'pointer-events':'none',
45
+ 'width': settings.width,
46
+ 'height': settings.height
47
+ }).css({
48
+ 'background-color': colors[colorIndex],
49
+ 'width': settings.width+'px',
50
+ 'height': settings.height+'px',
51
+ 'border-radius': settings.radius+'px',
52
+ '-moz-border-radius': settings.radius+'px'
53
+ });
54
+
55
+ svg.append(cobj);
56
+ // svg.append(group);
57
+ var svgHtml = window.btoa(unescape(encodeURIComponent($('<div>').append(svg.clone()).html())));
58
+
59
+ e.attr("src", 'data:image/svg+xml;base64,' + svgHtml);
60
+
61
+ })
62
+ };
63
+
64
+ }(jQuery));
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: initialjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Gil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.9'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ description: initialjs-rails is an assets gem for initial.js
62
+ email:
63
+ - dgilperez@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - CODE_OF_CONDUCT.md
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - initialjs-rails.gemspec
77
+ - lib/initialjs-rails.rb
78
+ - lib/initialjs-rails/engine.rb
79
+ - lib/initialjs-rails/version.rb
80
+ - lib/initialjs-rails/view_helpers.rb
81
+ - vendor/assets/javascripts/initial.js
82
+ homepage: https://github.com/dgilperez/initialjs-rails
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.4.6
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: initial.js for Rails
106
+ test_files: []