stylesheet_flipper 0.0.1 → 0.0.2
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 +1 -0
- data/README.md +11 -12
- data/lib/stylesheet_flipper/helper.rb +14 -0
- data/lib/stylesheet_flipper/locales.rb +11 -0
- data/lib/stylesheet_flipper/railtie.rb +13 -0
- data/lib/stylesheet_flipper/version.rb +1 -1
- data/lib/stylesheet_flipper.rb +3 -13
- data/spec/spec_helper.rb +10 -0
- data/spec/units/helper_spec.rb +27 -0
- data/spec/units/locales_spec.rb +25 -0
- data/stylesheet_flipper.gemspec +1 -0
- metadata +27 -7
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -32,20 +32,9 @@ Edit your application to serve up a copy of your stylesheets with '-flipped' pos
|
|
32
32
|
*= require application
|
33
33
|
*/
|
34
34
|
|
35
|
-
*app/helpers/application_helper.rb*
|
36
|
-
|
37
|
-
def stylesheet_name(options = {})
|
38
|
-
options[:for] ||= 'application'
|
39
|
-
if [:ar, :ckb, :fa, :he, :ug].include? I18n.locale
|
40
|
-
"#{options[:for]}-flipped"
|
41
|
-
else
|
42
|
-
options[:for]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
35
|
*app/views/layouts/application.html.erb*
|
47
36
|
|
48
|
-
<%= stylesheet_link_tag
|
37
|
+
<%= stylesheet_link_tag stylesheet_flipper %>
|
49
38
|
|
50
39
|
*config/environments/development.rb*
|
51
40
|
|
@@ -56,6 +45,16 @@ Edit your application to serve up a copy of your stylesheets with '-flipped' pos
|
|
56
45
|
|
57
46
|
config.assets.precompile += %w( application-flipped.css )
|
58
47
|
|
48
|
+
### Advanced usage
|
49
|
+
|
50
|
+
If you have stylesheets other that application.css, you can specify using
|
51
|
+
|
52
|
+
<%= stylesheet_link_tag stylesheet_flipper(for: 'my_custom_css') %>
|
53
|
+
|
54
|
+
You can specify the locales you want flipped by adding *config/initializers/stylesheet_flipper.rb*
|
55
|
+
|
56
|
+
StylesheetFlipper.flipped_locales = [:en, :da ...]
|
57
|
+
|
59
58
|
## Contributing
|
60
59
|
|
61
60
|
1. Fork it
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'stylesheet_flipper/locales'
|
2
|
+
|
3
|
+
module StylesheetFlipper
|
4
|
+
module Helper
|
5
|
+
def stylesheet_flipper(options = {})
|
6
|
+
options[:for] ||= 'application'
|
7
|
+
if StylesheetFlipper.flipped_locales.include? I18n.locale
|
8
|
+
"#{options[:for]}-flipped"
|
9
|
+
else
|
10
|
+
options[:for]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module StylesheetFlipper
|
2
|
+
def self.flipped_locales
|
3
|
+
@@flipped_locales ||= [:ar, :ckb, :fa, :he, :ug]
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.flipped_locales=(value)
|
7
|
+
raise ArgumentError.new('flipped_locales should be an array') unless value.is_a?(Array)
|
8
|
+
value.map! &:to_sym
|
9
|
+
@@flipped_locales = value
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module StylesheetFlipper
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer "stylesheet_flipper.initialize_rails", :group => :assets do |app|
|
4
|
+
app.assets.register_bundle_processor 'text/css', :stylesheet_flipper do |context, data|
|
5
|
+
if context.logical_path.include?('-flipped')
|
6
|
+
R2.r2 data
|
7
|
+
else
|
8
|
+
data
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/stylesheet_flipper.rb
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
require "stylesheet_flipper/version"
|
2
|
+
require "stylesheet_flipper/railtie"
|
3
|
+
require "stylesheet_flipper/helper"
|
2
4
|
require "r2"
|
3
5
|
|
4
|
-
|
5
|
-
class Railtie < ::Rails::Railtie
|
6
|
-
initializer "stylesheet_flipper.initialize_rails", :group => :assets do |app|
|
7
|
-
app.assets.register_bundle_processor 'text/css', :stylesheet_flipper do |context, data|
|
8
|
-
if context.logical_path.include?('-flipped')
|
9
|
-
R2.r2 data
|
10
|
-
else
|
11
|
-
data
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
6
|
+
ActionView::Base.send :include, StylesheetFlipper::Helper
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stylesheet_flipper/helper'
|
3
|
+
|
4
|
+
module StylesheetFlipper
|
5
|
+
class TestHelper; end
|
6
|
+
StylesheetFlipper::TestHelper.send :include, StylesheetFlipper::Helper
|
7
|
+
|
8
|
+
describe TestHelper do
|
9
|
+
let(:helper){ TestHelper.new }
|
10
|
+
|
11
|
+
it { should respond_to :stylesheet_flipper }
|
12
|
+
it "should return 'application' for :en locale" do
|
13
|
+
I18n.locale = :en
|
14
|
+
helper.stylesheet_flipper.should == "application"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return 'application-flipped' for :ar locale" do
|
18
|
+
I18n.locale = :ar
|
19
|
+
helper.stylesheet_flipper.should == "application-flipped"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should support :for option" do
|
23
|
+
I18n.locale = :en
|
24
|
+
helper.stylesheet_flipper(for: 'my_custom_css').should == "my_custom_css"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'stylesheet_flipper/locales'
|
2
|
+
|
3
|
+
module StylesheetFlipper
|
4
|
+
describe StylesheetFlipper.flipped_locales do
|
5
|
+
it { should include(:ar) }
|
6
|
+
it { should include(:ckb) }
|
7
|
+
it { should include(:fa) }
|
8
|
+
it { should include(:he) }
|
9
|
+
it { should include(:ug) }
|
10
|
+
|
11
|
+
it { should_not include(:en) }
|
12
|
+
it { should_not include(:da) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "setting locales" do
|
16
|
+
it "should set flipped_locales and normalize values" do
|
17
|
+
StylesheetFlipper.flipped_locales = [:da, 'en']
|
18
|
+
StylesheetFlipper.flipped_locales.should == [:da, :en]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should raise argument error if invalid argument" do
|
22
|
+
expect{ StylesheetFlipper.flipped_locales = :da }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/stylesheet_flipper.gemspec
CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.summary = %q{Flip stylesheets on-the-fly and during asset compilation}
|
9
9
|
gem.homepage = "https://github.com/monibuds/stylesheet_flipper"
|
10
10
|
|
11
|
+
gem.add_development_dependency "rspec"
|
11
12
|
gem.add_runtime_dependency "rails", "~>3.0"
|
12
13
|
gem.add_runtime_dependency "r2"
|
13
14
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stylesheet_flipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70258849666020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70258849666020
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: rails
|
16
|
-
requirement: &
|
27
|
+
requirement: &70258849665300 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ~>
|
@@ -21,10 +32,10 @@ dependencies:
|
|
21
32
|
version: '3.0'
|
22
33
|
type: :runtime
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *70258849665300
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: r2
|
27
|
-
requirement: &
|
38
|
+
requirement: &70258849664500 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,7 +43,7 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :runtime
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70258849664500
|
36
47
|
description: Flip stylesheets on-the-fly and during asset compilation
|
37
48
|
email:
|
38
49
|
- jeppe@liisberg.net
|
@@ -46,7 +57,13 @@ files:
|
|
46
57
|
- README.md
|
47
58
|
- Rakefile
|
48
59
|
- lib/stylesheet_flipper.rb
|
60
|
+
- lib/stylesheet_flipper/helper.rb
|
61
|
+
- lib/stylesheet_flipper/locales.rb
|
62
|
+
- lib/stylesheet_flipper/railtie.rb
|
49
63
|
- lib/stylesheet_flipper/version.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
- spec/units/helper_spec.rb
|
66
|
+
- spec/units/locales_spec.rb
|
50
67
|
- stylesheet_flipper.gemspec
|
51
68
|
homepage: https://github.com/monibuds/stylesheet_flipper
|
52
69
|
licenses: []
|
@@ -72,4 +89,7 @@ rubygems_version: 1.8.10
|
|
72
89
|
signing_key:
|
73
90
|
specification_version: 3
|
74
91
|
summary: Flip stylesheets on-the-fly and during asset compilation
|
75
|
-
test_files:
|
92
|
+
test_files:
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/units/helper_spec.rb
|
95
|
+
- spec/units/locales_spec.rb
|