Code Monkey home page Code Monkey logo

ava-pattern's Introduction

README

This document is not yet complete. It's a draft and it's under heavy development. To help, please go into Issues and take part into the open available issues. Your opinions are really useful!

Arrangement for View Assets Pattern

Introduction to the AVA Pattern

In the recent years, we’ve been seeing a lot of improvements on the organizational procedures for web applications. More specifically, the MVC Pattern, which greatly improved development speeds by imposing a well structured architecture. This allowed developers to feel at home with any application that uses the pattern.

The Model-View-Controller (MVC) Pattern is oriented to the back-end. There’s a specification about where to store your interface related code, the View, but there’s no real specification regarding how and where you should store your assets. This is where the Arrangement for View Assets (AVA) Pattern shines.

The AVA Pattern works side by side with the MVC Pattern. Both are framework and language agnostic, and independent of each other, but together you can achieve a better organization which will improve productivity, especially during advanced stages of the application.

Take this with a grain of salt and remember that you should always use what your team is accustomed to; these conventions may be modified to fit your project, however, try to follow the general idea about the structure.

For instance, you may want use snake_case over the dash-case naming pattern; these types of modifications are a matter of preference.

Why do we need the AVA Pattern?

You may think that there's a steep learning curve involved with the AVA Pattern however, this is not the case. The main objective of the AVA Pattern is to provide written documentation for you, and your team, to consult when in doubt about how to store your assets.

What do I get from the AVA Pattern, besides consistency?

The main plus you'll get from the AVA Pattern is consistency. And, that alone is something that is worth your time. Consistency is not something you should only want to achieve when you're working on a team, but it's something you should aim for, for your own sake.

Think of the following use cases:

  • As a Freelancer
    • The odds are that you're going to work alone on a project. You complete the project and months later you might need to get back in and support or change something. Chances are you completely forgot about the file structure and file names of the project. You'll spend some time trying to figure out your own code.
  • As a member of a Development Team
    • You're part of a team that has another front-end Engineer besides you. Everything is fine and dandy till he begins naming files under a completely different directory than the one you set. After some time you can notice who made what just by how it's stored.
  • As a Team Leader
    • You can instill some sort of structure for assets when working on multiple projects. This will allow assignment of team members to different projects, as needed, without having to worry about a team member learning a wildly different asset structure.
  • As an Outsourcer
    • Having different developers coming in and working on a code base on a contracted basis can create much confusion when it comes to the way that assets are handled. The AVA pattern will give a common way for different developers to save assets, and give you, the outsourcer, that much more control over your code.

Overview of the Structure.

Need to write some stuff here..

/stylesheets/                 # Documented? Soon.
  style.css
  handheld.css
/images/                         # Documented? ✓
/javascripts/                     # Documented? (needs more examples)
  tests/
    qunit/
    index.html
    tests.js
  libs/                      
    jquery-1.5.1.min.js
    jquery-1.5.1.js
    modernizr-1.7.min.js
    dd-belatedpng.js
  plugins.js
  script.js

/images/ Directory Convention

Conventions save you from having to figure out how the project is structured. The following conventions are the result of testing and polishing rules on production environment over the years.

Grouping Rules

Grouping is important; especially when you're working with projects that have many assets. The following rule proposes a way to organize these files into an easy to navigate way.

RULE
  IF images FROM same GROUP > 5
    store in new directory
    repeat RULE
  else
    store in root

This rule may loop a max of 3 times. Having too many levels is not advised since it may make everything more complex to mantain in the long run and will make your css file bigger.

Naming Rules

Names for individual files should always be singular, even if they're sprites that contains several elements. This is, by convention, a good practice that is taken from other web related frameworks.

Sub-Directories a.k.a. Groups should be named in their plural form when possible. Remember, this only applies to directories. For files, use the singular variant.

This whole plural/singular paradigm is to follow web frameworks and database naming conventions; think of it as a general recomendation.

background files:
  bg(-group)?(-name)
sprites:
  sp(-group)?(-name)
buttons:
  bt(-group)?(-name)
icons:
  ic(-group)?(-name)
other:
  (group-)?(name)

When the file is going to have several variants, it's a good practice to append the change in type or dimension using the following pattern.

(name)((-WIDTHx)(HEIGHT)?)?

Please note

logo-300x.jpg
logo-500x250.jpg
logo-500x300.jpg
logo-300x-grayscale.jpg

Notice that you're not forced to add the height when there's no variation to that file. The x is still left in place to denote that we're talking about width and not height:

50x <- 50 width
x50 <- 50 height

Examples

Need to document this further.

/bg-body.jpg
/bg-content.jpg
/bg-content-light.jpg
/sp-main.jpg
/ic-form-submit.jpg
/placeholders/
  content-big.jpg
  content-small.jpg
  content-medium.jpg
  user-display-100x.jpg
  user-display-200x.jpg
  video-medium.jpg

/javascripts/ Directory Convention

Previously /scripts/ - scripts was thought too general.

  • DHH voted for javascripts.
  • It maches rails conventions.
  • It's better than js.

Credits

Original Paper and Idea by Mario Ricalde. With the help of many people including:

ava-pattern's People

Contributors

armandocanals avatar dfischer avatar marioricalde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ava-pattern's Issues

Assumptions on Asset Manager

As of now with AVA Pattern we've been making some assumptions on the javascripts and stylesheets directories, most of them are related to the fact that to really get benefits from AVA Pattern you need to have a Asset Manager to merge files into one and to minify them accordingly.

Do you think this is bad?

Somehow I think that these assumptions are a good practice that everyone should be including on their developing environments. Having one HUGE file or multiple files invoked from the main HTML document is not a good practice.

Thoughts?

Use Cases

We need to complete the use cases; some of them are incomplete due to mexican lack of fluency with english. <3

Directory Structure

Currently with the directory structure we have there's no easy way to implement "vendor" libraries, that is any third party related portion of code that needs to be included inside our project.

Lets clarify, on front-end engineering a vendor script something that you're going to use that you didn't write.

I think we can add vendor directories inside the correct sections according to what it's specified on the AVA Pattern.

  • It sticks to what AVA Pattern specified.

  • You're not creating extra directories, so you know where to find what you want.

  • It's rails compatible.

    /stylesheets/
      libs/                     # This should be compressed into style.css
        vendor/                 # CSS Files related to a vendor library.
          package1/
        _sass-partial.scss
      style.css
      handheld.css
    /images/
      vendor/                   # Images related to a vendor library.
        package1/
    /javascripts/
      tests/
      libs/                     # Your Libraries.
        /vendor/
          package1/             # For more than one file.
      plugins.js
      script.js
    

Of course, here we're asuming you're using compass/coffeescript or something similar to sprockets to package all your js/css files into single file versions. I think we need to clarify this on the documentation; even though we're framework and language agnostic, we need to point out that many of the features AVA provides need to be coupled with a asset packager or the amount of http requests may become unberable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.