Module: QRHTMLLayout
- Defined in:
- lib/qr-bills/qr-html-layout.rb
Class Method Summary collapse
- .convert_qrcode_to_data_url(qrcode) ⇒ Object
- .create(params) ⇒ Object
- .html_layout(params) ⇒ Object
- .render_address(address) ⇒ Object
Class Method Details
.convert_qrcode_to_data_url(qrcode) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/qr-bills/qr-html-layout.rb', line 10 def self.convert_qrcode_to_data_url(qrcode) case qrcode when ChunkyPNG::Image qrcode.to_data_url else # Stolen from sprockets # https://github.com/rails/sprockets/blob/0f3e0e93dabafa8f3027e8036e40fd08902688c8/lib/sprockets/context.rb#L295-L303 data = CGI.escape(qrcode) data.gsub!('%3D', '=') data.gsub!('%3A', ':') data.gsub!('%2F', '/') data.gsub!('%27', "'") data.tr!('+', ' ') "data:image/svg+xml;charset=utf-8,#{data}" end end |
.create(params) ⇒ Object
4 5 6 7 8 |
# File 'lib/qr-bills/qr-html-layout.rb', line 4 def self.create(params) qrcode = QRGenerator.create(params, params[:qrcode_filepath]) params[:qrcode_filepath] = convert_qrcode_to_data_url(qrcode) html_layout(params) end |
.html_layout(params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/qr-bills/qr-html-layout.rb', line 28 def self.html_layout(params) I18n.with_locale(params[:bill_params][:language]) do layout = "<div class=\"bill_container\">\n" layout += " <div class=\"receipt_section\">\n" layout += " <div class=\"title\">#{I18n.t("qrbills.receipt").capitalize}</div>\n" layout += " <div class=\"subtitle payable_to\">#{I18n.t("qrbills.account").capitalize} / #{I18n.t("qrbills.payable_to").capitalize}</div>\n" layout += " <div class=\"qrcontent\">\n" layout += " #{params[:bill_params][:creditor][:iban]}<br/>\n" layout += render_address(params[:bill_params][:creditor][:address]) layout += " </div>\n" layout += " <div><br/></div>\n" if !params[:bill_params][:reference].nil? && !params[:bill_params][:reference].empty? layout += " <div class=\"subtitle reference\">#{I18n.t("qrbills.reference").capitalize}</div>\n" layout += " <div class=\"reference\">\n" layout += " #{params[:bill_params][:reference]}<br/>\n" layout += " </div>\n" layout += " <div><br/></div>\n" end layout += " <div class=\"subtitle payable_by\">#{I18n.t("qrbills.payable_by").capitalize}</div>\n" layout += " <div class=\"payable_by\">\n" layout += render_address(params[:bill_params][:debtor][:address]) layout += " </div>\n" layout += " <div class=\"amount\">\n" layout += " <div class=\"currency\">\n" layout += " <span class=\"amount_header subtitle\">#{I18n.t("qrbills.currency").capitalize}</span><br/>\n" layout += " #{params[:bill_params][:currency]}<br/>\n" layout += " </div>\n" layout += " <div class=\"amount_value\">\n" layout += " <span class=\"amount_header subtitle\">#{I18n.t("qrbills.amount").capitalize}</span><br/>\n" layout += " #{format('%.2f', params[:bill_params][:amount])}<br/>\n" layout += " </div>\n" layout += " </div>\n" layout += " <div class=\"acceptance_point\">\n" layout += " #{I18n.t("qrbills.acceptance_point").capitalize}<br/>\n" layout += " </div>\n" layout += " </div>\n" layout += " <div class=\"payment_section\">\n" layout += " <div class=\"left_column\">\n" layout += " <div class=\"title\">#{I18n.t("qrbills.payment_part").capitalize}</div>\n" layout += " <div class=\"qr_code\"><img src=\"#{params[:qrcode_filepath]}\" /></div>\n" layout += " <div class=\"amount\">\n" layout += " <div class=\"currency\">\n" layout += " <span class=\"amount_header subtitle\">#{I18n.t("qrbills.currency").capitalize}</span><br/>\n" layout += " #{params[:bill_params][:currency]}<br/>\n" layout += " </div>\n" layout += " <div class=\"amount_value\">\n" layout += " <span class=\"amount_header subtitle\">#{I18n.t("qrbills.amount").capitalize}</span><br/>\n" layout += " #{format('%.2f',params[:bill_params][:amount])}<br/>\n" layout += " </div>\n" layout += " </div>\n" layout += " <div class=\"further_information\">\n" if !params[:bill_params][:bill_information_coded].nil? && !params[:bill_params][:bill_information_coded].empty? layout += " <span class=\"finfo_header\">#{I18n.t("qrbills.name").capitalize} AV1:</span> #{params[:bill_params][:bill_information_coded]}\n" end if !params[:bill_params][:alternative_scheme_parameters].nil? && !params[:bill_params][:alternative_scheme_parameters].empty? layout += " <span class=\"finfo_header\">#{I18n.t("qrbills.name").capitalize} AV2:</span> #{params[:bill_params][:alternative_scheme_parameters]}\n" end layout += " </div>\n" layout += " </div>\n" layout += " <div class=\"right_column\">\n" layout += " <div class=\"subtitle payable_to\">#{I18n.t("qrbills.account").capitalize} / #{I18n.t("qrbills.payable_to").capitalize}</div>\n" layout += " <div class=\"qrcontent\">\n" layout += " #{params[:bill_params][:creditor][:iban]}<br/>\n" layout += render_address(params[:bill_params][:creditor][:address]) layout += " </div>\n" layout += " <div><br/></div>\n" if !params[:bill_params][:reference].nil? && !params[:bill_params][:reference].empty? layout += " <div class=\"subtitle reference\">#{I18n.t("qrbills.reference").capitalize}</div>\n" layout += " <div class=\"reference\">\n" layout += " #{params[:bill_params][:reference]}<br/>\n" layout += " </div>\n" layout += " <div><br/></div>\n" end if !params[:bill_params][:additionally_information].nil? && !params[:bill_params][:additionally_information].empty? layout += " <div class=\"subtitle additional_information\">#{I18n.t("qrbills.additional_information").capitalize}</div>\n" layout += " <div class=\"additional_information\">\n" layout += " #{params[:bill_params][:additionally_information]}<br/>\n" layout += " </div>\n" layout += " <div><br/></div>\n" end layout += " <div class=\"subtitle payable_by\">#{I18n.t("qrbills.payable_by").capitalize}</div>\n" layout += " <div class=\"payable_by\">\n" layout += render_address(params[:bill_params][:debtor][:address]) layout += " </div>\n" layout += " </div>\n" layout += " </div>\n" layout += "</div>\n" layout += "<style>\n" layout += " @font-face{ \n" layout += " font-family: \"liberation_sansregular\";\n" layout += " src: url(\"#{params[:fonts][:eot]}\");\n" layout += " src: url(\"#{params[:fonts][:eot]}?#iefix\") format(\"embedded-opentype\"),\n" layout += " url(\"#{params[:fonts][:woff]}\") format(\"woff\"),\n" layout += " url(\"#{params[:fonts][:ttf]}\") format(\"truetype\"),\n" layout += " url(\"#{params[:fonts][:svg]}#liberation_sansregular\") format(\"svg\");\n" layout += " font-weight: normal;\n" layout += " font-style: normal;\n" layout += " }\n" layout += " .bill_container {\n" layout += " width: 210mm;\n" layout += " height: 105mm;\n" layout += " font-family: \"liberation_sansregular\";\n" layout += " border: 1px solid #ccc;\n" layout += " }\n" layout += " .bill_container:after {\n" layout += " content: \"\";\n" layout += " display: table;\n" layout += " clear: both;\n" layout += " }\n" layout += " .receipt_section {\n" layout += " width: 52mm;\n" layout += " height: 95mm;\n" layout += " padding: 5mm;\n" layout += " float: left;\n" layout += " font-size: 8pt;\n" layout += " border-right: 1px dotted #ccc;\n" layout += " }\n" layout += " .payment_section {\n" layout += " width: 137mm;\n" layout += " height: 95mm;\n" layout += " float: left;\n" layout += " padding: 5mm;\n" layout += " font-size: 10pt;\n" layout += " }\n" layout += " .payment_section .left_column {\n" layout += " height: 95mm;\n" layout += " width: 46mm;\n" layout += " float: left;\n" layout += " margin-right: 5mm;\n" layout += " }\n" layout += " .payment_section .right_column {\n" layout += " height: 95mm;\n" layout += " width: 86mm;\n" layout += " float: left;\n" layout += " }\n" layout += " .qr_code {\n" layout += " padding: 5mm 0mm 5mm 0mm;\n" layout += " height: 46mm;\n" layout += " width: 46mm;\n" layout += " }\n" layout += " .qr_code img {\n" layout += " height: 46mm;\n" layout += " width: 46mm;\n" layout += " }\n" layout += " .amount {\n" layout += " margin-top: 15px;\n" layout += " }\n" layout += " .amount .currency {\n" layout += " float: left;\n" layout += " margin-right: 15px;\n" layout += " }\n" layout += " .title {\n" layout += " font-weight: bold;\n" layout += " font-size: 11pt;\n" layout += " }\n" layout += " .receipt_section .subtitle {\n" layout += " font-weight: bold;\n" layout += " font-size: 6pt;\n" layout += " line-height: 9pt;\n" layout += " }\n" layout += " .receipt_section .acceptance_point {\n" layout += " font-weight: bold;\n" layout += " text-align: right;\n" layout += " font-size: 6pt;\n" layout += " line-height: 8pt;\n" layout += " padding-top: 5mm;\n" layout += " }\n" layout += " .payment_section .subtitle {\n" layout += " font-weight: bold;\n" layout += " font-size: 8pt;\n" layout += " line-height: 11pt;\n" layout += " }\n" layout += " .payment_section .amount {\n" layout += " height: 22mm;\n" layout += " margin-top: 40px;\n" layout += " }\n" layout += " .payment_section .further_information {\n" layout += " font-size: 7pt;\n" layout += " }\n" layout += " .payment_section .finfo_header {\n" layout += " font-weight: bold;\n" layout += " } \n" layout += "</style>\n" layout end end |
.render_address(address) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/qr-bills/qr-html-layout.rb', line 248 def self.render_address(address) case address[:type] when 'S' if address[:street_name].empty? format("%s<br>\n%s %s<br>\n", address[:name], address[:postal_code], address[:town]) else format("%s<br>\n%s %s<br>\n%s %s<br>\n", address[:name], address[:street_name], address[:building_number], address[:postal_code], address[:town]) end when 'K' raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: please move to type-S addresses, K-type is not supported anymore with and after v2.0.0 - params line1 and line2 doesn't exist anymore and are now street_name / building_number" end end |