Alternatywne rozwiazanie problemu

Natknalem sie na tak oto zdefiniowany problem.

The goal of this project is to make a request at this URL and have it show a completed proposal:
http://localhost:3000/proposal_viewer/show/1

Once the user accesses the above URL an HTML template found in the public directory will be retrieved and
populated with data from several models.
For the purposes of this example,
assume that the HTML template is user generated and stored in this public directory.

This means that the HTML file must be left exactly as is and cannot be modified or have <%=%> tags within.

Important:

  1. You cannot add any files to the folder containing the index.html
  2. You cannot modify any of the files in the folder containing the index.html

Fragment pliku z szablonem:

{client_name}

{proposal_name}

Zastanawiam sie czy przychodzi Wam do glowy rozwiazanie inne niz:

  • wez plik z templatem
  • otworz go w jakims jQuery po stronie serwera (Nokogiri etc.)
  • podstaw zmienne/wartosci w templacie
  • zwroc jako html

Pozdro, dzieki

Zobacz sobie jak to jest rozwiązane w innych systemach szablonów jak: Handlebars (czysty, prosty kod), ew. liquid.

Generalnie w prostych przykładach możesz przelatywać regexpem i wypełniać odpowiednie pola po prostu.

zdecydowanie polecam liquida, można nim wczytywać template’y w postaci tekstu i “kompilować” z podanymi zmiennymi.

+1 dla liquid

Hej, dzieki za pomoc.
powiazany case: Crafting Rails Applications, Jose Valim: Retrieving View Templates from Custom Stores