Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Provide a comprehensive list of tags somewhere on the docs #63

Closed
miketheman opened this issue Aug 29, 2012 · 6 comments
Closed

Provide a comprehensive list of tags somewhere on the docs #63

miketheman opened this issue Aug 29, 2012 · 6 comments

Comments

@miketheman
Copy link
Contributor

There's a bunch of potential tags, and when looking at a given rule, once can see the tags for a given rule.

There's no 'listing' of what tags there are, so here's a wonderful one-liner that does this.

$ grep --color=none tags lib/foodcritic/rules.rb | awk '{sub(/^[ \t]+tags[ \t]\%w\{/,"");sub(/\}$/,"");gsub(" ","\n");print}' | sort | uniq
annoyances
attributes
correctness
definitions
deprecated
files
libraries
lwrp
metadata
notifications
portability
readme
search
services
solo
strings
style

Add a -c to uniq to see that there are 17 correctness rules and 14 style rules.

@acrmp
Copy link
Member

acrmp commented Aug 29, 2012

Thanks Mike. The tags are available in the YAML Front Matter against each rule so in theory (aside from Liquid limitations) this shouldn't be too hard to add to the docs.

I think there's a separate feature to be able to see from the command line the effective set of rules that would be applied given tag expressions and included rules.

@miketheman
Copy link
Contributor Author

Challenge accepted.

Here's the same, in ruby.

require 'open-uri'
require 'yaml'
input = YAML.load(open('https://raw.github.com/acrmp/foodcritic/gh-pages/index.html') {|f| f.read })
tags = Array.new
input['rules'].each do |rule|
  tags << rule['tags']
end
puts tags.flatten.uniq.sort

Output is the same list.

@acrmp
Copy link
Member

acrmp commented Aug 29, 2012

Hi Mike,

Thanks. My response probably should have included some more detail though. The foodcritic docs are hosted on GitHub pages and use Jekyll.

The rule data expressed in the YAML Front Matter is rendered by Liquid templates. Here's an example of the template that renders the rules section of the docs.

Using Liquid if we can would be the first preference, in order to make use of the same data and templating mechanism.

Cheers,

Andrew.

@miketheman
Copy link
Contributor Author

Hey Andrew,

I took a stab at it, and now hate Liquid. :) It's not the best documented thing int he world, and accessing data from it is somewhat restricted, and the data returned very String-y.

Here's a snippet I tried, and since there's no uniq in Liquid, I decided I'm done struggling with the template language that fights back.

### What tags are used?

Here's a listing of tags that are used in the rules:

{% capture rule_tags %}
{% for rule in page.rules %}
{% for tag in rule.tags %}
{{ tag }}
{% endfor %}
{% endfor %}
{% endcapture %}
{% capture num_words %}
{{ rule_tags | split:' ' | sort | join:' ' | number_of_words }}
{% endcapture %}
{% for item in (1..num_words) %}
{% capture this_word %}
{{ rule_tags | split:' ' | sort | join:' ' | truncatewords:item | remove:'...' | split:' ' | last }}
{% endcapture %}
* {{ this_word | markdownify }}
{% endfor %}

Sorting an array exists, but getting the data from the YAML, back to an array vs a string format, and then sorting it, the whole thing seems very unwieldy.

I experimented briefly with the plugin system, and could not figure out how to:

a) use the tagging system with a "non-array" structure like this tag list. Even if a tag works, there's still the issue of uniqness
b) create a generator that is pure ruby to create the list of tags from the data, and put that somewhere. This didn't make much sense either, since the generator code is expecting syntax for Pages, Posts, etc, not "rules" - so accessing that data, and figuring out how to generate data into another page seemed unwieldy as well.

Anyways, I hope you have more luck than I, and I'd be curious to see how this gets solved.

acrmp pushed a commit to Foodcritic/foodcritic-site that referenced this issue Aug 1, 2013
@acrmp
Copy link
Member

acrmp commented Aug 1, 2013

Hi Mike,

I'm currently refreshing the docs and have added a list of rules by tag here:
http://foodcritic.io/#tag-reference

The new docs are in the foodcritic-site repository.

Cheers,

Andrew.

@miketheman
Copy link
Contributor Author

Hi Andrew,

Looks awesome, thanks for following up!

I looked at the code, and I think this helper method isn't explicity always going to work.

I'll open a ticket on that repo, and I think this one is good to close out.

Thanks!
-Mike

@acrmp acrmp closed this as completed Aug 2, 2013
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