webify_ruby 0.0.8 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c1b122b795e4e326dd5a3e0c1bbd21fc7ceaa7c
4
- data.tar.gz: 066baf0ecb5422df5d89eb858f66223a0c9fa493
3
+ metadata.gz: 3508f82d818a9cd27c1739a92005ba15c17a3fe6
4
+ data.tar.gz: 69caea4901abffba0610032e1493c7a7f69a1485
5
5
  SHA512:
6
- metadata.gz: fd43e36cf7147cb52d56fb03bffe3a83bdbdf79011a9bafb829d5ac9b234c95e8d7f2a587fa54c477a6a5e8beb83418d7956fb7bf43d6d4994d29493fb728354
7
- data.tar.gz: 92102c14ffd358b9c1cbacf1e4ceeee6298022548f8710d21fa6ca261178b57c11f21a4fe02e3d131910593aac34b5731516b51d3b724ba241598e479bdffc5a
6
+ metadata.gz: 42fdf9121ba47b5c56c4f4574eaef776bb0268136aac680ce44e794aefd53b1d78692a32297d9f796f296065ac9e649e1035d9b21b15dba05c6015f5c040aabf
7
+ data.tar.gz: 3b178ef09a97e7c3bc0c97b33e5a9d6c47a77acc20c53c4db964d43ce57f3c4cd7482acc4bb1c7695cc500d3f7108de9501df88d0450e3cc45006288cb365d40
data/README.rdoc CHANGED
@@ -15,6 +15,11 @@
15
15
  Version 0.0.6 :: Gagra
16
16
  Version 0.0.7 :: Sochi
17
17
  Version 0.0.8 :: Poti
18
+ Version 0.1.0 :: Kaspi
19
+
20
+ == Generated HTML preview
21
+
22
+ {rdoc-image:http://dachi-gh.github.io/webify_ruby/preview.png}[http://dachi-gh.github.io/webify_ruby/preview.png]
18
23
 
19
24
  == Usage
20
25
 
data/lib/webify_ruby.rb CHANGED
@@ -6,6 +6,7 @@ require 'webify_ruby/version'
6
6
  require 'webify_ruby/errors'
7
7
  require 'webify_ruby/convert'
8
8
  require 'webify_ruby/css'
9
+ require 'webify_ruby/html'
9
10
  require 'webify_ruby/tasks'
10
11
  require 'webify_ruby/railtie' if defined?(Rails)
11
12
 
@@ -38,26 +38,29 @@ module WebifyRuby
38
38
 
39
39
  # Public: Initialize a Convertion of font-file.
40
40
  #
41
- # file - A String containing relative or full path of file to convert.
42
- # :dir - A String indicating to the desired to save converted files (optional).
43
- # :css - A String or Boolean value indicating a desired CSS behavior.
44
- # If present, it can be either directory path in String or Boolean.
45
- # If value is set to true, then a stylesheet file won't be created,
46
- # but code will become accessible as :styles attribute (optional).
47
- # :link_to - A String notation indicating how to prefix a font url in CSS (optional).
41
+ # file - A String containing relative or full path of file to convert.
42
+ # :dir - A String indicating to the desired to save converted files (optional).
43
+ # :css - A String or Boolean value indicating a desired CSS behavior.
44
+ # If present, it can be either directory path in String or Boolean.
45
+ # If value is set to true, then a stylesheet file won't be created,
46
+ # but code will become accessible as :styles attribute (optional).
47
+ # :link_to - A String notation indicating how to prefix a font url in CSS (optional).
48
48
  # :unique_id - A custom identifier which will separate different fonts (optional).
49
+ # :html - If present, it will create an HTML file in the given directory.
50
+ # Note: CSS has to be set to generate a file too. (optional).
49
51
  #
50
52
  # Returns nothing.
51
53
  # Raises Errno::ENOENT if the inputted file cannot be found.
52
54
  # Raises Error if the inputted font file is not withing valid extensions.
53
55
  # Raises Error::ENOENT if the directory of inputted file is not accessible.
54
- def initialize(file, dir: nil, css: nil, link_to: nil, unique_id: nil)
55
- [file, dir, css, link_to, unique_id]
56
+ def initialize(file, dir: nil, css: nil, link_to: nil, unique_id: nil, html: nil)
57
+ [file, dir, css, link_to, unique_id, html]
56
58
 
57
59
  @desired_dir = dir
58
60
  @css = css
59
61
  @link_to = link_to
60
62
  @unique_id = unique_id
63
+ @html = html
61
64
 
62
65
  raise Errno::ENOENT, "The font file '#{file}' does not exist" unless File.exists?(file)
63
66
  @original_file = file
@@ -90,6 +93,7 @@ module WebifyRuby
90
93
  end
91
94
 
92
95
  generate_css unless @css.nil?
96
+ generate_html unless @css_file.nil? or @html.nil?
93
97
  end
94
98
 
95
99
  # Internal: Know files that have been touched by running binary command.
@@ -128,6 +132,18 @@ module WebifyRuby
128
132
 
129
133
  @css_file = css.write @css if should_write_css?
130
134
  end
135
+
136
+ # Internal: Work with Html class and make a HTML5 Doc.
137
+ # Create a file under given directory.
138
+ # This method should not execute if there is no css file.
139
+ #
140
+ # Returns the HTML filepath or nothing.
141
+ def generate_html
142
+ return false if @css_file.nil? or @html.nil?
143
+
144
+ html = WebifyRuby::Html.new(@css_file, @html)
145
+ @html_file = html.result
146
+ end
131
147
 
132
148
  protected
133
149
 
@@ -0,0 +1,192 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+
5
+ module WebifyRuby
6
+ # Public: You can set a custom HTML template by using this method.
7
+ def self.html_doc=(str)
8
+ @html_doc = str
9
+ end
10
+
11
+ # Public: You can get a current HTML template that is used by the module.
12
+ def self.html_doc
13
+ return @html_doc if @html_doc
14
+ @html_doc = WebifyRuby::html_doc_default
15
+ end
16
+
17
+ # Internal: HTML template that is used in in generated .html file by default.
18
+ html_doc_default = <<-HTML.gsub /^\s*/, ''
19
+ <!DOCTYPE html>
20
+ <html lang="en">
21
+ <head>
22
+ <meta charset="utf-8">
23
+ <title><%=@font_name%> - WebifyRuby</title>
24
+ <link rel="stylesheet" type="text/css" href="<%=@css_file%>">
25
+ <style>
26
+ ::-moz-selection {
27
+ background: #b3d4fc;
28
+ text-shadow: none;
29
+ }
30
+
31
+ ::selection {
32
+ background: #b3d4fc;
33
+ text-shadow: none;
34
+ }
35
+
36
+ html {
37
+ padding: 30px 10px;
38
+ font-size: 20px;
39
+ line-height: 1.4;
40
+ color: #737373;
41
+ -webkit-text-size-adjust: 100%;
42
+ -ms-text-size-adjust: 100%;
43
+
44
+ background-color: #fff;
45
+ background-image:
46
+ linear-gradient(90deg, transparent 79px, #737373 79px, #737373 81px, transparent 81px),
47
+ linear-gradient(#eee .1em, transparent .1em);
48
+ background-size: 100% 1.2em;
49
+
50
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
51
+ }
52
+
53
+ a:link,a:visited,a:hover,a:active {
54
+ color:inherit;
55
+ text-decoration:none;
56
+ }
57
+
58
+ body {
59
+ max-width: 750px;
60
+ _width: 750px;
61
+ padding: 30px 20px 50px;
62
+ margin: 0 auto;
63
+ }
64
+
65
+ h1 {
66
+ margin: 5px 10px;
67
+ font-size: 40px;
68
+ text-align: center;
69
+ }
70
+
71
+ h1 span {
72
+ color: #bbb;
73
+ }
74
+
75
+ h3 {
76
+ margin: 1.5em 0 0.5em;
77
+ }
78
+
79
+ p {
80
+ margin: 0.5em 0;
81
+ }
82
+
83
+ ul {
84
+ margin: 1em 0;
85
+ list-style:none;
86
+ font-family:<%=@font_name%>;
87
+ border:1px solid #ccc;
88
+ padding:15px;
89
+ background: #fff;
90
+ }
91
+
92
+ ul li {
93
+ display:inline-block;
94
+ height:50px;
95
+ width:50px;;
96
+ text-align:center;
97
+ line-height:50px;
98
+ margin:10px;
99
+ background: #fff;
100
+ }
101
+
102
+ .container {
103
+ max-width: 700px;
104
+ _width: 700px;
105
+ margin: 0 auto;
106
+ }
107
+
108
+ input::-moz-focus-inner {
109
+ padding: 0;
110
+ border: 0;
111
+ }
112
+ </style>
113
+ </head>
114
+ <body>
115
+ <a href="https://github.com/dachi-gh/webify_ruby"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://github-camo.global.ssl.fastly.net/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
116
+
117
+ <div class="container">
118
+ <h1><a href="https://github.com/dachi-gh/webify_ruby">WebifyRuby <span>Gem</span></a></h1>
119
+ <p>
120
+ <strong><%=Time.now%></strong>
121
+ </p>
122
+ <p>
123
+ <strong><%=@font_name%></strong>
124
+ </p>
125
+ <p>The result looks like this:</p>
126
+ <ul>
127
+ <%("a".."z").each do |l|%>
128
+ <li><%=l.upcase%> <%=l%></li>
129
+ <%end%>
130
+ </ul>
131
+ <p>
132
+ <small>Github page: <a href="https://github.com/dachi-gh/webify_ruby">https://github.com/dachi-gh/webify_ruby</a></small>
133
+ </p>
134
+ </div>
135
+ </body>
136
+ </html>
137
+ HTML
138
+
139
+ # Public: Html class of the module which is to generate code,
140
+ # and write to the specified directory's .html file.
141
+ class Html
142
+ # Public: Returns the String file for created css stylesheet.
143
+ attr_reader :css_file
144
+ # Internal: Returns the String name of the directory where .html file will exist.
145
+ attr_reader :html_dir
146
+ # Internal: Returns the String font name that was converted.
147
+ attr_reader :font_name
148
+ # Internal: Returns the String directory path where a .html.
149
+ attr_reader :html_file
150
+ # Internal: Returns the Fixnum length of a file.
151
+ attr_reader :output
152
+ # Internal: Returns the String representation of HTML file.
153
+ attr_reader :result
154
+
155
+ # Public: Initialize a HTML generation.
156
+ #
157
+ # css_file - A String filepath to the generated CSS.
158
+ # html_dir - A String path to the directory where file will be created.
159
+ #
160
+ # Returns the String HTML document code.
161
+ def initialize(css_file, html_dir)
162
+ @css_file = css_file
163
+ @html_dir = html_dir
164
+ @font_name = File.basename(@css_file, ".*")
165
+
166
+ make_html
167
+ write
168
+ end
169
+
170
+ # Internal: (Re-)Create a HTML file and write code there.
171
+ #
172
+ # Returns the HTML filepath just created.
173
+ def write
174
+ @dir = FileUtils.mkdir_p @html_dir unless File.directory? @html_dir
175
+ @html_file = File.join(@html_dir, @font_name + '.html')
176
+
177
+ File.delete(@html_file) if File.exist?(@html_file)
178
+ @output = File.open(@html_file, 'w') { |file| file.write(@result) }
179
+ @html_file
180
+ end
181
+
182
+ private
183
+
184
+ # Public: Use template to fill placeholders with relevant values.
185
+ #
186
+ # Returns the String containing a HTML document code.
187
+ def make_html
188
+ template = ERB.new WebifyRuby::html_doc
189
+ @result = template.result binding
190
+ end
191
+ end
192
+ end
@@ -1,4 +1,4 @@
1
1
  module WebifyRuby
2
2
  # Public: WebifyRuby version
3
- VERSION = "0.0.8"
3
+ VERSION = "0.1.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webify_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dachi Natsvlishvili
@@ -111,6 +111,7 @@ files:
111
111
  - lib/webify_ruby/convert.rb
112
112
  - lib/webify_ruby/css.rb
113
113
  - lib/webify_ruby/errors.rb
114
+ - lib/webify_ruby/html.rb
114
115
  - lib/webify_ruby/railtie.rb
115
116
  - lib/webify_ruby/tasks.rb
116
117
  - lib/webify_ruby/version.rb