star_rating 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1e03be6c8538957ebb0375b8849a6fd5f882908
4
+ data.tar.gz: 9e2021c4626fbbef9d5c0ad2f428b281ee23e537
5
+ SHA512:
6
+ metadata.gz: cb41217ed77faac2a4a70329502057b5098994f86ee8b141dc15a2c4aa54c1c003de6b864543fd0a8f82b11ee1ab07ccf776ab2b5ddaeaf0b42b3b8c112efa7b
7
+ data.tar.gz: 0e1a16e0733bf23f8dfdb9e3499f882361303678ba6bef70f34838ac31ff06dac97fada7df89bdae8feab719a9248663a550b2eab34beaeea60b5e19b822621a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # star_rating gem
2
+ [![Build Status](https://travis-ci.org/johnnylaw/star_rating.png?branch=master)](https://travis-ci.org/johnnylaw/star_rating)
3
+ [![Code Climate](https://codeclimate.com/github/johnnylaw/star_rating.png)](https://codeclimate.com/github/johnnylaw/star_rating)
4
+
5
+ The star_rating gem allows for the easy integration of a star rating widget into a Rails app running Ruby 2.0 or higher. The star rating form input as well as the star rating display helper rely entirely on Sass (no JavaScript) to create a **highly** configurable arrangement of any number of stars of any size and appearance. The default number of stars is of course five.
6
+
7
+ ### Installing star_rating
8
+
9
+ Install manually using
10
+
11
+ gem install star_rating
12
+
13
+ or more canonically place the following in your Gemfile:
14
+
15
+ gem 'star_rating'
16
+
17
+ and run
18
+
19
+ bundle
20
+
21
+ from the Rails root. Then run
22
+
23
+ rails g star_rating:install
24
+
25
+ to install ````app/assets/stylesheets/star_rating_settings.css.scss````, the file in which you can override any default settings.
26
+
27
+ NOTE: The generator will NOT explicitly put a ````*= require star_rating_settings```` in your ````application.*ss```` manifest file, so you will need to do that unless you are using a ````*= require_tree .```` statement in your manifest.
28
+
29
+ ## The form helper
30
+
31
+ The form helper comes in two varieties just like every other Rails form helper:
32
+
33
+ star_rating_input(object_name, method, value: nil, size: nil, html: {})
34
+
35
+ and
36
+
37
+ star_rating_input(method, size: nil, html: {})
38
+
39
+ the latter being used as part of a form builder, e.g.
40
+
41
+ <%= form_for @opinion do |f| %>
42
+ <%= f.star_rating_input :rating %>
43
+ ...
44
+ <%= f.submit 'Rate' %>
45
+ <% end %>
46
+
47
+ - The ````value```` option is the value of the currently selected star if the form is for an already existing object. This option is neither necessary nor available on the form builder method.
48
+ - The ````size```` option represents the height of the row of stars (in pixels). You can configure a default in star_rating_settings.css.scss.
49
+ - The ````html```` option is for attributes of the &lt;span&gt; tag that contains the form inputs. If a class is given, it will be added to the .star-rating class necessary for proper rendering.
50
+
51
+ ## The view helper
52
+
53
+ This is for rendering already existing ratings or possibly an average rating for an item.
54
+
55
+ star_rating(value = 0, size: nil, rating_html: {}, container_html: {})
56
+
57
+ - ````value```` is the value of the rating to be rendered, e.g. 3.3 as shown above
58
+ - The ````size```` option is as with the form helper.
59
+ - The ````rating_html```` and the ````container_html```` options are for adding HTML attributes to either of the two containers that make up the output, which essentially looks like (in the example of a value of 3.3 on a 5-point scale):
60
+
61
+ ````<span class="star-rating"><span style="width: 66.7%"></span></span>````
62
+
63
+ A possible use of the ````rating_html```` option would be as follows if you wanted to bind the rating to an AngularJS model:
64
+
65
+ star_rating(3.3, rating_html: { 'ng-model' => 'rating' })
66
+
67
+ speaking of which, my limited knowledge of AngularJS, EmberJS and other JS frameworks prevented me from making the form helpers more configurable, so please hit me with suggestions and/or pull requests if you know how the gem could be better suited for these things.
68
+
69
+ ## Configuration options
70
+ By default there are five stars with values [1, 2, 3, 4, 5], and both the form helper and the view display helper behave accordingly. You can, however, override these settings in a file in ````config/initializers```` with:
71
+
72
+ StarRating.configure do |config|
73
+ config.number_of_stars = 6
74
+ config.scale = 2
75
+ end
76
+
77
+ which would produce 6 stars with values [2, 4, 6, 8, 10, 12]. Additionally the appearance of the stars is highly configurable, utilizing SVG graphics, allowing for changes to spacing, color, outline, gradient (for the "full" stars), and you can even replace the url of the images altogether in the SCSS override file installed by the generator and get something entirely different, such as hearts or babies' faces or baboons' butts.
78
+
79
+ See the SASS file created by the generator for explicit details about how to configure the different appearance options.
80
+
81
+ This project is 5-star and uses MIT-LICENSE.
82
+
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'StarRating'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ StarRating::Engine.routes.draw do
2
+ end
@@ -0,0 +1,15 @@
1
+ module StarRating
2
+ DEFAULT_NUMBER_OF_STARS = 5
3
+ DEFAULT_SCALE = 1
4
+
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace StarRating
7
+ config.number_of_stars = DEFAULT_NUMBER_OF_STARS
8
+ config.scale = DEFAULT_SCALE
9
+ end
10
+
11
+ def self.configure(&block)
12
+ yield Engine.config if block
13
+ Engine.config
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module StarRating
2
+ module FormBuilderExt
3
+ def star_rating_field(method, size: nil, html: {})
4
+ @template.star_rating_field(@object_name, method, size: size, html: html, value: @object && @object.send(method))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module StarRating
2
+ module FormHelperExt
3
+ def star_rating_field(object_name, method, size: nil, html: {}, value: nil)
4
+ css_class = ['star-rating', html.delete(:class)].compact.join(' ')
5
+ html.merge!(class: css_class)
6
+ if size
7
+ width = size * StarRating::Engine.config.number_of_stars
8
+ html.merge!(style: "width: #{width}px; height: #{size}px")
9
+ end
10
+ content_tag(
11
+ :span,
12
+ (1..StarRating::Engine.config.number_of_stars).map do |index|
13
+ input_value = index * StarRating::Engine.config.scale
14
+ checked = value == input_value
15
+ radio_button(object_name, method, input_value, class: "star-rating-#{index}", checked: checked) + content_tag(:i)
16
+ end.join.html_safe,
17
+ html
18
+ ).html_safe
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/generators'
2
+
3
+ module StarRating
4
+ module Generators
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ def add_stylesheet
7
+ settings_file = File.join(File.dirname(__FILE__), "..", "..", "..", "vendor", "assets", "stylesheets", "star_rating", "_settings.scss")
8
+ file_name = "app/assets/stylesheets/star_rating_settings.css.scss"
9
+ create_file file_name, File.read(settings_file)
10
+ prepend_to_file file_name, "@import 'star_rating/defaults';\n\n"
11
+ gsub_file file_name, /^[\$]/, '// $'
12
+ append_to_file file_name, "\n\n@import 'star_rating';"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ module StarRating
2
+ module Helpers
3
+ def star_rating(value = 0, size: nil, rating_html: {}, container_html: {})
4
+ outer_css_class = ['star-rating', container_html.delete(:class)].compact.join(' ')
5
+ html_attrs = { class: outer_css_class }
6
+ if size
7
+ width = size * StarRating::Engine.config.number_of_stars
8
+ html_attrs.merge!(style: "width: #{width}px; height: #{size}px")
9
+ end
10
+ width_percentage = value * 100/StarRating::Engine.config.number_of_stars/StarRating::Engine.config.scale
11
+ content_tag(
12
+ :span,
13
+ content_tag(
14
+ :span,
15
+ '',
16
+ rating_html.merge(style: "width: #{width_percentage}%")
17
+ ),
18
+ html_attrs.merge(container_html)
19
+ )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'base64'
2
+
3
+ module StarRating
4
+ module SassFunctions
5
+ def self.included(base)
6
+ base.module_eval do
7
+ def encode64(string)
8
+ assert_type string, :String
9
+ ::Sass::Script::String.new(Base64.encode64(string.value))
10
+ end
11
+ declare :encode64, args: [:string]
12
+
13
+ def number_of_stars
14
+ ::Sass::Script::Number.new(StarRating::Engine.config.number_of_stars)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module StarRating
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require "star_rating/engine"
2
+ require 'star_rating/generators/install_generator'
3
+
4
+ require 'sass'
5
+
6
+ module StarRating
7
+ extend ActiveSupport::Autoload
8
+
9
+ autoload :FormHelperExt
10
+ autoload :FormBuilderExt
11
+ autoload :SassFunctions
12
+ autoload :Helpers
13
+ end
14
+
15
+ ActionView::Helpers::FormHelper.send :include, StarRating::FormHelperExt
16
+ ActionView::Base.default_form_builder.send :include, StarRating::FormBuilderExt
17
+ Sass::Script::Functions.send :include, StarRating::SassFunctions
18
+
19
+ ActiveSupport.on_load(:action_view) do
20
+ include StarRating::Helpers
21
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :star_rating do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: star_rating
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Lawrence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sass-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: genspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Makes it easy to place star-rating inputs into any web app. Configurable
98
+ appearance, number and value of stars
99
+ email:
100
+ - johnonrails@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - config/routes.rb
106
+ - lib/star_rating/engine.rb
107
+ - lib/star_rating/form_builder_ext.rb
108
+ - lib/star_rating/form_helper_ext.rb
109
+ - lib/star_rating/generators/install_generator.rb
110
+ - lib/star_rating/helpers.rb
111
+ - lib/star_rating/sass_functions.rb
112
+ - lib/star_rating/version.rb
113
+ - lib/star_rating.rb
114
+ - lib/tasks/star_rating_tasks.rake
115
+ - MIT-LICENSE
116
+ - Rakefile
117
+ - README.md
118
+ homepage: https://github.com/johnnylaw/star_rating.git
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ~>
129
+ - !ruby/object:Gem::Version
130
+ version: '2.0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.1.11
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: A flexible sass-based star-rating system for Rails.
142
+ test_files: []
143
+ has_rdoc: