r2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +1 -1
  2. data/lib/r2.rb +17 -2
  3. data/lib/r2/version.rb +1 -1
  4. data/r2.gemspec +1 -1
  5. metadata +4 -4
data/README.md CHANGED
@@ -19,7 +19,7 @@ Report bugs in the github project at http://github.com/mzsanford/r2rb
19
19
 
20
20
  == Copyright and License ==
21
21
 
22
- Copyright 2011 Twitter, Inc.
22
+ Copyright 2011 Twitter, Inc.
23
23
 
24
24
  Licensed under the Apache License, Version 2.0 (the "License");
25
25
  you may not use this work except in compliance with the License.
data/lib/r2.rb CHANGED
@@ -1,9 +1,18 @@
1
+ # Change the directionality of a block of CSS code from right-to-left to left-to-right. This includes not only
2
+ # altering the <tt>direction</tt> attribute but also altering the 4-argument version of things like <tt>padding</tt>
3
+ # to correctly reflect the change. CSS is also minified, in part to make the processing easier.
4
+ #
5
+ # Author:: Matt Sanford (mailto:matt@twitter.com)
6
+ # Copyright:: Copyright (c) 2011 Twitter, Inc.
7
+ # License:: Licensed under the Apache License, Version 2.0
1
8
  module R2
2
9
 
10
+ # Short cut method for providing a one-time CSS change
3
11
  def self.r2(css)
4
12
  ::R2::Swapper.new.r2(css)
5
13
  end
6
14
 
15
+ # Reuable class for CSS alterations
7
16
  class Swapper
8
17
  PROPERTY_MAP = {
9
18
  'margin-left' => 'margin-right',
@@ -35,8 +44,7 @@ module R2
35
44
  'direction' => lambda {|obj,val| obj.direction_swap(val) }
36
45
  }
37
46
 
38
-
39
-
47
+ # Given a String of CSS perform the full directionality change
40
48
  def r2(original_css)
41
49
  css = minimize(original_css)
42
50
 
@@ -57,6 +65,7 @@ module R2
57
65
  return result
58
66
  end
59
67
 
68
+ # Minimize the provided CSS by removing comments, and extra specs
60
69
  def minimize(css)
61
70
  return '' unless css
62
71
 
@@ -66,6 +75,7 @@ module R2
66
75
  gsub(/\s+/, ' ') # replace multiple spaces with single spaces
67
76
  end
68
77
 
78
+ # Given a single CSS declaration rule (e.g. <tt>padding-left: 4px</tt>) return the opposing rule (so, <tt>padding-right:4px;</tt> in this example)
69
79
  def declartion_swap(decl)
70
80
  return '' unless decl
71
81
 
@@ -81,6 +91,7 @@ module R2
81
91
  return property + ':' + value + ';'
82
92
  end
83
93
 
94
+ # Given a value of <tt>rtl</tt> or <tt>ltr</tt> return the opposing value. All other arguments are ignored and returned unmolested.
84
95
  def direction_swap(val)
85
96
  if val == "rtl"
86
97
  "ltr"
@@ -91,6 +102,7 @@ module R2
91
102
  end
92
103
  end
93
104
 
105
+ # Given a value of <tt>right</tt> or <tt>left</tt> return the opposing value. All other arguments are ignored and returned unmolested.
94
106
  def side_swap(val)
95
107
  if val == "right"
96
108
  "left"
@@ -101,6 +113,9 @@ module R2
101
113
  end
102
114
  end
103
115
 
116
+ # Given a 4-argument CSS declaration value (like that of <tt>padding</tt> or <tt>margin</tt>) return the opposing
117
+ # value. The opposing value swaps the left and right but not the top or bottom. Any unrecognized argument is returned
118
+ # unmolested (for example, 2-argument values)
104
119
  def quad_swap(val)
105
120
  # 1px 2px 3px 4px => 1px 4px 3px 2px
106
121
  points = val.to_s.split(/\s+/)
data/lib/r2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module R2
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/r2.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["matt@twitter.com"]
11
11
  s.homepage = ""
12
12
  s.summary = %q{CSS flipper for right-to-left processing}
13
- s.description = %q{A Ruby port of https://github.com/ded/r2}
13
+ s.description = %q{CSS flipper for right-to-left processing. A Ruby port of https://github.com/ded/r2}
14
14
 
15
15
  s.rubyforge_project = "r2"
16
16
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r2
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Sanford
@@ -19,7 +19,7 @@ date: 2011-06-17 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: A Ruby port of https://github.com/ded/r2
22
+ description: CSS flipper for right-to-left processing. A Ruby port of https://github.com/ded/r2
23
23
  email:
24
24
  - matt@twitter.com
25
25
  executables: