Dynamic Goodreads SASS formatting

Summary

Putting up some code that might be useful to others when formatting Goodreads widgets using dynamic class creation in SASS.

Over at my reading list and book mini-reviews page, I've re-formatted the Goodreads widgets to save space and look a bit nicer. Originally was editing a bunch of CSS, but like other parts of the site, decided to migrate it over the SCSS. Below is the resulting code that allows me to compactly define the CSS stylesheet for all the different widgets. Since Goodreads javascript dynamically calls the html, I can't control the naming of the classes but they are similar across widgets that I can use @each loops, @extends (to define the actually styles) and lists to dynamically create all the CSS needed for that page. I used @extends instead of @include in this case because didn't need dynamic variables input to mixins and currently @include doesn't work with dynamic variables. The % signs are just placeholder selectors used in lieu of . and # normally seen with classes and ids.

See below for the code, useful either as a template for modifying your own SCSS or just as an example for nested @each loops in SCSS and combining them with @extends to dynamically define a group of classes easily.


download goodreads.scss

CSS
  1. /*======================================*/
  2. /*Dynamically create Goodreads classes*/
  3. $container-list: 1406083933 1421607017 1402318543 1402387978;
  4. $tag-list: "gr_custom_container" "gr_custom_header" "gr_custom_each_container" "gr_custom_book_container" "gr_custom_author" "gr_custom_tags" "gr_custom_rating";
  5. @each $container in $container-list {
  6.     @each $tag in $tag-list {
  7.       .#{$tag}_#{$container} {
  8.         @extend %#{$tag};
  9.       }
  10.     }
  11. }
  12. /*Modify images to make them standard across classes*/
  13. $container-list: 1406083933 1421607017 1402318543 1402387978;
  14. $tag-list: "gr_custom_book_container";
  15. @each $container in $container-list {
  16.     @each $tag in $tag-list {
  17.       .#{$tag}_#{$container} img{
  18.         width:100%;
  19.       }
  20.     }
  21. }
  22. /*======================================*/
  23. /*Placeholder selectors for later use with @extends*/
  24. %gr_custom_container{
  25.   /* customize your Goodreads widget container here*/
  26.   padding: 10px 5px 10px 5px;
  27.   background-color: transparent;
  28.   color: #000000;
  29.   width: 100%;
  30.   -webkit-column-count: 3; /* Chrome, Safari, Opera */
  31.       -moz-column-count: 3; /* Firefox */
  32.       column-count: 3;
  33.   @media only screen and (max-width : 1000px){
  34.     -webkit-column-count: 1; /* Chrome, Safari, Opera */
  35.         -moz-column-count: 1; /* Firefox */
  36.         column-count: 1;
  37.   }
  38. }
  39. %gr_custom_header{
  40.   /* customize your Goodreads header here*/
  41.   border-bottom: 1px solid gray;
  42.   width: 100%;
  43.   margin-bottom: 5px;
  44.   text-align: center;
  45.   font-size: 120%;
  46.   display:none;
  47. }
  48. %gr_custom_each_container{
  49.   /* customize each individual book container here */
  50.   width: 95%;
  51.   display: inline-table;
  52.   clear: both;
  53.   margin-bottom: 19px;
  54.   overflow: auto;
  55.   padding-bottom: 4px;
  56.   /*border-bottom: 5px solid #aaa;*/
  57.   border: 1px solid #aaa;
  58.   background-color: rgb(242,242,242);
  59.   @media only screen and (max-width : 1000px){
  60.     width: 100%;
  61.   }
  62. }
  63. %gr_custom_book_container{
  64.   /* customize your book covers here */
  65.   overflow: hidden;
  66.   height: 160px;
  67.     float: left;
  68.     margin-right: 4px;
  69.     width: 98px;
  70.     float:left;
  71. }
  72. %gr_custom_author{
  73.   /* customize your author names here */
  74.   font-size: 10px;
  75. }
  76. %gr_custom_tags{
  77.   /* customize your tags here */
  78.   font-size: 10px;
  79.   color: gray;
  80.   display:inline;
  81.   display:none;
  82. }
  83. %gr_custom_rating{
  84.   /* customize your rating stars here */
  85.   /*float: right;*/
  86.   /*display:inline;*/
  87. }
  88. %gr_custom_review{
  89.   display:inline;
  90. }
  91.  

-biafra
bahanonu [at] alum.mit.edu

other entires to explore:

facebook crawler and youtube api: part 1
07 october 2012 | programming

Created a small app, implemented in python and PHP, that crawls authenticated Facebook page for Youtube videos and adds them to a specified[...] user's Youtube playlist. Useful for groups that post a lot of youtube videos and want a centralized playlist to share with others. I'll go over some of the implementation details in this post.

why you should watch black mirror
29 november 2015 | television

Black Mirror is a unique and ever timely experience. The vignettes are spot on and while each explores a different aspect of our interactio[...]n with technology, the internet, and social media, there is an underlying dystopian view of the world that unifies the whole series. Watch it.

Cheyne-Stoke Respiration
12 April 2013 | designs

One can create art with data, many have proven that with beautiful infographics or dazzling company reports. I thought using R[...]ong> to create an artistic rendering of a normally mundane process would be neat. I created a graphic based on Cheyne-Stokes respiration with the help of ggplot package. I think the resulting work has a sci-fi feel to it, almost like it could be a symbol for a corporation should the sinusoidal lobes be made solid.

Note: The black line is the breathing rate while the red and blue interlocking lines signify aponea and hyperponea, respectively.

archive everything!
01 october 2012 | notes

Archived everything in my inbox. It's awesome. Continues my general trend of simplifying. Logging off websites, only checking the news for [...]brief periods, and focusing on a core set of hobbies. Eliminating distractions and reducing information overload are doing wonders to fight off stress and keep me humming along.

©2006-2025 | Site created & coded by Biafra Ahanonu | Updated 21 October 2024
biafra ahanonu