purpur 0.0.1

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: 6959d8a987cc192e13d40ac5965b777b1e7084d6
4
+ data.tar.gz: 0f47c22ec4208c4afdf444aaa3daceca4fe80cfe
5
+ SHA512:
6
+ metadata.gz: eb88c6a48bdc7fbe544bc8d4532ea34ec4b588dd20b34c2c6c2c903d73ef734b5e891452ac19f7b564651df222b504ed8b5a1a875a73f316c2d4f34f3d4adbdc
7
+ data.tar.gz: 6e5746a3e94fe04ba6ed70cb65a23f4f498532b0f917d03463c32e31dd9c90914de33c15352e6155c5ec4129e8e2af130fe2d8aa00344875b31db719eec0bd5c
@@ -0,0 +1,23 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ node_modules
@@ -0,0 +1,7 @@
1
+ ## v0.0.1
2
+ * Remove unnecessary code, adjust to rails only
3
+
4
+ ## v0.0.0
5
+ * Import repo from https://github.com/outpunk/evil-icons
6
+
7
+ [@aratak]: https://github.com/aratak
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in purpur.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alexey Osipenko <alexey@osipenko.in.ua>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # PurPur
2
+
3
+ Free ‘plug and play’ set of SVG icons designed specifically for web projects. Available as a Ruby gem. Just use icon names with your templates and styles — and all the rest will be done automagically.
4
+
5
+ The 'purpur' gem originaly based on '[EvilIcons](https://github.com/outpunk/evil-icons/)'.
6
+
7
+ ### Supported browsers
8
+ We support IE 11+, Firefox, Chrome, Safari (desktop and mobile), Opera, Android 4+.
9
+
10
+ ### Using with rails
11
+
12
+ Add the `'purpur'` gem to your Gemfile:
13
+ ```ruby
14
+ gem 'purpur'
15
+ ```
16
+
17
+ This gem is under deep development, so we would reccomend to use master branch:
18
+ ```ruby
19
+ gem 'purpur', github: 'cimon-io/purpur'
20
+ ```
21
+
22
+
23
+ Add the purpur icons require to your `application.css`:
24
+ ```css
25
+ /*
26
+ *= require purpur
27
+ */
28
+ ```
29
+
30
+ Next, you have to place all svg-icons inside `app/assets/icons` folder and generate `purpur.svg` file:
31
+
32
+ ```console
33
+ bin/rake purpur:process
34
+ ```
35
+
36
+ Finally, you can render the icon using the `icon_tag` helper.
37
+ Here are some examples:
38
+ ```erb
39
+ <%= icon_tag 'search' %>
40
+ <%= icon_tag 'arrow-right', size: :m %>
41
+ <%= icon_tag 'envelope', size: :l, class: "custom-class" %>
42
+ ```
43
+
44
+ ## Roadmap
45
+ * Implement possibility to use ourside rails.
46
+ * Allow to set animated icons inside icons
47
+ * Describe algorithm to create cvg icons
48
+ * Implement responsive icons
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ require "tasks/icons"
@@ -0,0 +1,78 @@
1
+ @-webkit-keyframes purpur-spinner {
2
+ 100% {
3
+ -webkit-transform:rotate(360deg);
4
+ transform:rotate(360deg);
5
+ }
6
+ }
7
+
8
+ @keyframes purpur-spinner {
9
+ 100% {
10
+ -webkit-transform:rotate(360deg);
11
+ transform:rotate(360deg);
12
+ }
13
+ }
14
+
15
+
16
+ [data-icon] {
17
+ position: relative;
18
+ display: inline-block;
19
+ width: 0;
20
+ height: 0;
21
+ overflow: hidden;
22
+ fill: currentColor;
23
+ vertical-align: middle;
24
+
25
+ &[data-icon-size=xsm] {
26
+ width: .5em;
27
+ height: .5em;
28
+ }
29
+
30
+ &[data-icon-size=sm] {
31
+ width: .8em;
32
+ height: .8em;
33
+ }
34
+
35
+ &[data-icon-size=m] {
36
+ width: 1em;
37
+ height: 1em;
38
+ }
39
+
40
+ &[data-icon-size=lg] {
41
+ width: 1.2em;
42
+ height: 1.2em;
43
+ }
44
+
45
+ &[data-icon-size=xl] {
46
+ width: 1.8em;
47
+ height: 1.8em;
48
+ }
49
+
50
+ &[data-icon-size=xxl] {
51
+ width: 2.4em;
52
+ height: 2.4em;
53
+ }
54
+
55
+ &.spinner {
56
+ .icon--wrapper {
57
+ position: absolute;
58
+ top: 0;
59
+ left: 0;
60
+ width: 100%;
61
+ height: 100%;
62
+
63
+ -webkit-animation: purpur-spinner 1s steps(12) infinite;
64
+ animation: purpur-spinner 1s steps(12) infinite;
65
+ }
66
+ }
67
+
68
+ .icon--cnt {
69
+ width: 100%;
70
+ height: 100%;
71
+ background: inherit;
72
+ fill: inherit;
73
+ position: absolute;
74
+ transform: translateX(0); /* Crisp fix for non-retina */
75
+ -ms-transform: translate(0.5px, -0.3px); /* Crisp fix for IE */
76
+ }
77
+
78
+ }
@@ -0,0 +1,119 @@
1
+ require_relative "purpur/version"
2
+
3
+ module Purpur
4
+
5
+ ICON_SIZES = ({
6
+ xsmall: 'xsm',
7
+ extrasmall: 'xsm',
8
+ xsm: 'xsm',
9
+ small: 'sm',
10
+ sm: 'sm',
11
+ medium: 'm',
12
+ m: 'm',
13
+ md: 'm',
14
+ large: 'lg',
15
+ lg: 'lg',
16
+ big: 'xl',
17
+ xl: 'xl',
18
+ huge: 'xxl',
19
+ xxl: 'xxl'
20
+ }).with_indifferent_access
21
+ ICON_SIZES.default_proc = ->(h, i) { Rails.logger.warn("'#{i}' is wrong size of icon. Use one of #{h.keys.join(', ')}"); i.to_s; }
22
+
23
+ ICON_EXTENTION = '.svg'
24
+
25
+ ICON_SYNONIMS_HASH = if File.exists? File.join("config", "icon_synonims.yml")
26
+ YAML.load(ERB.new(IO.read(File.join("config", "icon_synonims.yml"))).result)
27
+ else
28
+ {}
29
+ end
30
+
31
+ class << self
32
+
33
+ def icon_size(size)
34
+ ICON_SIZES[size]
35
+ end
36
+
37
+ def icon_synonim(key)
38
+ (ICON_SYNONIMS_HASH.with_indifferent_access.tap do |h|
39
+ h.default_proc = ->(_, i) { i.to_s }
40
+ end)[key]
41
+ end
42
+
43
+ def icon_key(n)
44
+ case n
45
+ when Symbol, String
46
+ n.downcase
47
+ when Class
48
+ n.name.to_s.downcase
49
+ when Object
50
+ n.class.name.to_s.downcase
51
+ end
52
+ end
53
+
54
+ def icon_name(key)
55
+ icon_names[icon_synonim(icon_key(key))]
56
+ end
57
+
58
+ def register!
59
+ register_helpers
60
+ register_engine if rails?
61
+ register_sprockets if sprockets?
62
+ end
63
+
64
+ def rails?
65
+ defined?(::Rails::Engine)
66
+ end
67
+
68
+ def sprockets?
69
+ defined?(::Sprockets)
70
+ end
71
+
72
+ def root_dir
73
+ File.expand_path "."
74
+ end
75
+
76
+ def assets_dir
77
+ File.join(root_dir, 'app', 'assets')
78
+ end
79
+
80
+ def images_dir
81
+ File.join(assets_dir, 'icons')
82
+ end
83
+
84
+ def icons
85
+ Dir[File.join(self.images_dir, "*#{ICON_EXTENTION}")]
86
+ end
87
+
88
+ def icon_names
89
+ Hash[
90
+ self.icons.map {|i|
91
+ [File.basename(i, ICON_EXTENTION), File.basename(i, ICON_EXTENTION)]
92
+ }
93
+ ].tap do |h|
94
+ h.default_proc = ->(_, i) { Rails.logger.warn("'#{i}' is wrong icon name. Use one of #{h.keys.join(', ')}"); i.to_s }
95
+ end
96
+ end
97
+
98
+ def sprite_file
99
+ File.join(assets_dir, 'images', 'purpur.svg')
100
+ end
101
+
102
+ private
103
+
104
+ def register_engine
105
+ require_relative 'purpur/engine'
106
+ end
107
+
108
+ def register_sprockets
109
+ Sprockets.append_path(File.join(File.expand_path('../../', __FILE__), 'assets'))
110
+ end
111
+
112
+ def register_helpers
113
+ require_relative 'purpur/helpers'
114
+ end
115
+
116
+ end
117
+ end
118
+
119
+ Purpur.register!
@@ -0,0 +1,11 @@
1
+ module Purpur
2
+ class Engine < Rails::Engine
3
+
4
+ initializer 'purpur.view_helpers' do
5
+ ActiveSupport.on_load :action_view do
6
+ include ::Purpur::Helpers
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,57 @@
1
+ require "nokogiri"
2
+ require "erb"
3
+ require "purpur"
4
+
5
+ module Purpur
6
+
7
+ class Generator
8
+ def initialize
9
+ @templates_dir = File.expand_path('../../templates', __FILE__)
10
+ end
11
+
12
+ def files
13
+ Purpur.icons
14
+ end
15
+
16
+ def read_svg(filename)
17
+ File.read(filename)
18
+ end
19
+
20
+ def icons
21
+ files.map do |name|
22
+ file = read_svg(name)
23
+ doc = Nokogiri::HTML::DocumentFragment.parse(file)
24
+
25
+ doc.css('*').remove_attr('fill')
26
+
27
+ svg = doc.at_css('svg')
28
+ viewbox = svg['viewbox']
29
+ g = svg.search('g')
30
+ container = g.empty? ? svg : g
31
+
32
+ shape = container.children.map {|c| c.to_s}.join('')
33
+ name = File.basename(name, Purpur::ICON_EXTENTION)
34
+
35
+ { name: name, viewbox: viewbox, shape: shape }
36
+ end
37
+ end
38
+
39
+ def optimize(code, template)
40
+ template == 'sprite.svg' ? code.gsub(/$\s+/, '') : code
41
+ end
42
+
43
+ def sprite(template)
44
+ view = File.read File.join(@templates_dir, "#{template}.erb")
45
+ result = ERB.new(view).result(binding)
46
+ optimize(result, template)
47
+ end
48
+
49
+ def generate(template, destination_path)
50
+ file = File.new(destination_path, 'w')
51
+ file.write sprite(template)
52
+ file.close
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,18 @@
1
+ module Purpur
2
+ module Helpers
3
+
4
+ def icon_tag(name, options = {})
5
+ size = Purpur::ICON_SIZES[options.delete(:size)]
6
+ styleclass = ['icon', options.delete(:class)].join(' ')
7
+
8
+ content_tag(:span, {class: styleclass, data: { icon: Purpur.icon_name(name), 'icon-size' => size }}.deep_merge(options)) do
9
+ content_tag(:span, class: 'icon--wrapper') do
10
+ content_tag(:svg, class: 'icon--cnt') do
11
+ content_tag('use', nil, 'xlink:href' => "#{asset_url('purpur.svg')}##{name}-icon", 'x' => 0, 'y' => 0)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Purpur
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,33 @@
1
+ require "purpur"
2
+ require "purpur/generator"
3
+ require "uglifier"
4
+ require 'csso'
5
+
6
+
7
+ namespace :purpur do
8
+
9
+ desc "Generate SVG icons sprite"
10
+ task :process => [:normalize_filenames, :optimize] do
11
+ generator = Purpur::Generator.new
12
+ generator.generate("purpur.svg", Purpur.sprite_file)
13
+ end
14
+
15
+ desc "Normalize filenames"
16
+ task :normalize_filenames do
17
+ Purpur.icons.each do |old_name|
18
+ next unless old_name.include?('_')
19
+
20
+ new_name = File.join Purpur.images_dir, old_name.gsub('_', '-')
21
+ old_name = File.join Purpur.images_dir, old_name
22
+
23
+ File.delete(new_name) if File.exists?(new_name)
24
+ File.rename(old_name, new_name)
25
+ end
26
+ end
27
+
28
+ desc "Optimize SVG"
29
+ task :optimize do
30
+ system "svgo -f #{Purpur.images_dir} --disable=mergePaths"
31
+ end
32
+
33
+ end
@@ -0,0 +1,7 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="ei-sprite" style="display:none">
2
+ <% icons.each do |icon| %>
3
+ <symbol id='<%= icon[:name] %>-icon' viewBox='<%= icon[:viewbox] %>'>
4
+ <%= icon[:shape] %>
5
+ </symbol>
6
+ <% end %>
7
+ </svg>
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'purpur/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "purpur"
8
+ spec.version = Purpur::VERSION
9
+ spec.authors = ["Alexey Osipenko", "Alexander Madyankin", "Roman Shamin"]
10
+ spec.email = ["alexey@osipenko.in.ua", "alexander@madyankin.name"]
11
+ spec.summary = "Purpur is a SVG icons generator for modern web projects"
12
+ spec.description = "Purpur is a possibility to generate SVG which will use for icons in modern web projects"
13
+ spec.homepage = "https://github.com/cimon-io/purpur"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "nokogiri", "~> 1.6"
21
+ spec.add_dependency "bundler", "~> 1.6"
22
+ spec.add_dependency "rake", "~> 10.4"
23
+ spec.add_dependency "uglifier", "~> 2.7.0"
24
+ spec.add_dependency "csso-rails", "~> 0.3.4"
25
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: purpur
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexey Osipenko
8
+ - Alexander Madyankin
9
+ - Roman Shamin
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-06-06 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.6'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.6'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.6'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.4'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '10.4'
57
+ - !ruby/object:Gem::Dependency
58
+ name: uglifier
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 2.7.0
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: 2.7.0
71
+ - !ruby/object:Gem::Dependency
72
+ name: csso-rails
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: 0.3.4
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: 0.3.4
85
+ description: Purpur is a possibility to generate SVG which will use for icons in modern
86
+ web projects
87
+ email:
88
+ - alexey@osipenko.in.ua
89
+ - alexander@madyankin.name
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - Changelog.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - assets/purpur.scss
101
+ - lib/purpur.rb
102
+ - lib/purpur/engine.rb
103
+ - lib/purpur/generator.rb
104
+ - lib/purpur/helpers.rb
105
+ - lib/purpur/version.rb
106
+ - lib/tasks/icons.rake
107
+ - lib/templates/purpur.svg.erb
108
+ - purpur.gemspec
109
+ homepage: https://github.com/cimon-io/purpur
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.2.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Purpur is a SVG icons generator for modern web projects
133
+ test_files: []
134
+ has_rdoc: