cssensible 0.2.2 → 0.3.0

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.
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (July 27th, 2010)
4
+
5
+ * improved returned grids (multiple line-heights within one result that still make up the same grid)
6
+ * cleaner output
7
+
8
+
9
+ ## 0.2.2 (July 19th, 2010)
10
+
11
+ * fixed bug that made everything explode once --line-height was NOT used
12
+
13
+
3
14
  ## 0.2.1 (July 17th, 2010)
4
15
 
5
16
  * fixed bug that made everything explode once --line-height was used
data/README.md CHANGED
@@ -28,18 +28,31 @@ Options:
28
28
  # finds sensible grids including a font-size of 12px
29
29
  $ cssensible 12
30
30
 
31
+
31
32
  # finds sensible grids including both 12px and 16px
32
33
  $ cssensible 12 16
33
34
 
34
- # finds sensible grids including both 12px and 16px where the resulting
35
+
36
+ # finds sensible grids including 12px, 15px and 16px where the resulting
35
37
  # line-height for every font-size is at least 1.3em
36
- $ cssensible --line-height 1.3 12 16
38
+ $ cssensible --line-height 1.3 12 15 16
39
+
40
+ line-height: 12px (9 font-sizes)
41
+
42
+ font-size (px) | line-height (px) | line-height (em)
43
+ ------------------+--------------------+--------------------
44
+ 10 | 18 | 1.8
45
+ 12* | 18 | 1.5
46
+ 15* | 24 | 1.6
47
+ 16* | 24 | 1.5
48
+ 20 | 30 | 1.5
49
+ 24 | 36 | 1.5
50
+ 25 | 36 | 1.44
51
+ 28 | 42 | 1.5
52
+ 30 | 42 | 1.4
37
53
 
38
54
 
39
- ## Documentation
40
55
 
41
- View the HTML document:
42
- $ open doc/index.html
43
56
 
44
57
  ## Problems?
45
58
 
@@ -5,7 +5,7 @@ require_relative 'vertical_grid'
5
5
  module CSSensible
6
6
  class Finder
7
7
  # A line-height should be at least this em-value to improve readability.
8
- # MIN_LINE_HEIGHT_EM_VALUE = EmValue.new(1.3)
8
+ MIN_LINE_HEIGHT_EM_VALUE = EmValue.new(1.3)
9
9
 
10
10
  # Size in pixel a font should at least be to be readable
11
11
  MIN_FONT_SIZE_PX = 10
@@ -13,56 +13,78 @@ module CSSensible
13
13
  attr_reader :font_size
14
14
 
15
15
  # Returns a new Vertical Grid Finder based on the font size passed to new.
16
- def initialize(font_sizes, min_line_height_em)
16
+ def initialize(font_sizes, min_line_height_em = MIN_LINE_HEIGHT_EM_VALUE)
17
17
  @font_sizes = font_sizes.sort
18
- # set minimum line-height to value passed OR 1.0 IF NIL
19
- # TODO this is probably wrong
20
- @min_line_height_em = min_line_height_em || 1.0
18
+ @min_line_height_em = min_line_height_em
21
19
  end
22
20
 
23
21
  # Finds sensible vertical grids based on the parameters given in new.
24
22
  def find
25
23
  vertical_grids = []
26
- line_heights = []
27
24
 
28
- # go through all line-heights that could possibly include all font-sizes
29
- (@font_sizes.last .. @font_sizes.last * 2).each do |line_height|
30
- line_height_usable = true
25
+ # for the first iteration, all line-heights from the smallest font-size
26
+ # to two times the largest font-size are potentially possible
27
+ line_heights = (@font_sizes.first .. @font_sizes.last * 2).to_a
31
28
 
32
- # go through all of the required font-sizes
33
- @font_sizes.each do |font_size|
34
- # check if line-height for this font-size can be expressed in 'em'
35
- line_height_em = EmValue.new(line_height / font_size.to_f)
29
+ # go through required font-sizes and identify all line-heights that work
30
+ # with all of them
31
+ @font_sizes.each do |font_size|
32
+ possible_line_heights = []
36
33
 
37
- unless line_height_em.usable?
38
- line_height_usable = false
39
- break
34
+ # keep line-height if it can be expressed in valid 'em' for this
35
+ # font-size
36
+ line_heights.each do |line_height|
37
+ if EmValue.new(line_height / font_size.to_f).usable?
38
+ possible_line_heights << line_height
40
39
  end
41
40
  end
42
41
 
43
- line_heights << line_height if line_height_usable
42
+ # for next iteration, only check line-heights that work with this
43
+ # font-size
44
+ line_heights = possible_line_heights
44
45
  end
45
46
 
46
47
  line_heights.each do |line_height|
48
+ base_line_height = line_height
47
49
  font_sizes_to_line_height = {}
48
50
 
49
- (MIN_FONT_SIZE_PX .. line_height).each do |font_size|
51
+ # we will increment the line-height as soon as a resulting em-value
52
+ # falls underneath @min_line_height_em; to prevent large differences, we
53
+ # add half of our base line-height if possible
54
+ if line_height.even?
55
+ line_height_increment = line_height / 2
56
+ else
57
+ line_height_increment = line_height
58
+ end
59
+
60
+ # to offer a larger range of available font-sizes, we start from the
61
+ # smallest possible font-size and end at don't just end at the biggest
62
+ # supplied font-size
63
+ (MIN_FONT_SIZE_PX .. @font_sizes.last * 2).each do |font_size|
50
64
  line_height_em = EmValue.new(line_height / font_size.to_f)
51
- font_sizes_to_line_height[font_size] = line_height_em if line_height_em.usable? && line_height_em >= @min_line_height_em
65
+
66
+ # increment line-height if we fall below the minimum value
67
+ if line_height_em < @min_line_height_em
68
+ line_height += line_height_increment
69
+ redo
70
+ end
71
+
72
+ # map font-size and line-height for this grid
73
+ if line_height_em.usable? && line_height_em >= @min_line_height_em
74
+ font_sizes_to_line_height[font_size] = line_height_em
75
+ end
52
76
  end
53
77
 
54
- if font_sizes_to_line_height.keys.include_all?(@font_sizes)
55
- vertical_grids << VerticalGrid.new(@font_sizes, line_height, font_sizes_to_line_height) unless font_sizes_to_line_height.empty?
78
+ # add grid to results
79
+ # TODO can font_sizes_to_line_height ever really be empty?
80
+ unless font_sizes_to_line_height.empty?
81
+ vertical_grid = VerticalGrid.new(@font_sizes, base_line_height,
82
+ font_sizes_to_line_height)
83
+ vertical_grids << vertical_grid
56
84
  end
57
85
  end
58
86
 
59
87
  vertical_grids
60
-
61
- # line_heights = {}
62
- # (fontsize .. fontsize * 2).each do |lineheight|
63
- # lineheight_ratio = EmValue.new(lineheight / fontsize.to_f)
64
- # line_heights[lineheight] = lineheight_ratio if lineheight_ratio.usable?
65
- # end
66
88
  end
67
89
  end
68
90
  end
@@ -1,4 +1,4 @@
1
1
  module CSSensible
2
2
  # The current version of CSSensible.
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
@@ -15,11 +15,26 @@ module CSSensible
15
15
  end
16
16
 
17
17
  def to_s
18
- vertical_grid = "line-height: #{@line_height}px\n"
19
- vertical_grid += "#{@font_sizes_to_line_height.size} font-size(s):\n"
18
+ vertical_grid = "line-height: #{@line_height}px"
19
+ vertical_grid += " (#{@font_sizes_to_line_height.size} font-sizes)\n"
20
+
21
+ vertical_grid += "\n"
22
+
23
+ vertical_grid += "font-size (px)".center(18)
24
+ vertical_grid += "|"
25
+ vertical_grid += "line-height (px)".center(20)
26
+ vertical_grid += "|"
27
+ vertical_grid += "line-height (em)".center(20)
28
+ vertical_grid += "\n"
29
+ vertical_grid += "------------------+--------------------+--------------------\n"
20
30
 
21
31
  @font_sizes_to_line_height.each do |font_size, line_height_em|
22
- vertical_grid += " font-size: #{font_size}px#{'*' if @base_font_sizes.include?(font_size)}\tline-height: #{line_height_em}em\n"
32
+ vertical_grid += " #{font_size}#{'*' if @base_font_sizes.include?(font_size)}".ljust(18)
33
+ vertical_grid += "|"
34
+ vertical_grid += " #{(font_size * line_height_em).to_i}".ljust(20)
35
+ vertical_grid += "|"
36
+ vertical_grid += " #{line_height_em}".ljust(20)
37
+ vertical_grid += "\n"
23
38
  end
24
39
 
25
40
  vertical_grid
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dominik Habersack
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-20 00:00:00 +12:00
18
+ date: 2010-07-27 00:00:00 +12:00
19
19
  default_executable:
20
20
  dependencies: []
21
21