Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 10th, 2012, 02:44 AM
bmson bmson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 1 bmson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 52 sec
Reputation Power: 0
Shell - Makefile that user cat to load html and sed to replace

Hi,

Long time lurker but first time poster. I have a Makefile question and wasn't sure where to post the question but so I hope I picked the right category.

I'm working with backbone templates and have split my html in multiple files.
The index files includes this {template} text. I'm planing to use tha Makefile to load the text from multiple HTML files and replace the {template} variable with the content from those files.

My HTML files looks like this:

file.html
<div>
<a href='#'>my link</a>
</div>

index.html
<body>
{template}
</body>


Then I have a makefile that looks like such:

Makefile
include:
$(eval data := $(shell cat "file.html"))
sed -i '' 's/$({template})/$(data)/' index.html


The sed code works lika a charm and it replaces it with the data value if I force it to have text, but the cat breaks and gives me an 'Error 1'


I've tried both...
$(eval data := $(shell grep -nr file.html))
$(eval data := $(shell cat "file.html"))

They both fail when they reach <, >, ", ' or #.
I've not yet figured out how to load the html data into the variable.

So I'm looking for guidance from you guys and girl.

Reply With Quote
  #2  
Old October 10th, 2012, 07:31 AM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2007
Posts: 737 OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 42 m 14 sec
Reputation Power: 928
First off, please surround code with [code]...[/code] tags. This preserves formatting (which is especially important for makefiles where whitespace is significant).


There are several problems here:
  • $(xxx yyy) runs the command "xxx yyy" so unless you have an executable on your path named "shell", $(shell cat file) is going to fail. You probably meant $(cat file).
  • Each line of a makefile runs within its own shell. Variables set in one line won't be present in the next line. You need to combine the lines to do this by using shell commands like ; or && to join commands, or eliminate the need for the preceding line by interpolating the file directly into the sed command.
  • But even if you do all that, your sed command is going to turn into s/{template}/...</div>/ and it's going to choke.


You'll have an easier time if you use existing template software for this. Here's a quick example of how it would look using Template Toolkit. (And there are many many choices for templating software out there if you need something different.)

Code:
F:\temp>cat file.tt
<div>
<a href='#'>my link</a>
</div>

F:\temp>cat index.tt
<body>
[% INCLUDE file.tt %]
</body>


F:\temp>cat makefile
index.html: index.tt file.tt
        tt-render index.tt > index.html

F:\temp>dmake index.html
tt-render index.tt > index.html

F:\temp>cat index.html
<body>
<div>
<a href='#'>my link</a>
</div>

</body>
__________________
sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Shell - Makefile that user cat to load html and sed to replace

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap