How my team wrote 12 Cloudflare apps with fewer than 20 lines of code

Cloudflare Railgun is available when using Cloud Server Webuzo, Cloud Web Apps. Contact us to find out our latest offers!

Instead, we built a single integration template. Then, we wrote a few lines of code to automatically generate 12 apps in about as long as it takes to enjoy a sumptuous sip of California Cab. Ready for a quick overview? Begin swirling…

First we defined a “replacements” object with the important attributes of each app (which is already available in our database in an AppDetail model):

replacements = {
    APP_COMMON_NAME: app_detail.common_name, #eg “Form Builder”
    APP_SLUG: app_detail.slug, #e.g. “form-builder”
    APP_DESCRIPTION: app_detail.short_description #e.g. “Increase conversions and get more sign-ups.”
    …
}

Using these replacements, we then duplicated and renamed each file of our Cloudflare App accordingly:

replacements.each do |key, val|
  `find #{parent_dir} -name "*#{key}*" -exec rename 's/#{key}/#{val}/' * -v {} +`
end

And finally, we moved into each file and made the corresponding replacements:

Dir.glob("lib/cloudflare/powr-#{replacements[:APP_SLUG]}/**/*").reject{|fn| File.directory?(fn)}.each do |file_name|
  text = File.read(file_name)
  replacements.each do |key, val|
    text = text.gsub(key.to_s, val)
   end
   File.open(file_name, "w") {|file| file.puts text }
end

Delicious, right?

At this point, you may be wondering, “what are POWr Apps, anyway?” I’m glad you asked. They are a customizable and easy-to-use set of tools to supercharge any website… from forms to galleries to social media integrations to eCommerce.

Could you build a custom form for your website, a backend to handle and graph responses, and an integration with Zapier to turn on a lightbulb every time someone presses submit? Probably. Is that a good use of your time? Probably not. Instead, you can install POWr Form Builder in about 2 minutes, pass it off to your Marketing Intern to make it look pretty, and get back to the hard problems.

Adding POWr Form Builder to Cloudflare

Customize your app in the POWr Editor

If YOU want to be a Scaled Engineer, it’s not about knowing everything there is to know. The geekiest engineers that spend their lunches vehemently discussing the pros and cons of bubble vs selection sort often do not make the best Scaled Engineers. Scaled Engineers know when to avoid going down Rabbit Holes and use whatever tools are at their disposal to maximize impact.

So if you want to add some dynamic content to your site, take a look at POWr Apps for Cloudflare. I’d tell you that again, but I don’t want to repeat myself.

Cloudflare Railgun is available when using Cloud Server Webuzo, Cloud Web Apps. Contact us to find out our latest offers!

Comments are closed.