Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Standard Way of Including Custom Tags in Rails Type Frameworks #22

Open
TheNotary opened this issue Feb 11, 2015 · 4 comments
Open

Standard Way of Including Custom Tags in Rails Type Frameworks #22

TheNotary opened this issue Feb 11, 2015 · 4 comments

Comments

@TheNotary
Copy link

I've been wondering what the best way is to use custom tags in a rails app. Would you expect the standard way to fork this repo, edit the tags in the fork, and then point bundler at the fork? I feel like that works, but it's a little external, so there's either an easier way to do it, or it might be worth spending a little time on.

I've been thinking of a gem ruby-bbcode-rails similar to the rspec-rails gem, which when installed in a rails app will automatically create a rails initializer called config/initializer/ruby-bbcode.rb containing the tags definition.

This could lead to something like rails g ruby-bbcode:full-tags which would override the default minimal tag set and use a larger tagset located in the ruby-bbcode-rails repository.

I don't want to tackle something that big at the moment (I've already spent a little more time today off task than I meant to, lol) and it definitely should be kept out of this repo given that it's framework specific, but what are your thoughts on custom tags?

@veger
Copy link
Owner

veger commented Feb 11, 2015

I have added this gem to my Gemlock file (either using rubygems and this repo works fine for me).
I do not need custom tags (yet), so I haven't tried to add them to my rails application.

I agree that Rails-specific code indeed should not be put in this repository to keep this repository rails-independent and usable for 'bare' ruby or other frameworks.

Application-wide

As you said, yo have new tags application-wide you could modify the @@tags Hash, using a (new) file in the 'config/initializers' directory (Rails 4+), or in config/application.rb (Rails 3).

I now notice that we might need to add a method to the module (lib/tags/tags.rb), to add tags to @@tags, as we cannot (easily) access the class variable in the module .

I do not know if this is 'complex' enough to add a generator for this.
Especially since it requires another gem to add this generator to your application, which is after using it once not required for the application anymore...?

Local

To add tags for a single controller, it is probably easiest to add the tag in the to_bbcode method that is called to convert the string (to HTML).
Although I wonder whether there are (much) situations where to add new tags to a single controller only...

Rails gem

Creating a rail gem is a nice idea.
Providing a set of custom tags is nice to get more tags available in the application. And acts as an example for users to see how to add their own tags.

On the other hand, how to decide what additional tags to provide? Just adding lots and lots of them only clutters the application, which is something no-one is waiting for. (Same problem as with this gem)
Maybe adding multiple sets, grouped by service/website/something-else, so users are able to pick one (or more) is an idea to solve this 'issue'? (and a full_tags to select all sets)

@TheNotary
Copy link
Author

"Maybe adding multiple sets, grouped by service/website/something-else, so users are able to pick one (or more) is an idea to solve this 'issue'? (and a full_tags to select all sets)"

That's sounds good, I was kind of thinking something like a "complete_tag_list" vs "minimal_tag_list" or something, but now I see how powerful groupings could be. I think discrete wordpress plugins are used to add support for specific bbcode. I don't follow wordpress closely, but we could mirror the groupings in a similar style:

Groups:
twitter (to render tweets, that's actually getting very popular on news sites)
soundcloud (to render audio)
complete (would include EVERY group)
base (would include the minimal tag set)
etc.

Before we/I look into the rails gem, we'll have to sort out how tags works. Would you like to do the tag groups in this gem? Possibly in the form:

lib/tags/tag_sets/base.rb
lib/tags/tag_sets/soundcloud.rb
lib/tags/tag_sets/twitter.rb
lib/tags/tag_sets/complete.rb

complete.rb could contain some code to look through the entire tags directory, and merge all the tags it can pull out of all the files into one big hash.

@TheNotary
Copy link
Author

This is kind of a sticky issue too, isn't it? I can't put the issue out of my head, I think maybe deciding on a good usage example is a good step one.

RubyBBCode::Tags.add_tag_set  RubyBBCode::ExtendedTagSets.twitter
RubyBBCode::Tags.add_tag_set  RubyBBCode::ExtendedTagSets.soundcloud
# or simply
RubyBBCode::Tags.tag_set  = RubyBBCode::ExtendedTagSets.full

So by calling that add-tag_set method, we could pass in additional tags. That looks pretty clean, right?

Then we'd need to decide if /lib/tags/ is the best folder for the ExtendedTagSet module. Theoretically, we could pull the extended tag set out into it's own repo. That would keep the clutter completely out of this repo. We could also set that repo as a dependency of this one, so users would be able to use it without having to add more gems to get access to it.

@veger
Copy link
Owner

veger commented Feb 12, 2015

Yes, I am warming up for the groups idea as well! :)

Adding the groups in this repository might be nice:

  • So not only the Rails users have access to these groups, but also other users.
  • By having groups, the base set of tags won't get cluttered (which is a 'must' for me).
    Using /lib/tags/ is a good location (as the name suggest, it once was intended for this)

Then we indeed need to think about a way of 'registering' tag groups (so users can even provide their own as well!). So something like add_tag_set might be good, or using an array(-like) interface so we simply add a set by '<<-ing' the set.

I think this new feature can become the 'main feature' for the release after the one containing my BBCodeErrorTemplate update! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants