I am building off of Ben's static site generator, and I wanted to DRY it up a bit.
One thing led to another and I built my own static site generator today
Ben Halpern ・ May 3 '20
I have a few methods:
prod_build = ARGV[0] = "production_build"
# Read files
def page_partials(new_page_partial)
pages = "site/#{page_partial}.html"
new_page_partial = File.open(pages).read
end
def script_partials(new_script_partial)
scripts = "site/#{script_partial}.js"
new_script_partial = File.open(scripts).read
end
def style_partial(new_style_partial)
styles = "site/#{style_partial}.css"
new_style_partial(styles).read
end
puts page_partials()
I'm not a Rubyist, though I've dabbled in it. I assume these methods are correct, considering:
build_string = base_html
# How do you use a block in a .gsub method???
.gsub("{{ head }}" {page_partials})
.gsub("{{ seo }}", seo_html)
.gsub("{{ main }}", main_css)
.gsub("{{ dev }}", dev_html)
I have a bunch of .gsub
methods that expect a file, will change the file name, and in the build string, will create the file.
What I want to know is, as a JavaScript dev, how to pass these methods as parameters to the .gsub
method in a block and if you can do this.
Shifting paradigms
I haven't looked at this code in a month as I was sick for that long. I have no idea what I was aiming for as such I am a little lost. JavaScript handles things much differently and I am trying to apply my js knowledge to Ruby and that seems to be a bad idea.
Thanks for helping, if you can.