Skip to content

Instantly share code, notes, and snippets.

@DanielEFrampton
Last active March 21, 2020 22:03
Show Gist options
  • Save DanielEFrampton/04752930f309fe7cef639021d7fab744 to your computer and use it in GitHub Desktop.
Save DanielEFrampton/04752930f309fe7cef639021d7fab744 to your computer and use it in GitHub Desktop.
Dev.to Data Flow and Files Notes

Dev.to Data Flow and Files Notes

General

  • The primary view template at app/views/layouts/application.html.erb loads:
    • app/assets/javascripts/application.js, which loads all JS files.
  • Instant Click loads data in the background when users mouse over links, using:
    • app/assets/javascripts/base.js.erb - calls various initializers
    • app/assets/javascripts/initializePage.js.erb calls all initializers related to page data
    • app/assets/javascripts/initializers/initializeBaseUserData.js - involved in prepping data for home page

Home page

  • config/routes.rb handles HTTP GET requests, and on line 415:
    • default '/' root URI routes to stories_controller#index, which is here:
      • app/controllers/stories_controller.rb, specifically the:
        • index action for main feed, which calls:
          • 'handle_base_index`, which renders:
            • articles/index view/template, which is located at:
              • app/views/articles/index.html.erb, which uses javascript_pack_tag to load Preact components:
                • app/javascript/packs/homePage.jsx, homePage component, which in turn imports:
                  • app/javascript/packs/homePageFeed.jsx which renders the articles.
              • app/views/articles/index.html.erb also renders these partials:
                • app/views/articles/_sidebar.html.erb, which in turn renders:
                  • app/views/articles/_sidebar_nav.html.erb, which contains the area we want to link to Collections.

Article Show Page

  • config/routes.rb handles HTTP GET request, and on line 403:
    • get "/:username/:slug/:view" => "stories#show" routes to:
      • app/controllers/stories_controller.rb, specifically the:
        • show action, which calls:
          • handle_article_show, which renders:
            • app/views/articles/show.html.erb, which has bulk of content and also renders:
              • app/views/articles/_actions.html.erb, which has the social media buttons.
          • the show action also declares an @article instance variable (passed to show.html.erb) which:
            • runs an ActiveRecord query against the Article model (app/models/article.rb):
              • Article.find_by(path: "/#{params[:username].downcase}/#{params[:slug]}")
                • it then calls .decorate on the found article object, which gives it methods from:
                  • app/decorators/article_decorator.rb, a "Decorator" file using the Draper gem/library.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment