required_field_style 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/dataSources.ids +6 -0
- data/.idea/dataSources.xml +12 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/required_field_style.iml +138 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/workspace.xml +399 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +0 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/controllers/application_controller.rb +2 -0
- data/app/models/account.rb +5 -0
- data/app/views/accounts/new.html.erb +7 -0
- data/config/.gitignore +6 -0
- data/config/boot.rb +127 -0
- data/config/environment.rb +50 -0
- data/config/environments/.gitignore +5 -0
- data/config/environments/test.rb +20 -0
- data/config/locales/en.yml +29 -0
- data/config/routes.rb +6 -0
- data/db/test.sqlite3 +0 -0
- data/lib/required_field_style.rb +32 -0
- data/lib/required_field_style/version.rb +3 -0
- data/required_field_style.gemspec +30 -0
- data/spec/required_field_style.rb +31 -0
- data/spec/spec_helper.rb +52 -0
- metadata +221 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# RequiredFieldStyle
|
2
|
+
|
3
|
+
This gem will automatically add asterisk after your form label for required field.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'required_field_style'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install required_field_style
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You do not need to do anything, after you install it and restart the server this gem will automatically do the job.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/active_authorisation/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/config/.gitignore
ADDED
data/config/boot.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
#gem 'bundler'
|
7
|
+
#require 'bundler'
|
8
|
+
|
9
|
+
module Rails
|
10
|
+
class << self
|
11
|
+
def boot!
|
12
|
+
unless booted?
|
13
|
+
preinitialize
|
14
|
+
pick_boot.run
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def booted?
|
19
|
+
defined? Rails::Initializer
|
20
|
+
end
|
21
|
+
|
22
|
+
def pick_boot
|
23
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
24
|
+
end
|
25
|
+
|
26
|
+
def vendor_rails?
|
27
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
28
|
+
end
|
29
|
+
|
30
|
+
def preinitialize
|
31
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def preinitializer_path
|
35
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Boot
|
40
|
+
def run
|
41
|
+
load_initializer
|
42
|
+
Rails::Initializer.run(:set_load_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class VendorBoot < Boot
|
47
|
+
def load_initializer
|
48
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
49
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
50
|
+
Rails::GemDependency.add_frozen_gem_path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class GemBoot < Boot
|
55
|
+
def load_initializer
|
56
|
+
self.class.load_rubygems
|
57
|
+
load_rails_gem
|
58
|
+
require 'initializer'
|
59
|
+
end
|
60
|
+
|
61
|
+
def load_rails_gem
|
62
|
+
if version = self.class.gem_version
|
63
|
+
gem 'rails', version
|
64
|
+
else
|
65
|
+
gem 'rails'
|
66
|
+
end
|
67
|
+
rescue Gem::LoadError => load_error
|
68
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
69
|
+
exit 1
|
70
|
+
end
|
71
|
+
|
72
|
+
class << self
|
73
|
+
def rubygems_version
|
74
|
+
Gem::RubyGemsVersion rescue nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def gem_version
|
78
|
+
if defined? RAILS_GEM_VERSION
|
79
|
+
RAILS_GEM_VERSION
|
80
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
81
|
+
ENV['RAILS_GEM_VERSION']
|
82
|
+
else
|
83
|
+
parse_gem_version(read_environment_rb)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def load_rubygems
|
88
|
+
min_version = '1.3.2'
|
89
|
+
require 'rubygems'
|
90
|
+
unless rubygems_version >= min_version
|
91
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
rescue LoadError
|
96
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
97
|
+
exit 1
|
98
|
+
end
|
99
|
+
|
100
|
+
def parse_gem_version(text)
|
101
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
def read_environment_rb
|
106
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class Rails::Boot
|
113
|
+
def run
|
114
|
+
load_initializer
|
115
|
+
|
116
|
+
Rails::Initializer.class_eval do
|
117
|
+
def load_gems
|
118
|
+
@bundler_loaded ||= ::Bundler.require :default, Rails.env
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
Rails::Initializer.run(:set_load_path)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# All that for this:
|
127
|
+
Rails.boot!
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
# Be sure to restart your web server when you modify this file.
|
4
|
+
|
5
|
+
# Uncomment below to force Rails into production mode when
|
6
|
+
# you don't control web/app server and can't set it the proper way
|
7
|
+
# ENV['RAILS_ENV'] ||= 'production'
|
8
|
+
ENV["TDSVER"] = "8.0"
|
9
|
+
# Specifies gem version of Rails to use when vendor/rails is not present
|
10
|
+
|
11
|
+
# Bootstrap the Rails environment, frameworks, and default configuration
|
12
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
13
|
+
|
14
|
+
Rails::Initializer.run do |config|
|
15
|
+
# Settings in config/environments/* take precedence those specified here
|
16
|
+
|
17
|
+
# Skip frameworks you're not going to use
|
18
|
+
# config.frameworks -= [ :action_web_service, :action_mailer ]
|
19
|
+
|
20
|
+
# Add additional load paths for your own custom dirs
|
21
|
+
|
22
|
+
# Force all environments to use the same logger level
|
23
|
+
# (by default production uses :info, the others :debug)
|
24
|
+
# config.log_level = :debug
|
25
|
+
|
26
|
+
# Use the database for sessions instead of the file system
|
27
|
+
# (create the session table with 'rake db:sessions:create')
|
28
|
+
# config.action_controller.session_store = :active_record_store
|
29
|
+
|
30
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
31
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
32
|
+
# like if you have constraints or database-specific column types
|
33
|
+
config.active_record.schema_format = :sql
|
34
|
+
|
35
|
+
# Activate observers that should always be running
|
36
|
+
# config.active_record.observers = :cacher, :garbage_collector
|
37
|
+
|
38
|
+
# Make Active Record use UTC-base instead of local time
|
39
|
+
# config.active_record.default_timezone = :utc
|
40
|
+
#
|
41
|
+
|
42
|
+
# See Rails::Configuration for more options
|
43
|
+
config.action_mailer.delivery_method = :test
|
44
|
+
|
45
|
+
config.action_controller.session = { :key => "_test_ab_session", :secret => "foobafoobafoobafoobafoobarrrrrfoobar" }
|
46
|
+
end
|
47
|
+
|
48
|
+
# Include your application configuration below
|
49
|
+
ActiveRecord::Base.pluralize_table_names = true
|
50
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The test environment is used exclusively to run your application's
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.action_controller.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Tell ActionMailer not to deliver emails to the real world.
|
17
|
+
# The :test delivery method accumulates sent emails in the
|
18
|
+
# ActionMailer::Base.deliveries array.
|
19
|
+
config.action_mailer.delivery_method = :test
|
20
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
en:
|
2
|
+
activerecord:
|
3
|
+
attributes:
|
4
|
+
ledger:
|
5
|
+
BatchTypeCode: Adjustment type
|
6
|
+
ticket:
|
7
|
+
IssueDate: Action Date
|
8
|
+
IssueTitle: Title
|
9
|
+
IssueClassCode: Category
|
10
|
+
UserAssigned: Assigned To
|
11
|
+
IssueSourceCode: Source
|
12
|
+
IssueText: Description
|
13
|
+
ReferenceValue: Reference Value
|
14
|
+
ticket_note:
|
15
|
+
IssueNoteTitle: Title
|
16
|
+
IssueNoteText: Description
|
17
|
+
time:
|
18
|
+
formats:
|
19
|
+
date: %d/%m/%Y
|
20
|
+
short_datetime: %d/%m/%Y
|
21
|
+
date_time: %d/%m/%Y %l:%M%p
|
22
|
+
descriptive_timestamp: at %l:%M%p on %b %d, %Y
|
23
|
+
date:
|
24
|
+
formats:
|
25
|
+
date: %d/%m/%Y
|
26
|
+
full_date: %A, %B %d, %Y
|
27
|
+
date_time: %d/%m/%Y %l:%M%p
|
28
|
+
descriptive_timestamp: at %l:%M%p on %b %d, %Y
|
29
|
+
|
data/config/routes.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
# Install the default route as the lowest priority.
|
3
|
+
# map.connect ':controller/:action/:id', :requirements => { :id => /.*/ }
|
4
|
+
map.connect ':controller/:action/:id'
|
5
|
+
map.connect ':controller/:action/:id.:format'
|
6
|
+
end
|
data/db/test.sqlite3
ADDED
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "required_field_style/version"
|
2
|
+
require "validation_reflection"
|
3
|
+
|
4
|
+
module RequiredFieldStyle
|
5
|
+
class ActionView::Helpers::FormBuilder
|
6
|
+
alias :orig_label :label
|
7
|
+
|
8
|
+
# add a '*' after the field label if the field is required
|
9
|
+
def label(method, content_or_options = nil, options = nil, &block)
|
10
|
+
if content_or_options && content_or_options.class == Hash
|
11
|
+
options = content_or_options
|
12
|
+
else
|
13
|
+
content = content_or_options
|
14
|
+
end
|
15
|
+
|
16
|
+
required_mark = ''
|
17
|
+
required_mark = '<sup style="color:red"> *</sup>'.html_safe if ValidationChecker.mandatory_field?(object.class, method)
|
18
|
+
|
19
|
+
content ||= method.to_s.humanize
|
20
|
+
content = content + required_mark
|
21
|
+
|
22
|
+
self.orig_label(method, content, options || {}, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ValidationChecker
|
27
|
+
def self.mandatory_field?(klass, name)
|
28
|
+
klass.reflect_on_validations_for(name).find { |f| f.macro.to_s == 'validates_presence_of' }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'required_field_style/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "required_field_style"
|
8
|
+
spec.version = RequiredFieldStyle::VERSION
|
9
|
+
spec.authors = ["Michael Febrianto"]
|
10
|
+
spec.email = ["michaelfebrianto@gmail.com"]
|
11
|
+
spec.summary = %q{This gem will add asterisk after your required field label}
|
12
|
+
spec.description = %q{This gem will add asterisk after your required field label}
|
13
|
+
spec.homepage = "http://www.mfebrianto.com"
|
14
|
+
spec.license = ""
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", "~> 2.3.11"
|
22
|
+
spec.add_dependency "rack", "~> 1.1.6"
|
23
|
+
spec.add_dependency "validation_reflection", "~> 0.3.8"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec", "~> 1.3.0"
|
28
|
+
spec.add_development_dependency "rspec-rails", "~> 1.3.0"
|
29
|
+
spec.add_development_dependency "sqlite3"
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RequiredFieldStyle
|
4
|
+
|
5
|
+
describe '/accounts/new.html.erb', :type => :view do
|
6
|
+
it 'should render mandatory style for required field' do
|
7
|
+
required_field = 'Account no'
|
8
|
+
mandatory_style = '<sup style=\"color:red\"> *</sup>'
|
9
|
+
assigns[:account] = Account.new
|
10
|
+
render
|
11
|
+
response.body.to_s =~ /#{required_field}#{mandatory_style}/
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'ValidationChecker' do
|
16
|
+
it 'should return MacroReflection if field_name is mandatory fields' do
|
17
|
+
field_name = :account_no
|
18
|
+
result = ValidationChecker.mandatory_field?(Account, field_name)
|
19
|
+
result.instance_of?(ActiveRecord::Reflection::MacroReflection).should be true
|
20
|
+
result.macro.should == :validates_presence_of
|
21
|
+
result.name.should == field_name
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return nil if field_name is not mandatory fields' do
|
25
|
+
field_name = :company_name
|
26
|
+
result = ValidationChecker.mandatory_field?(Account, field_name)
|
27
|
+
result.should be nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
SPEC_ROOT = Pathname(File.expand_path('..', __FILE__))
|
4
|
+
|
5
|
+
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
|
7
|
+
require 'spec/autorun'
|
8
|
+
require 'spec/rails'
|
9
|
+
|
10
|
+
Pathname.glob(SPEC_ROOT.join('support', '**', '*.rb')).each { |f| require f.to_s }
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
# If you're not using ActiveRecord you should remove these
|
14
|
+
# lines, delete config/database.yml and disable :active_record
|
15
|
+
# in your config/boot.rb
|
16
|
+
# config.use_transactional_fixtures = true
|
17
|
+
# config.use_instantiated_fixtures = false
|
18
|
+
# config.fixture_path = SPEC_ROOT.join('fixtures/').to_s
|
19
|
+
# ActiveSupport::TestCase.fixture_class_names = {:luBatchType => BatchType, :luBatchGroup => BatchGroup }
|
20
|
+
|
21
|
+
# == Fixtures
|
22
|
+
#
|
23
|
+
# You can declare fixtures for each example_group like this:
|
24
|
+
# describe "...." do
|
25
|
+
# fixtures :table_a, :table_b
|
26
|
+
#
|
27
|
+
# Alternatively, if you prefer to declare them only once, you can
|
28
|
+
# do so right here. Just uncomment the next line and replace the fixture
|
29
|
+
# names with your fixtures.
|
30
|
+
#
|
31
|
+
# config.global_fixtures = :table_a, :table_b
|
32
|
+
#
|
33
|
+
# If you declare global fixtures, be aware that they will be declared
|
34
|
+
# for all of your examples, even those that don't use them.
|
35
|
+
#
|
36
|
+
# You can also declare which fixtures to use (for example fixtures for test/fixtures):
|
37
|
+
#
|
38
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
39
|
+
#
|
40
|
+
# == Mock Framework
|
41
|
+
#
|
42
|
+
# RSpec uses its own mocking framework by default. If you prefer to
|
43
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
44
|
+
#
|
45
|
+
# config.mock_with :mocha
|
46
|
+
# config.mock_with :flexmock
|
47
|
+
# config.mock_with :rr
|
48
|
+
#
|
49
|
+
# == Notes
|
50
|
+
#
|
51
|
+
# For more information take a look at Spec::Runner::Configuration and Spec::Runner
|
52
|
+
end
|