Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request from Schneems rails tutorial #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion erb_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@

x = 42
template = ERB.new "The value of x is: <%= x %>"
puts template.result(binding)
puts template.result(binding)

# My Coding

name = "Richard Schneeman"
template1 = ERB.new "The Name of the Author is: <%= name %>"
puts template1.result(binding)

web_frameworks = ["rails", "django", "cakephp", "noir"]
template2 = ERB.new "The World Class frameworks are: <%= web_frameworks %>"
puts template2.result(binding)

26 changes: 26 additions & 0 deletions erb_example.rb~
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'erb'

x = 42
template = ERB.new "The value of x is: <%= x %>"
puts template.result(binding)

# My Coding

name = "Richard Schneeman"
template1 = ERB.new "The Name of the Author is: <%= name %>"
puts template1.result(binding)

web_frameworks = ["rails", "django", "cakephp", "noir"]
template2 = ERB.new "The World Class frameworks are: <%= web_frameworks %>"
puts template2.result(binding)

<ul>
<% ["rails", 'django', 'cakephp', 'noir'].each do |framework| %>
<li> People like <%= framework %></li>
<% end %>
</ul>





72 changes: 72 additions & 0 deletions page_generator.rb~
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'erb'


def process_erb(string)
template = ERB.new string
return template.result(binding)
end

## Define a function
# def add_thes_together(x,y)
# return x + y
# end

## Replace contents from a string
# str = "i rode a plane today"
# puts str.gsub('rode', 'bought')
# => "i bought a plane today"


## Remove contents from a string
# str = "i rode a plane today"
# puts str.gsub('today', '')
# => "i bought a plane"


## Turn a string into an array
# str = "tigers,lions,bears,ohmy"
# puts str.split(',')
# ["tigers", "lions", "bears", "ohmy"]

## Get the last element from an array
# arry = [1,2,3,4,5]
# puts arry.last
# => 5


## Read a file
# File.open('file_name', 'r').read

## Write a file
# File.open('file_name', 'w') do |f|
# f.write('new contents')
# end

## Iterate over all files in a directory matching a pattern
# Dir['views/*.html.erb'].each do |file|
# puts file`
# end
## Here the * character represents a wildcard

puts "================================================"
puts "=== Converting files in /views to html ========="
puts "================================================"
Dir['views/*.html.erb'].each do |file|
puts "- Reading #{file}"

content_string = File.open(file, 'r').read
file_name = file.split('/').last.gsub('html.erb', 'html')
output_file = "public/#{file_name}"

puts " - Converting .html.erb to html"
main_contents = process_erb(content_string)

puts " - Writing #{output_file}"
File.open(output_file, 'w') do |f|
f.write(main_contents)
end
end

puts "================================================"
puts "=== Done, open files in /public with browser ==="
puts "================================================"
51 changes: 51 additions & 0 deletions public/fmeg80126.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

<html>
<body>
<h1>You're using a layout</h1>
<p>
<h3>Ruby And Rails Tutorial</h3>
<p>This is Header</p>
<a href="http://www.google.com" target="_blank">Google</a>

</p>
<hr />
<div>
<h1>Thank you Richard Schneeman for Rails Tutorail</h1>
<h2>FMEG08126</h2>
<p>
<i>Now we will List some Web development Frameworks</i>
</p>


<ul type="1">

<h3><li> People like rails</li></h3>

<h3><li> People like django</li></h3>

<h3><li> People like noir</li></h3>

<h3><li> People like cakephp</li></h3>

<h3><li> People like express.js</li></h3>

<h3><li> People like cuba</li></h3>

</ul>


<h1>This Rails Tutorial Rocks</h1>


</div>
<hr />
<div>
<h3> I'm a footer</h3>
<p>This is Footer</p>

<a href='http://google.com'>This is a link to google</a><br>
<a href='http://yahoo.com'>This is a link to Yahoo</a>

</div>
</body>
</html>
29 changes: 27 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
<h1> Hello</h1>

<html>
<body>
<h1>You're using a layout</h1>
<p>
<h3>Ruby And Rails Tutorial</h3>
<p>This is Header</p>
<a href="http://www.google.com" target="_blank">Google</a>

</p>
<hr />
<div>
<h1> Hello World</h1>
<p>
The time is now:
2012-06-16 16:00:08 -0500
2012-09-17 23:22:41 +0530
</p>

<p>
My Name is:

</p>


</div>
<hr />
<div>
<h3> I'm a footer</h3>
<p>This is Footer</p>

<a href='http://google.com'>This is a link to google</a><br>
<a href='http://yahoo.com'>This is a link to Yahoo</a>

</div>
</body>
</html>
26 changes: 25 additions & 1 deletion public/me.html
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
foo

<html>
<body>
<h1>You're using a layout</h1>
<p>
<h3>Ruby And Rails Tutorial</h3>
<p>This is Header</p>
<a href="http://www.google.com" target="_blank">Google</a>

</p>
<hr />
<div>
foo
</div>
<hr />
<div>
<h3> I'm a footer</h3>
<p>This is Footer</p>

<a href='http://google.com'>This is a link to google</a><br>
<a href='http://yahoo.com'>This is a link to Yahoo</a>

</div>
</body>
</html>
Loading