5 Replies - 6607 Views - Last Post: 09 July 2012 - 07:08 PM Rate Topic: -----

#1 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

phpBB syntax [img] [etc...] in RoR app?

Posted 30 June 2012 - 11:10 AM

Hey, I'm about to implement a small blogging function in an existing app, and I was wondering if there were any gems out there that would let me use the syntax we use to make our posts. Also, I'm still a little foggy on how rails specific gems work so if it turns out it's something I have to implement on my own, what are some good ways to turn it into a gem that handles the translation of the users source text into the html code?
Is This A Good Question/Topic? 0
  • +

Replies To: phpBB syntax [img] [etc...] in RoR app?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,203
  • Joined: 21-June 11

Re: phpBB syntax [img] [etc...] in RoR app?

Posted 30 June 2012 - 12:17 PM

View PostNotarySojac, on 30 June 2012 - 08:10 PM, said:

Hey, I'm about to implement a small blogging function in an existing app, and I was wondering if there were any gems out there that would let me use the syntax we use to make our posts.


The markup syntax used by phpBB and most other forum softwares is called bbcode. According to a quick gem search, there seem to be a number of bbcode gems for ruby. Of those rbbcode and ruby-bbcode look the most promising at a quick glance.

Quote

Also, I'm still a little foggy on how rails specific gems work


Why would/should the gem be specific to rails?


Quote

if it turns out it's something I have to implement on my own, what are some good ways to turn it into a gem that handles the translation of the users source text into the html code?


I'm not sure what you're asking here. You'd write a module that contains a method that takes a bb-encoded string and returns an HTML-encoded string. You'd then put that module into a gem and call the method from inside your rails project. (Sorry if I missed your point - as I said I didn't really understand the question).

This post has been edited by sepp2k: 30 June 2012 - 12:30 PM

Was This Post Helpful? 2
  • +
  • -

#3 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: phpBB syntax [img] [etc...] in RoR app?

Posted 30 June 2012 - 01:13 PM

View Postsepp2k, on 30 June 2012 - 12:17 PM, said:

Quote

Also, I'm still a little foggy on how rails specific gems work


Why would/should the gem be specific to rails?


Quote

if it turns out it's something I have to implement on my own, what are some good ways to turn it into a gem that handles the translation of the users source text into the html code?


I'm not sure what you're asking here. You'd write a module that contains a method that takes a bb-encoded string and returns an HTML-encoded string. You'd then put that module into a gem and call the method from inside your rails project. (Sorry if I missed your point - as I said I didn't really understand the question).


Oh, that's a good point. I suppose the only gems I have experience with are like pageination where they feel closely tied to the active record stuff in rails, but now that you mention it, the gem is as simple as taking in a chunk of text and returning another chunk.

Thanks for the info, I check out those two gems and see how things go.
Was This Post Helpful? 0
  • +
  • -

#4 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1359
  • View blog
  • Posts: 3,425
  • Joined: 28-November 09

Re: phpBB syntax [img] [etc...] in RoR app?

Posted 09 July 2012 - 06:52 PM

Either go the gem, or just whip out some simple gsub to make your own versions and whatnot. It's always fun to reinvent the wheel, if but once, just to see how the thing works. Best to do it with the easy wheels, that way when something hard comes along it's not such an insane jump.
Was This Post Helpful? 0
  • +
  • -

#5 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,203
  • Joined: 21-June 11

Re: phpBB syntax [img] [etc...] in RoR app?

Posted 09 July 2012 - 07:02 PM

View PostLemur, on 10 July 2012 - 03:52 AM, said:

or just whip out some simple gsub to make your own versions and whatnot.


No, don't. Any simple solution that only uses gsub and regular expressions will almost certainly break on nested tags and/or not handle tags withing code-tags correctly.

Any regular expression-based solution¹ that actually works will have a huge readability problem and only work on ruby 1.9 (though that's not so much of a problem anymore these days) since ruby 1.8 didn't have recursive regular expressions.

¹ Note that when I say "regular expression-based solution" I mean a solution that relies solely on regular expressions (combined with a method like gsub). It's perfectly fine to use regular expressions to find all tags in the text and then use manual logic to find out which opening tag corresponds to which closing tag.

This post has been edited by sepp2k: 10 July 2012 - 05:28 AM

Was This Post Helpful? 0
  • +
  • -

#6 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1359
  • View blog
  • Posts: 3,425
  • Joined: 28-November 09

Re: phpBB syntax [img] [etc...] in RoR app?

Posted 09 July 2012 - 07:08 PM

Perhaps a tad unclear on that note.

If that's the case, then on for clearing up a bit. It would more requite a queue based system to recursively hunt for matching tags, but that's being rather broad about it. I'm merely stating an idea for a potentially interesting project to try out to expand knowledge.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1