<commit_before>require 'sinatra'
require 'roadie'
require 'action_view'
require 'sinatra/content_for'

IMAGE_CLASSES = 'image_link'

class NacedaEmailTemplateGenerator < Sinatra::Base

  get '/' do
    @files = Dir[File.dirname(__FILE__) + '/views/emails/*.erb'].map do |filename|
      filename.match(/.+\/([\w-]+)\.erb/)[1]
    end
    erb :home, layout: :'layouts/main'
  end

  get '/templates/:template' do
    @raw = CGI.escapeHTML emailify(params[:template])
    @preview_url = "/templates/#{params[:template]}/preview?#{URI.encode_www_form(params)}"
    erb :template, layout: :'layouts/main'
  end

  get '/templates/:template/preview' do
    emailify params[:template]
  end

  get '/form-news' do
    erb :'/forms/form-news', layout: :'layouts/main'
  end

  helpers ActionView::Helpers::AssetTagHelper
  helpers Sinatra::ContentFor
  helpers do

    def emailify template
      document = Roadie::Document.new(
        erb(:"emails/#{template}", layout: :'layouts/email')
          .gsub(/<!--\s*STRIP:.+?-->/, '')
      )
      document.asset_providers = [
        Roadie::FilesystemProvider.new(File.dirname(__FILE__) + '/public/')
      ]
      document.transform
    end

    def phone number
      %(
        <span class="mobile_link">#{number}</span>
      )
    end

    def image source, options
      if options[:class]
        options[:class] += IMAGE_CLASSES
      else
        options[:class] = IMAGE_CLASSES
      end
      image_tag source, options
    end

    def param_exists? parameter
      params[parameter] && !params[parameter].empty?
    end

    def textarea label, parameter
      %(
        <div class="column">
          <label for="#{parameter}">#{label}:</label>
          <br>
          <textarea name="#{parameter}"  rows="10">#{params[parameter]}</textarea>
        </div>
      )
    end

    def textbox label, parameter
      %(
        <div class="column">
          <label>#{label}:
            <input type="text" name="#{parameter}" value="#{params[parameter]}">
          </label>
        </div>
      )
    end

    def hr
      %(
        <table class="hr" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table><commit_msg>add placeholder text to textareas<commit_after>require 'sinatra'
require 'roadie'
require 'action_view'
require 'sinatra/content_for'

IMAGE_CLASSES = 'image_link'

class NacedaEmailTemplateGenerator < Sinatra::Base

  get '/' do
    @files = Dir[File.dirname(__FILE__) + '/views/emails/*.erb'].map do |filename|
      filename.match(/.+\/([\w-]+)\.erb/)[1]
    end
    erb :home, layout: :'layouts/main'
  end

  get '/templates/:template' do
    @raw = CGI.escapeHTML emailify(params[:template])
    @preview_url = "/templates/#{params[:template]}/preview?#{URI.encode_www_form(params)}"
    erb :template, layout: :'layouts/main'
  end

  get '/templates/:template/preview' do
    emailify params[:template]
  end

  get '/form-news' do
    erb :'/forms/form-news', layout: :'layouts/main'
  end

  helpers ActionView::Helpers::AssetTagHelper
  helpers Sinatra::ContentFor
  helpers do

    def emailify template
      document = Roadie::Document.new(
        erb(:"emails/#{template}", layout: :'layouts/email')
          .gsub(/<!--\s*STRIP:.+?-->/, '')
      )
      document.asset_providers = [
        Roadie::FilesystemProvider.new(File.dirname(__FILE__) + '/public/')
      ]
      document.transform
    end

    def phone number
      %(
        <span class="mobile_link">#{number}</span>
      )
    end

    def image source, options
      if options[:class]
        options[:class] += IMAGE_CLASSES
      else
        options[:class] = IMAGE_CLASSES
      end
      image_tag source, options
    end

    def param_exists? parameter
      params[parameter] && !params[parameter].empty?
    end

    def textarea label, parameter
      placeholder =
%(<h3>Headline</h3>
<p>This is a paragraph that includes <a href='http://url.com'>a link</a> and <strong>bold text</strong>.</p>
<hr>
<ul>
  <li>This is</li>
  <li>a bulleted list</li>
</ul>
      )
      %(
        <div class="column">
          <label for="#{parameter}">#{label}:</label>
          <br>
          <textarea name="#{parameter}" rows="10" placeholder="#{placeholder}">#{params[parameter]}</textarea>
        </div>
      )
    end

    def textbox label, parameter
      %(
        <div class="column">
          <label>#{label}:
            <input type="text" name="#{parameter}" value="#{params[parameter]}">
          </label>
        </div>
      )
    end

    def hr
      %(
        <table class="hr" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table>
{'fraction_non_alphanumeric': 0.16066540324278797, 'fraction_numerical': 0.0029479890503263844, 'mean_word_length': 2.5081240768094535, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6209295', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1510, 'n_words': 308}